Implemention of PENTE board game with AI components
###Rules of the game The objective of the game is to either get 5 consecutive pieces on a board, or capture 5 pairs of the opponent's pieces. Players are free to place their pieces wherever on any unoccupied board spot. Some rules to keep in mind:
- A pair of the opponent's pieces mean two consecutive pieces that belong to the opponent
- To capture, the player must place a piece which makes a pair bracketed by the player's. For example, in a certain row [a, b, b, a]
- A player cannot cause themselves to be capture. For example, placing a 'b' where the row is [a, _, b, a]
###Heuristics I. Based on how many win states are still available II. Based on maximizing Trias III. Based on minimizing Tesseras IV. ??? V. ???
###Game files
- Pente.py
- gameAI.py
###Pente.py functions
-
main(): the main function controls the flow of the game, turns of the player, and collecting the moves from players. It also keeps track of winning or not, although those functions are implemented in the game file.
-
playAgain(): The function determines if user wants to play again after a win/loss game
-
whoGoesFirst(): The function decides using randint whether the computer goes first or the human player.
-
getHumanMove(board, tile): asks the human player to move, displays the computer's last move, and make sure the move entered is valid in format
###gameAI.py functions
-
getComputerMove(board, tile): this calls all the necessary functions to calculate which move the computer will make. Returns a tuple
-
generateChildren(board, player): this creates a list of possible next game states.
-
AlphaBeta(board, depth, player): computes AlphaBeta algorithm with a cutoff depth.
-
maxValue(board, depth, player, alpha, beta): helper function of AlphaBeta to compute the max level selections
-
minValue(board, depth, player, alpha, beta): helper function of AlphaBeta to computer the min level selections
-
heuristic(board): where all the magical things happen and a magical prediction of best move will come up. Returns a number.
-
drawBoard(board): draws the board in a text format, visualization of the board for the player
-
getNewBoard(): creates a new board with all blank points
-
isValidMove(board, move): determines if a move on a board state is ok.
-
isCaptureMove(board, player, move): counts pairs that are captured by this move as well as remove those captured pieces.
-
makeMove(board, player, move): makes a certain move, calls isCaptureMove to remove tiles and count captured pairs.
-
getPrevMove(): just returns the previous move of computer
-
isBoardFull(board): determines if a board is filled. returns a boolean
-
isWinner(board, tile): determines if a player has won. returns a boolean