-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameBoard.py
62 lines (53 loc) · 2.41 KB
/
GameBoard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from Miniboard import MiniBoard
class GameBoard:
boardA = []
def __init__(self, ):
for x in range(0, 9):
y = MiniBoard()
self.boardA.append(y)
def printboard(self):
for x in range(0, 9):
print(self.boardA[x].geta())
def checklegal(self, bcellnum, scellnum):
if 9 > bcellnum > -1 and self.boardA[bcellnum].checklegal(scellnum):
return True
else:
return False
def playmove(self, bcellnum, scellnum, ptag):
c = self.checklegal(bcellnum, scellnum)
if c:
self.boardA[bcellnum].setv(scellnum, ptag)
print(self.boardA[bcellnum].getv(scellnum))
return True
else:
return False
def checkwin(self):
if (self.checkDiagonal() == 1 or self.checkVertical() == 1 or self.checkHorizontal() == 1):
print("The first player has won")
return True
if (self.checkDiagonal() == 2 or self.checkVertical() == 2 or self.checkHorizontal() == 2):
print("The second player has won")
return True
def checkDiagonal(self):
if str(self.boardA[0].getv(0)) + str(self.boardA[4].getv(0)) + str(self.boardA[8].getv(8)) == "FFF" or str(self.boardA[2].getv(2)) + str(self.boardA[4].getv(4)) + str(self.boardA[6].getv(6)) == "FFF":
return 1
if str(self.boardA[0].getv(0)) + str(self.boardA[4].getv(0)) + str(self.boardA[8].getv(8)) == "SSS" or str(self.boardA[2].getv(2)) + str(self.boardA[4].getv(4)) + str(self.boardA[6].getv(6)) == "SSS":
return 2
else:
return False
def checkVertical(self):
for x in range(0, 3):
if str(self.boardA[x].getv(0)) + str(self.boardA[x + 2].getv(0)) + str(self.boardA[x + 5].getv(0)) == "FFF":
return 1
if str(self.boardA[x].getv(0)) + str(self.boardA[x + 2].getv(0)) + str(self.boardA[x + 5].getv(0)) == "SSS":
return 2
else:
return False
def checkHorizontal(self):
for x in range(0, 3):
if str(self.boardA[3 * x].getv(0)) + str(self.boardA[3 * x+1].getv(0)) + str(self.boardA[3 * x + 2].getv(0)) == "FFF":
return 1
if str(self.boardA[3 * x].getv(0)) + str(self.boardA[3 * x+1].getv(0)) + str(self.boardA[3 * x + 2].getv(0)) == "SSS":
return 2
else:
return False