In this lab you will be writing agents that use depth-bounded Minimax search with Alpha-Beta pruning to play Mancala and Breakthrough. In Mancala, players take turns grabbing all of the stones from one house on their side of the board and sowing them counterclockwise. The objective is to end the game with the most pieces in one's scoring house. In Breakthrough, players take turns advancing pawn-like pieces on a rectangular board. The objective is to get a single piece to the opponent's end of the board. The examples below show a mid-game board state from each game.
----------------------------------- | | 0 | 7 | 1 | 0 | 1 | 0 | | | 13 |-----------------------| 14 | >| | 0 | 1 | 3 | 3 | 5 | 0 | |< ----------------------------------- --------- |· · · · ●| |· · ● · ●| |· ● ● ● ●| |● ● · · ·| |● · ● ● ●| |· · ● ● ·| |· · · · ●| ---------
The following Wikipedia pages have complete rulesets for each game. Note that Mancala has many, many variants, so if you have played it before, you might have used different rules.
As in the previous lab, use Teammaker to form your team. You can log in to that site to indicate your partner preference. Once you and your partner have specified each other, a GitHub repository will be created for your team.
The objectives of this lab are to:
You will need to modify up to three python files:
You should also look over the following files:
To see the available command-line options for game play try running:
./PlayGame.py -hThen try playing Breakthrough against a really terrible opponent by running:
./PlayGame.py breakthrough random human --showAnd try playing Mancala against your lab partner by running:
./PlayGame.py mancala human human --showTry playing several games (and refer to the Wikipedia links above) to make sure you understand the rules of each game.
Begin by completing the following steps:
Next focus on the MinMaxPlayers.py file, and complete the following steps:
bounded_min_max(state, depth) if depth limit reached or state is terminal return staticEval(state) # init bestValue depending on who's turn it is bestValue = turn * -infinity for each move from state: determine the next_state # Recursive call value = bounded_min_max(next_state, depth+1) if player is maximizer if value > bestValue bestValue = value if depth is 0, update bestMove to current move else # player is minimizer if value < bestValue bestValue = value if depth is 0, update bestMove to current move return bestValue
./PlayGame.py mancala minmax minmax -d1 2 -d2 4 --showYou can also have your agent play several games (alternating sides) and report the results:
./PlayGame.py mancala minmax random -d1 2 -games 10You should also try playing against it yourself!
./PlayGame.py mancala minmax human -d1 4 --show
Come up with an improved static evaluator for the breakthrough game and implement it in the file Heuristics.py.
Your goal is to create an evaluator that will beat the basicEval function when tested using minimax players with equal depth limits.
Your static evaluators should:
Write a clear and thorough comment with your betterEval method to describe how it works. If you add helper functions, be sure to include comments describing these as well. You can tell your agent which static evaluator to use via the -e1 and -e2 command line options. The following runs agents that both search to depth 3, but use different static evaluators:
./PlayGame.py mancala minmax minmax -d1 3 -d2 3 -e1 better -e2 basic
./PlayGame.py mancala minmax pruning -games 2Note that these agents should be equally matched; pruning should just make decisions faster.
The BreakthroughTournamentPlayer is already set up to use your PruningPlayer and BreakthroughBetterEval implementations. All you need to do is fill in your team's usernames. For the Breakthrough tournament, all agents are required to search to depth 4. The goal of this competition is to come up with the best possible static evaluation function.
The MancalaTournamentPlayer is not yet implemented, and you may implement it to search to any depth (or even use iterative deepening). In this contest, you are encouraged to explore trade-offs between time spent searching and time spent on static evaluation.
Both of your tournament agents must implement non-randomized algorithms and run on a single CPU. Your agents will be limited to ten seconds per move (if they take longer, a random move will be chosen).
None of the points for the assignment depend on outcomes in the tournaments; they are strictly for fun. I encourage you to submit agents for both tournaments, even if you don't think your implementation is particularly exciting. The tournaments are more fun when more people play, and you might be surprised how effective simple strategies can be!