Prog 5: Tic Tac Two

Write a program to allow playing the 2-person game of Tic-Tac-Two.  According to the person in the Marbles Brain Store where I bought it, this was invented by a soldier in a foxhole during WWII.  Just like Tic-Tac-Toe, the object of the game is to get three of your pieces in a row, either horizontally, vertically.  The trick here is that the grid itself can move, and also pieces can be repositioned.

Play starts with the 3x3 grid positioned in the middle of a 5x5 board.  The first player places a piece on the board somewhere inside the 3x3 blue grid, and play alternates from there.  After two moves have been made by each player, a player's move can consist of one of the following three:

One additional restriction is that once the grid is moved, on the immediately following opponent's move the opponent may not move it back to its previous location. On any move entering 'x' exits the program.  [Note that the above rules are slightly modified from the original.]  

An ASCII graphics version might look something like the following:

Program #5: Tic Tac Two    

Author: Dale Reed    

Lab: Tues 8am     

System:  Mac OS X, xCode IDE 

 

 -------------------       

| .   .   .   .   . |   Pieces remaining for:

|                   |      Player 1: A B C D

| .   . | . | .   . |      Player 2: a b c d    

|     ---------     |

| .   . | . | .   . |   Grid destination squares:

|     ---------     |       1 2 3   

| .   . | . | .   . |       4 5 6

|                   |       7 8 9

| .   .   .   .   . | 

 -------------------            

1. Player 1: Enter piece to move and destination number: A2

 -------------------       

| .   .   .   .   . |   Pieces remaining for:

|                   |      Player 1:   B C D

| .   . | A | .   . |      Player 2: a b c d    

|     ---------     |

| .   . | . | .   . |   Grid destination squares:

|     ---------     |       1 2 3   

| .   . | . | .   . |       4 5 6

|                   |       7 8 9

| .   .   .   .   . | 

 -------------------            

2. Player 2: Enter piece to move and destination number: c 6

 -------------------       

| .   .   .   .   . |   Pieces remaining for:

|                   |      Player 1:   B C D

| .   . | A | .   . |      Player 2: a b   d    

|     ---------     |

| .   . | . | c   . |   Grid destination squares:

|     ---------     |       1 2 3   

| .   . | . | .   . |       4 5 6

|                   |       7 8 9

| .   .   .   .   . | 

 -------------------            

3. Player 1: Enter piece to move and destination number: D 5

 -------------------       

| .   .   .   .   . |   Pieces remaining for:

|                   |      Player 1:   B C  

| .   . | A | .   . |      Player 2: a b   d    

|     ---------     |

| .   . | D | c   . |   Grid destination squares:

|     ---------     |       1 2 3   

| .   . | . | .   . |       4 5 6

|                   |       7 8 9

| .   .   .   .   . | 

 -------------------            

4. Player 2: Enter piece to move and destination number: m 2

*** Both players must place 2 pieces before grid can be moved.  Please retry.

4. Player 2: Enter piece to move and destination number: c 8

*** Both players must place 2 pieces before grid pieces can be moved.  Please retry.

4. Player 2: Enter piece to move and destination number: B7

*** Player 2 can only select from lower-case pieces.  Please retry.

4. Player 2: Enter piece to move and destination number: b5

*** Destination square 5 is already occupied.  Please retry.

4. Player 2: Enter piece to move and destination number: b8

 -------------------       

| .   .   .   .   . |   Pieces remaining for:

|                   |      Player 1:   B C  

| .   . | A | .   . |      Player 2: a     d    

|     ---------     |

| .   . | D | c   . |   Grid destination squares:

|     ---------     |       1 2 3   

| .   . | b | .   . |       4 5 6

|                   |       7 8 9

| .   .   .   .   . | 

 -------------------            

5. Player 1: Enter piece to move and destination number, or 'm' 

             to move the grid and move direction (1-9 except 5): m 1

 -------------------       

| . | . | .   .   . |   Pieces remaining for:

| ---------         |      Player 1:   B C  

| . | . | A   .   . |      Player 2: a     d    

| ---------         |

| . | . | D   c   . |   Grid destination squares:

|                   |       1 2 3   

| .   .   b   .   . |       4 5 6

|                   |       7 8 9

| .   .   .   .   . | 

 -------------------            

6. Player 2: Enter piece to move and destination number, or 'm' 

             to move the grid and move direction (1-9 except 5): m 9

*** Grid cannot be immediately moved back to original position.  Please retry.

6. Player 2: Enter piece to move and destination number, or 'm' 

             to move the grid and move direction (1-9 except 5): b3

*** Piece b is not within the grid.  Please retry.

6. Player 2: Enter piece to move and destination number, or 'm' 

             to move the grid and move direction (1-9 except 5): m4

*** Grid may not be moved off of board.  Please retry.

6. Player 2: Enter piece to move and destination number, or 'm' 

             to move the grid and move direction (1-9 except 5): m8

 -------------------       

| .   .   .   .   . |   Pieces remaining for:

|                   |      Player 1:   B C  

| . | . | A   .   . |      Player 2: a     d    

| ---------         |

| . | . | D   c   . |   Grid destination squares:

| ---------         |       1 2 3   

| . | . | b   .   . |       4 5 6

|                   |       7 8 9

| .   .   .   .   . | 

 -------------------            

6. Player 2: Enter piece to move and destination number, or 'm' 

             to move the grid and move direction (1-9 except 5):  

Grading Rubric

Error checking must be done on user input, allowing user to retry.  Your program must implement and check for:

(2 points) Move numbers must be displayed.

(3 points) You may expect user input to always be exactly two characters, which may or may not be separated by spaces.  The exception to this is when 'x' (or 'X') is entered to exit the program.

(5 points) Only upper-case A-D are allowed as input pieces for player 1, and conversely lower-case a-d for player 2.

(5 points) Destination squares for must be empty when placing pieces. When initially placing pieces, pieces can be selected from A-D (and a-d) in any order.

(5 points) Pieces on the board may only be moved after each player has placed at least 2 pieces.

(10 points) The 3x3 grid may only be moved after each player has placed at least 2 pieces. The prompt to move the grid should accordingly only be shown once it is an option.

(5 points) The grid may not be moved off the edge of the board.

(10 points) Only squares contained within the 3x3 grid may be moved.

(10 points) A win consisting of 3 in a row (horizontal, vertical or diagonal) inside the 3x3 grid, created either by placing a piece or by moving the grid.  If moving the grid results in a win for both players, the win is awarded to the player making the move.

Turning it In

Only individual work is allowed for both program 5.  (Pair programming was allowed only for programs 3 & 4.)

As in previous assignments, create an executable named netid.cpp, and zip this up into netid.zip.  Turn this in to the programming assignment  called Prog. 5

Extra Credit

Extra Credit #1 (10 points): Figure out how to make a graphical version of this program in C++ that implements all the functionality described above, using only mouse input.  Submit this into Blackboard project Program 5 Extra 1.

Extra Credit #2 (10 points): In addition to turning in a fully-functioning C++ version (changed 11/16),  create a version that runs on an Android device or iPhone. 

 Submit this into Blackboard project Program 5 Extra 2.