CS 0447 – Project 2: Tic-Tac-Toe

Due: Sunday, July 17, 2016, by 11:59pm

Description

Many video games of the past were programmed directly in assembly language. In this project, we’ll be taking a classic pen-and-paper game, tic-tac-toe, and making a version in MIPS under MARS.

You will make a video display version of the game board, allow the user to select their move using the arrow keys, and have the computer play its turn automatically.

A small part of the grade will be based upon how well your computer-player plays.

Tools

After your first project, you might be wondering how to get MARS to make something as awesome as a video game. For this, we can thank several graduate students and Dr. Childers for a modified version of MARS that contains a LED display which we can control. The display is an array of pixels (64 x 64) and each LED can be one of 4 colors: off (black), red, green, or yellow/orange.

In later courses, we’ll discuss two strategies for talking to I/O devices from machine instructions. In this case, the pixel display is memory-mapped. This means that a byte in our address space is reserved for each pixel, and that the content of that array is reflected in the output of our display. Learning about the memory-mapped I/O is not the core of the project and so we provide get and set methods for manipulating a pixel at a specified location.

Additionally, the LED display has support for a key pad. It can handle either button presses on the dialog box or you can use the keys on your keyboard (WASD).

You will need to download this special modified version of MARS from the class webpage in order to do this project.

When you wish to use it, go into the tools menu and select “Keypad and LED Display Simulator”. In the window that appears, click “Connect to MIPS”. Then run the program in MARS using the green play button.

The Board

The board will be the LED display divided into the typical 9 squares using two lines in the X and Y directions. Make the lines yellow/orange in color and each row or column one-third of the width of the screen.

X’s and O’s

The computer player will play as O and always go first. Draw the O in the chosen location using green.

The human player will play as X and when it is the player’s turn, display a red X in the top-leftmost empty square. Allow the user with the arrow keys to move the X to other open squares left/right and up/down. The b button will lock in their choice. When locked in, turn the X green.

The Computer

The ideal tic-tac-toe game ends in a draw. While you may want to start your computer player using a random strategy, you should eventually add code to make the computer play smarter.

10 points of your grade will be based upon a 5 game play of your program. You’ll get 2 points for each win or tie the computer plays to and 0 points if the TA wins. We will document the game as part of grading so you can see what happened.

Game Requirements

  1. Draw the tic-tac-toe board
  2. Have the computer go first, play as O drawn in green.
  3. Have the player select where their turn will be by using the arrow keys and display their current choice as a red X. When they press the ‘b’ button, lock in their choice as a green X and move on to the next computer turn.
  4. The game ends when there are no more empty squares.
  5. When the game ends, the winner is printed using the print syscalls.
  6. You must use functions in this project. At minimum you need a function that draws an X in a given square, draws an O in a given square, and given the current state of the board computes the next computer turn. You may use others, but those three are required.
  7. Functions must follow the MIPS calling convention. Use the stack for spills. Use the $a0-$a3 registers for arguments and $v0-$v1 for return values.

Submission

Create a zip file of your source code and a README.txt text file that has your name, your Pitt username and any notes for the TA to help with grading.

Name the file USERNAME-project2.zip

Use the lab submission policies to upload your project.