CS 107 (Spring '09)
[Schedule] [Programs] [Notes & Reference] [Examples][Syllabus] [Lab & TA] [Tests] [Grades]

Program #5: Yote as Text, in C++

Prof. Reed, CS 107, Fall '08
Due Tuesday 12/2 at 1:00 PM

Description

Again implement Yote, implementing the same functionality as in the previous program. This time you will not have a graphical interface, but rather will use a text-based interface, with the program written in C++. Running the program will look like:

Author: Dale Reed 
Program: #5, Yote
TA: Englebert Humberdink, T 4-5 
Nov 19, 2008


Welcome to the ancient African game of Yote.

On each turn, each player may either deploy a piece from their reserve 
to any empty space on the board, or move a piece already on the board. Moves must 
be made vertically or horizontally, but not diagonally. Pieces move either by 
sliding to an adjacent empty cell or by jumping over and capturing an adjacent 
opponent's piece, landing in an empty square immediately beyond. When a piece 
captures another piece, the player may then select any other opponent piece on 
the board (but not in their opponent's reserve) and capture it as well. 

The player who captures all of her opponent's pieces wins. If either player is unable 
to move, then the game ends and the player with the most pieces on the board wins. If 
both players are reduced to three or less pieces, then the game is a draw. 


The first character on the input line tells what kind of move it will be.
Possible inputs for each move are: x to exit program. A message tells who has the most pieces. p n1 p signifies placing a piece at postion n1, where n1 is a number 1..20 m n1 n2 m signifies moving a piece from board position n1 to n2 X goes first, then O. For reference, the square numbers are given at right below. Let's begin... ------------------- | . | . | . | . | . | 1 2 3 4 5 |-------------------| | . | . | . | . | . | 6 7 8 9 10 |-------------------| | . | . | . | . | . | 11 12 13 14 15 |-------------------| | . | . | . | . | . | 16 17 18 19 20 ------------------- 1. Enter move for X: p 7 ------------------- | . | . | . | . | . | 1 2 3 4 5 |-------------------| | . | X | . | . | . | 6 7 8 9 10 |-------------------| | . | . | . | . | . | 11 12 13 14 15 |-------------------| | . | . | . | . | . | 16 17 18 19 20 ------------------- 2. Enter move for O: p 2 ------------------- | . | O | . | . | . | 1 2 3 4 5 |-------------------| | . | X | . | . | . | 6 7 8 9 10 |-------------------| | . | . | . | . | . | 11 12 13 14 15 |-------------------| | . | . | . | . | . | 16 17 18 19 20 ------------------- 3. Enter move for X: p 12


You need to know the following concepts in order to write this program:

Everything from the first four assignments; How to design a program and write function calls in C++;

Notes:

  1. I recommend that you represent the board using an array of characters, and use variables to count how many pieces have been placed so far for X and for O.
  2. See this sample program that shows how to handle user input. You may also want to see a sample program to declare an array for the board and display it. Note that this second program has an extra "border" of 'Z' characters stored in the array, however these characters are never displayed on the screen. This extra border makes it more convenient to write code in other parts of the program, since you don't then have to write special code to make sure you don't otherwise go off the edge of the board.
  3. You may not have any global variables except for the array of characters containing the board. NO GLOBAL VARIABLES OTHERWISE! You will lose 30 points if you break this rule. This means that you will need to declare variables inside of main, and will have to pass them around in your program as parameters.
  4. Program play should proceed with the same functionality and error checking as was required in program #4. You do not need to check user input to verify that it is only numbers. You can assume that your user only gives numbers as input. You do, however, have to check those numbers to make sure they are valid. In other words, you must do the same error checking as in the previous program:
                   - There must be a piece at the source position, and it must be the correct color
                   - Only allow placing onto an open square
                   - Only allow moving into an open square
                   - Can't move off the board
                   - Can only jump one piece
                  - Can only jump an opponent's piece (not an empty square or same color piece)
                   - After a jump, prompt for opponent's piece to remove, and can only remove an opponent's piece
  5. Turnin your program electronically using the "turnin" command from your CS account. The turnin command should be used as follows:
  6. turnin -c cs107 -p program5 YoteText.cpp
    where the file containing your solution is called YoteText.cpp. 

[CS Dept] [UIC] [Prof. Reed]