-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayAGame.py
35 lines (29 loc) · 1.02 KB
/
PlayAGame.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
import itertools
import chess
def playAGame(whiteBoardEvaluator, blackBoardEvaluator, testMode=False):
board = chess.Board()
whitesTurn = True
count = 0
while(not board.is_game_over()):
if(whitesTurn):
nextMove = getNextMove(board, whiteBoardEvaluator)
else:
nextMove = getNextMove(board, blackBoardEvaluator)
board.push(nextMove)
if(count % 50 == 0 and testMode):
print(board)
print("-----------------------")
count += 1
whitesTurn = not whitesTurn
if(testMode):
print("Total Moves: " , count)
print("Outcome: " , board.outcome())
return board
def getNextMove(board, boardEvaluator):
nextBoards = []
for move in board.legal_moves:
newBoard = board.copy()
newBoard.push(move)
nextBoards.append(newBoard)
indexOfNextBestBoard = boardEvaluator.getIndexOfBestBoard(nextBoards)
return next(itertools.islice(board.legal_moves, indexOfNextBestBoard, None))