MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / getComputerMove

Function getComputerMove

src/gamesbyexample/pygame_games/fourinarow.py:258–270  ·  view source on GitHub ↗
(board)

Source from the content-addressed store, hash-verified

256
257
258def getComputerMove(board):
259 potentialMoves = getPotentialMoves(board, BLACK, DIFFICULTY)
260 # get the best fitness from the potential moves
261 bestMoveFitness = -1
262 for i in range(BOARDWIDTH):
263 if potentialMoves[i] > bestMoveFitness and isValidMove(board, i):
264 bestMoveFitness = potentialMoves[i]
265 # find all potential moves that have this best fitness
266 bestMoves = []
267 for i in range(len(potentialMoves)):
268 if potentialMoves[i] == bestMoveFitness and isValidMove(board, i):
269 bestMoves.append(i)
270 return random.choice(bestMoves)
271
272
273def getPotentialMoves(board, tile, lookAhead):

Callers 1

runGameFunction · 0.70

Calls 2

getPotentialMovesFunction · 0.85
isValidMoveFunction · 0.70

Tested by

no test coverage detected