Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package andyai | ||
|
||
// TODO: move this to blokus package that andyai imports | ||
type BlokusState struct { | ||
WhoseTurn int // which player the game is waiting on | ||
[][]int Board // 2d grid of colored cells | ||
[4][]int PiecesLeft // for each player, list of pieces left | ||
} | ||
|
||
func TakeTurn(BlokusState state) { | ||
// returns move, heuristic score for each player | ||
func getBestMove(BlokusState state) { | ||
list_of_possible_moves := generateMoveList(state, state.WhoseTurn) | ||
best_score := nil | ||
best_move := nil | ||
for move in list_of_possible_moves { | ||
test_board = doMove(test_board, move) | ||
while not gameOver(test_board) { | ||
enemy_move = getBestMove(test_board) | ||
test_board = doMove(test_board, enemy_move) | ||
} | ||
board_score = boardScore(test_board) | ||
if best_score == nil || board_score > best_score { | ||
best_score = board_score | ||
best_move = move | ||
} | ||
} | ||
} | ||
best_move, scores = getBestMove(state) | ||
return best_move | ||
} |