Sunteți pe pagina 1din 3

CSL 102 - Assignment 6

April 22, 2012


Due Date: Monday April 30. 11:50 pm In this assignment we will design a real life game called tic-tac-toe. There is a high chance that you already played this game while as a kid: http://en.wikipedia.org/wiki/Tic-tac-toe We will generalize this to boards of any size. A player wins the game when they have got all the crosses (or noughts as the case might be) on one of the rows, columns or diagonals of the board before the opponent is able to do so. 1. Write a Python program which inputs the board size n (n 3) and implements a 2-player tic-tac-toe game as described above keeping the following points in mind. Your program should start the game with all the board positions unlled. The players should be given turns alternately. At each turn of a player, they should be prompted to input their next move. The chosen position should then be noted and the board should be updated accordingly. At any turn, if the board reaches a winning position, you should ag accordingly and declare the winner. If the board gets completely lled without any of the users reaching a winning position, you should declare a tie. Once the game is nished (either someone has won or there is a tie), you should prompt whether the users want to play again or 1

exit, and then appropriately take the right action (i.e. start a new game or exit). Your program should be able to detect all kinds of erroneous inputs (selected position being out of range, selected position being already occupied, non-integer inputs etc.) and take the appropriate action. For instance, for an out of range move, user should be warned and prompted to try another move. In no case there should be an abrupt exit. For this part, you can display the board on the standard output, using x for crosses and o for noughts. Any unlled positions should be marked with the corresponding square number (ranging from 1 to n2 ) to give the users an ease in choosing their next move. After every move, you should generate the new board and display it accordingly. 2. Design a GUI (Graphical User Interface) for the game designed in the part above. Download this graphics package and store it in the directory where you will write your program. For a detailed documentation, click here. Here is a template le demonstrating the use of various utilities that you will need to write your program. You should feel free to use various elements in the graphics package and give an aesthetic touch to the display of your board. We may decide to give an extra credit for creative displays! 3. Extra Credit: Programming computers to play against humans is a very interesting area of research in its own right. You must have heard about the Deep Blue supercomputer defeating the world chess champion Garry Kasparov back in 1997. This and more such events, including the latest defeat of human players against a computer (IBMs Watson) in the game of jeopardy, leave us wondering if the machines can really surpass human intelligence. Here are a few interesting links on this: http://news.blogs.cnn.com/2011/02/10/man-vs-computer-a-gaming-history/ http://www.youtube.com/watch?v=bpgFGYBJbms (a) Design the above game of tic-tac-toe where a computer plays against a human. In this case, your program will have to decide the next move when it is the turn of the computer. Various 2

kinds of heuristics can be used to decide the next optimal move. Think of what those heuristics might be. The wiki-page given in the beginning of the assignment might give some pointers. (b) A winning strategy is a sequence of moves (based on opponents moves) which would always lead to a win independent of how the opponent plays. For a 33 tic-tac-toe-board, argue that their does not exist a winning strategy i.e. if both players play optimally the game will always result in a tie. Additional note about submission of this assignment: In addition to the submission of the tarred directory of all your les, you are also required to append all your code (that you wrote) for this assignment into a single text le and submit it along. The complete submission will have two components: A tarred directory of all your les as before. A text le containing all the code that you wrote for this assignment. This le should be named in the same way as you named your directory i.e. it should contain your name and entry number and name.

S-ar putea să vă placă și