-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (48 loc) · 1.84 KB
/
main.py
File metadata and controls
54 lines (48 loc) · 1.84 KB
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
import cv2
import gameLogic
import pieceFinder
import computerMove
import display
def game():
videoStream = cv2.VideoCapture(0)
compOrder = display.displayMenu(videoStream)
# indicates if one of the players is a computer, and whether they play first or second
currentTurn = 1
# 1 is player 1 turn, 2 is player 2 turn
board = [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 2, 0, 0, 0],
[0, 0, 0, 2, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]
]
# 1 is player 1
# 2 is player 2
# 0 is empty
endgameWinner = 0
while endgameWinner == 0:
validMoves = gameLogic.getMoves(board, currentTurn)
# displays the board then runs a turn
display.displayBoard(board, validMoves, currentTurn, compOrder)
runTurn(board, currentTurn, compOrder, videoStream, validMoves)
# swaps the turns
currentTurn = abs(currentTurn - 2) + 1
endgameWinner = gameLogic.checkEndGame(board)
display.displayBoard(board, [], currentTurn, compOrder)
display.displayEndgame(endgameWinner)
def runTurn(board, currentTurn, compOrder, videoStream, validMoves):
# checks whether the player whose turn it is has any valid moves to make
if len(validMoves):
print(validMoves)
# gets the move for the computer if it is the computers turn, or the player if it is the player's turn
if compOrder == currentTurn:
moveToMake = computerMove.makeComputerTurn(board, currentTurn, validMoves)
else:
moveToMake = pieceFinder.makePlayerTurn(validMoves, videoStream)
# alters the board file for the decided move
gameLogic.flipTiles(board, currentTurn, moveToMake)
while True:
game()