CS151 - Assignment 2 Mancala Due: Tuesday March 5 at the beginning of class

Similar documents
For slightly more detailed instructions on how to play, visit:

Introduction to Artificial Intelligence CS 151 Programming Assignment 2 Mancala!! Due (in dropbox) Tuesday, September 23, 9:34am

1 Introduction. 1.1 Game play. CSC 261 Lab 4: Adversarial Search Fall Assigned: Tuesday 24 September 2013

1 Modified Othello. Assignment 2. Total marks: 100. Out: February 10 Due: March 5 at 14:30

Pay attention to how flipping of pieces is determined with each move.

mywbut.com Two agent games : alpha beta pruning

B551 Homework 2. Assigned: Sept. 15, 2011 Due: Sept. 29, 2011

Homework Assignment #2

CSCI1410 Fall 2018 Assignment 2: Adversarial Search

Module 3. Problem Solving using Search- (Two agent) Version 2 CSE IIT, Kharagpur

CSE 332: Data Structures and Parallelism Games, Minimax, and Alpha-Beta Pruning. Playing Games. X s Turn. O s Turn. X s Turn.

ARTIFICIAL INTELLIGENCE (CS 370D)

Computer Science and Software Engineering University of Wisconsin - Platteville. 4. Game Play. CS 3030 Lecture Notes Yan Shi UW-Platteville

2 person perfect information

More Adversarial Search

CMPUT 396 Tic-Tac-Toe Game

CS 2710 Foundations of AI. Lecture 9. Adversarial search. CS 2710 Foundations of AI. Game search

CS 1571 Introduction to AI Lecture 12. Adversarial search. CS 1571 Intro to AI. Announcements

Assignment 2 (Part 1 of 2), University of Toronto, CSC384 - Intro to AI, Winter

CPSC 217 Assignment 3 Due Date: Friday March 30, 2018 at 11:59pm

CSE 3401 Assignment 4 Winter Date out: March 26. Date due: April 6, at 11:55 pm

Assignment 2, University of Toronto, CSC384 - Intro to AI, Winter

Game-playing AIs: Games and Adversarial Search I AIMA

Artificial Intelligence Lecture 3

Adversary Search. Ref: Chapter 5

Programming an Othello AI Michael An (man4), Evan Liang (liange)

Game Playing for a Variant of Mancala Board Game (Pallanguzhi)

Game Playing AI Class 8 Ch , 5.4.1, 5.5

Adversarial Search (Game Playing)

ADVERSARIAL SEARCH. Today. Reading. Goals. AIMA Chapter , 5.7,5.8

CMSC 201 Fall 2018 Project 3 Sudoku

CS 440 / ECE 448 Introduction to Artificial Intelligence Spring 2010 Lecture #5

ADVERSARIAL SEARCH. Today. Reading. Goals. AIMA Chapter Read , Skim 5.7

Algorithms for Data Structures: Search for Games. Phillip Smith 27/11/13

03/05/14 20:47:19 readme

CS 188: Artificial Intelligence Spring Announcements

AI Approaches to Ultimate Tic-Tac-Toe

2359 (i.e. 11:59:00 pm) on 4/16/18 via Blackboard

CSC 110 Lab 4 Algorithms using Functions. Names:

game tree complete all possible moves

Adversarial Search 1

Game Playing AI. Dr. Baldassano Yu s Elite Education

Activity 6: Playing Elevens

CS 188: Artificial Intelligence. Overview

Playing Games. Henry Z. Lo. June 23, We consider writing AI to play games with the following properties:

Games (adversarial search problems)

CS 229 Final Project: Using Reinforcement Learning to Play Othello

Five-In-Row with Local Evaluation and Beam Search

Board Game AIs. With a Focus on Othello. Julian Panetta March 3, 2010

Real-Time Connect 4 Game Using Artificial Intelligence

CS885 Reinforcement Learning Lecture 13c: June 13, Adversarial Search [RusNor] Sec

Before attempting this project, you should read the handout on the algorithms! (games.pdf)

ADVERSARIAL SEARCH. Chapter 5

Tic-tac-toe. Lars-Henrik Eriksson. Functional Programming 1. Original presentation by Tjark Weber. Lars-Henrik Eriksson (UU) Tic-tac-toe 1 / 23

Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning

Learning to Play like an Othello Master CS 229 Project Report. Shir Aharon, Amanda Chang, Kent Koyanagi

CS 771 Artificial Intelligence. Adversarial Search

Documentation and Discussion

CS 540-2: Introduction to Artificial Intelligence Homework Assignment #2. Assigned: Monday, February 6 Due: Saturday, February 18

CS61B, Fall 2014 Project #2: Jumping Cubes(version 3) P. N. Hilfinger

Adversarial Search Aka Games

Artificial Intelligence. Minimax and alpha-beta pruning

Interactive 1 Player Checkers. Harrison Okun December 9, 2015

Game-playing AIs: Games and Adversarial Search FINAL SET (w/ pruning study examples) AIMA

Tac Due: Sep. 26, 2012

COSC 117 Programming Project 2 Page 1 of 6

CPS331 Lecture: Search in Games last revised 2/16/10

CS188 Spring 2014 Section 3: Games

Project 1: A Game of Greed

CPSC 217 Assignment 3

CITS3001. Algorithms, Agents and Artificial Intelligence. Semester 2, 2016 Tim French

Announcements. CS 188: Artificial Intelligence Spring Game Playing State-of-the-Art. Overview. Game Playing. GamesCrafters

Lecture 33: How can computation Win games against you? Chess: Mechanical Turk

Last update: March 9, Game playing. CMSC 421, Chapter 6. CMSC 421, Chapter 6 1

Game Tree Search. CSC384: Introduction to Artificial Intelligence. Generalizing Search Problem. General Games. What makes something a game?

Unit 12: Artificial Intelligence CS 101, Fall 2018

Foundations of AI. 5. Board Games. Search Strategies for Games, Games with Chance, State of the Art. Wolfram Burgard and Luc De Raedt SA-1

Adversarial Search and Game- Playing C H A P T E R 6 C M P T : S P R I N G H A S S A N K H O S R A V I

Tic-Tac-Toe and machine learning. David Holmstedt Davho G43

Comp th February Due: 11:59pm, 25th February 2014

COMP219: COMP219: Artificial Intelligence Artificial Intelligence Dr. Annabel Latham Lecture 12: Game Playing Overview Games and Search

Game Playing. Why do AI researchers study game playing? 1. It s a good reasoning problem, formal and nontrivial.

The game of Reversi was invented around 1880 by two. Englishmen, Lewis Waterman and John W. Mollett. It later became

Artificial Intelligence 1: game playing

University of Amsterdam. Encyclopedia of AI project. Tic-Tac-Toe. Authors: Andreas van Cranenburgh Ricus Smid. Supervisor: Maarten van Someren

Adversarial Search and Game Playing. Russell and Norvig: Chapter 5

Foundations of AI. 6. Adversarial Search. Search Strategies for Games, Games with Chance, State of the Art. Wolfram Burgard & Bernhard Nebel

Solving Problems by Searching: Adversarial Search

Adversarial Search and Game Playing

Selected Game Examples

2 Textual Input Language. 1.1 Notation. Project #2 2

EXPLORING TIC-TAC-TOE VARIANTS

CS 188: Artificial Intelligence Spring 2007

Game Playing in Prolog

Today. Types of Game. Games and Search 1/18/2010. COMP210: Artificial Intelligence. Lecture 10. Game playing

CS 251 Intermediate Programming Space Invaders Project: Part 3 Complete Game

Final Project: Reversi

CSE 231 Fall 2012 Programming Project 8

CMSC 671 Project Report- Google AI Challenge: Planet Wars

CS 188: Artificial Intelligence

Transcription:

CS151 - Assignment 2 Mancala Due: Tuesday March 5 at the beginning of class http://www.clubpenguinsaraapril.com/2009/07/mancala-game-in-club-penguin.html The purpose of this assignment is to program some of the search algorithms and game playing strategies that we have learned in class. In particular, you will implement two aspects of Mancala (and other two-player games): search with alpha-beta pruning, and a game board evaluator. Your goals are to implement alpha-beta pruning correctly, and to create the best AI player you can. We will hold a tournament between the submitted players. (However, your placement in the tournament will have no effect on your grade and involvement is optional). For this assignment, you may work with one other person (i.e. in a pair) if you d like. If you choose to do so, collaboration on the assignment must be truly collaborative; sitting together and programming together. 1

1 Introduction to Mancala Mancala is a two-player game from Africa in which players moves stones around a board (shown above), trying to capture as many pieces as possible. In the board above, player 1 owns the bottom row of stones and player 2 owns the top row. There are also two special pits on the board, called Mancalas, in which each player accumulates his or her captured stones (player 1 s Mancala is on the right and player 2 s Mancala is on the left). There are a number of variants on Mancala, but here are the rules that we will play by: The board starts out with four pieces in each of the non-mancala pits. To take a turn, a player chooses on of the pits on his or her side of the board (not the Mancala) and removes all of the stones from that pit. The player then places one stone in each pit, moving counterclockwise around the board, starting with the pit immediately next to the chosen pit, including the player s Mancala but NOT the opponent s Mancala, until the player has run out of stones. If the player s last stone ends in his or her own Mancala, the player gets another turn. If the player s last stone ends in an empty pit on his or her own side, the player captures all of the stones in the pit directly across the board from where the last stone was placed (the opponents stones are removed from the pit and placed in the player s Mancala) as well as the last stone placed (the one placed in the empty pit). The game ends when one player cannot move on his or her turn (i.e. there are no stone s left on the player s side), at which time the other player captures all of the stones remaining on his or her side of the board. For more details on Mancal and its variants visit: http://en.wikipedia.org/wiki/mancala 2 Provided Code At: http://www.cs.middlebury.edu/~dkauchak/classes/cs311/assignments/assign2_starter.tar.gz I have included some initial code to get you started. This code includes support for the basic game as well as a simple AI player (it s REALLY simple). The starter code contains the following files: 2

MancalaBoard.py: A file that contains a class that represents the Mancala gameboard (similar to TTTBoard from the first assignment). This class manages the gameboard, knows how to add moves, can return legal moves, can determine when a player has won, etc. Player.py: A player class that can be instantiated with several types ( constants defined at the beginning of the class): HUMAN: a human player (i.e. prompt the user for a move) RANDOM: a player that makes random legal moves MINIMAX: a player that uses the minimax algorithm and the score function to choose its next move, limited by a specified ply depth ABPRUNE: a player that uses alpha-beta pruned search and the score function to choose its next move, limited by a specified ply depth. This player is not yet supported (you will implement it). CUSTOM: the best player you can create. This player is not yet supported (you will implement it). Notice that this file also contains a class MancalaPlayer which inherits from Player and which you will also fill out the details for. MancalaGUI.py: A simple GUI for playing the Mancala game. To invoke the game you call the startgame(p1, p2) function, passing it two player objects. TicTacToe.py: A file that contains a class representing a Tic Tac Toe gameboard, similar to what you implemented in the first assignment. Download these files and make sure you can run them. To run a GUI game between two humans: # load the GUI class and associated functions >>> from MancalaGUI import * >>> player1 = Player(1, Player.HUMAN) >>> player2 = Player(2, Player.HUMAN) >>> startgame(player1, player2) Note that the ply parameter is not required for some of the players (e.g. HUMAN and RANDOM). The GUI will show up when you execute the startgame command. You should see a window appear (it may appear in the background). You can now play Mancala with a friend. But what if you don t have a friend, you ask? Well, never fear! The computer will play against you (and you will likely win). To play against the computer you simply need to create a computer player to play against: >>> startgame(player(1, Player.HUMAN), Player(2, Player.RANDOM)) or 3

>>> startgame(player(1, Player.HUMAN), Player(2, Player.MINIMAX, 5)) If Mancala isn t your game, you can also play a very basic version of Tic Tac Toe using the same player objects (but no GUI provided with Tic Tac Toe). Use the hostgame function in the TTTBoard class: >>> from Player import * >>> from TicTacToe import * >>> board = TTTBoard() >>> board.hostgame(player(1, Player.HUMAN), Player(2, Player.MINIMAX, 6)) Once you understand how to run the code, make sure you read though the provided code and understand what it does. Notice that the minimax algorithm we discussed in class has already been implemented. 3 A Better Board Scoring Function The board scoring function in the basic player is too simple to be useful in Mancala the agent never looks ahead to see the end of the game until it s too late to do anything about it. Your first task is to write an improved score function in the MancalaPlayer class, a subclass of Player, that scores the quality of the current board. You may wish to consider the number of pieces your player currently has in its Mancala, the number of blank spaces on its side of the board, the total number of pieces on its side of the board, specific board configurations that often lead to large gains, or anything else you can think of. You should experiment with a number of different heuristics, and you should systematically test these heuristics to determine which work best. Note that you can test these heuristics with the MINIMAX player, or you can wait until you ve completed part 4 below (alpha-beta pruning). In addition to your code, you will submit a short (1-2 paragraphs) writeup about how you chose your final score function. What did you try along the way? What worked well and how did you determine what works well? This writeup will be a large part of your grade for this part! 4 Alpha-Beta Pruning The next part of the assignment is to implement the alpha-beta pruning search algorithm described in the textbook and in class. Look in the code to see where to implement this function (in the Player class). I encourage you to refer to the pseudocode in the book, but make sure you understand what you are writing. In your alpha-beta pruning algorithm, you do NOT have to take into account that players get extra turns when they land in their own Mancalas with their last stones. You can assume that a player simply gets one move per turn and ignore the fact that this is not always true. Notice that 4

my provided version of minimax also makes this simplifying assumption. This makes the scoring function slightly inaccurate, but easier to code. You will likely want to test your alpha-beta pruning algorithm on something simpler than Mancala, which is why we have provided the Tic Tac Toe class. Using alpha-beta pruning, it s possible for an agent to play a perfect game of Tic Tac Toe (by setting ply=9) in a reasonable amount of time. The first move by the agent may takea few seconds depending on the computer, but after that the agent will choose its moves quickly. Contrast this timing to minimax which will take 5-10 seconds to make it s first move. Test your algorithm carefully by working through the utility values for various board configurations and making sure your algorithm is not only choosing the correct move, but pruning the tree appropriately. You must submit along with your code at least one example that illustrates that your algorithm correctly prunes the search tree. For example, consider the board: X X O Your search will first try an O in the top right corner and should find that that move leads ultimately to a tie. Now consider this point in the search tree: X X _ O O where O has tried a move in the left, center spot. On the next level (when X plays in the top right), the algorithm immediately sees that X will win, resulting in a score of 0 for O. Since X is the min player, X will choose this move unless there is a move with an even LOWER value (which there is not). Thus, the best O can do is a score of 0 if it moves in the middle left. It does not need to try the other positions for X because it knows that it is not going to choose to play here (because blocking X in the top row leads to a score of 50, which is better). Thus the algorithm will prune the rest of the search tree at this point after it has tried the top right corner for X. To write this part up, you must first illustrate that your program behaves correctly in this case by adding print statements to your code (that you must remove before submitting), which might then produce the following output: alpha is 50.0, score is 0.0. Aborted on move 2 in minvalue on XX2 OO5 678 You should then explain what is going on as above. You should choose a different example when testing your code. Come see me if you have questions about this part. Your explanation of what 5

is going on is worth a significant part of your grade, so be sure that you understand the above explanation and that you can produce one of your own. 5 Creating a custom player Create a custom player (using any technique you wish) that plays the best game of Mancala possible. This will be the player that you enter into the class tournament. Past years of resourceful students have led me to be more specific about my specification and restrictions for your players: Your player must compile without errors. Your player must make its moves in 10 seconds or less on one of the lab machines (you don t need to get fancy with timers or anything, but if it runs significantly longer than that, it will be disqualified from the tournament). Choose a name for your player. Rename both the MancalaPlayer subclass and the Player.py file to exactly match your player s name. (This is so they can be easily identified in the tournament). For example, I might name my player DavesPlayer. So, my file (which would be called DavesPlayer.py ) would contain a class called Player and a class called DavesPlayer. I will not specify a ply for your tournament player. It is your (your player s) responsibility to use the ply that makes it return a move within 10 seconds. What I mean by this is, I ll instantiate your player in this way for the tournament: DavesPlayer.DavesPlayer(1, DavesPlayer.Player.CUSTOM) In other words, I will not initialize it with a ply and you should either have a default ply, or have the player determine on its own what ply it can get to in each move. Your player may NOT use a database. Your player may NOT connect remotely to another machine. Your code must compile in 5 seconds or less. Your player may NOT spawn any other processes or threads. The player must use a single thread. Any pre-computed moves can be hard coded, but not written to or loaded from a file or database. Let me know if you have any further questions! 6

6 Hints! For alpha-beta pruning, you likely will need equivalent minvalue and maxvalue functions for your pruning approach, for example minvalueab and maxvalueab. Notice that minvalue, maxvalue and minimaxmove return both a score and a state. When you call a function that returns two values, make sure that you either assign the result to two values OR, if you save it as a single value, it will be a tuple and you ll have to select the appropriate value. (Technically, we only need the score in minvalue and maxvalue, however, it was included here for debugging purposes). If you want to start Tic Tac Toe from a particular state, comment out self.reset() in the hostgame method. Then, create a new board and two new players. Use makemove to make the appropriate moves to change the board configuration. When the board state is where you d like it to be, you can then call hostgame and since the reset call is commented out, it will start from that state. 7 When you re done Make sure that your code compiles, that your files are named as specified and that all your functions have the correct name and number of parameters. Create a directory with your name followed by the assignment number. For example, my folder would be called davidkauchak1 (but use your name!). If you worked with a partner, put both people s last names on the submitted directory. Put all of your files to be submitted in this directory and zip it up. Submit this zip file through the mechanism on the course web page. What to submit YourPlayer.py: (i.e. the appropriately renamed Player.py file) This file should contain all the code you have written, including your score function, your alpha beta pruning algorithm and your custom player. ABcorrectness.txt: Your analysis of the correctness of your alpha-beta pruning algorithm, as described above. boardscore.txt: Your analysis of how you chose your board score function, as described above. Commenting and code style Your code should be commented appropriately (though you don t need to go overboard). The most important things: Your name (or names) and the assignment number should be at the top of each file 7

Each class and method should have a short docstring If anything is complicated, put a short note in there to help the graders out if there are any issues. There are many possible ways to approach this problem, which makes code style and comments very important here so that the grader and I can understand what you did. For this reason, you will lose points for poorly commented or poorly organized code. Grading Part points Board scoring function code style 5 good heuristics 20 write-up/discussion 15 AB pruning code style 5 correctness 20 example write-up 20 custom player 10 commenting 5 total 100 Optional Just for fun! If you find yourself incredibly interested in this assignment and want to do a little extra, read on... As described above, the current minimax implementation does not take into account the fact that a player gets another move if his or her last stone ends in the player s own Mancala. Write a new minimax function, called minimaxfull and a new alpha-beta pruning function, called abprunefull, that takes into account that a player gets another move on their turn if they land in their own Mancala with their last stone. 8