Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add my AI pseudocode to a package

  • Loading branch information...
commit 196129ab991b04d09f1817eceec414284402b47d 1 parent 210ddf3
@andrewrk andrewrk authored
Showing with 31 additions and 0 deletions.
  1. +31 −0 andyai/andyai.go
View
31 andyai/andyai.go
@@ -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
+}
Please sign in to comment.
Something went wrong with that request. Please try again.