Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment 6: Given: 02/16/12 Due: 03/01/12 ------------ Points: 10 Purpose: Use

ID: 3640277 • Letter: A

Question

Assignment 6: Given: 02/16/12 Due: 03/01/12
------------ Points: 10
Purpose: Use a 2-D array.
Write functions to process a 2-D array

Description:

Extend assignment #5 to be able to run the complete game.
Have it stop and display who won when there is a winner.

Ex:
--
Input:
0 0

Output:
| |
X | |
| |
-----------------
| |
| |
| |
-----------------
| |
| |
| |

Input:
1 1

Output:
| |
X | |
| |
-----------------
| |
| O |
| |
-----------------
| |
| |
| |

Input:
2 2

Output:
| |
X | |
| |
-----------------
| |
| O |
| |
-----------------
| |
| | X
| |

Input:
0 2

Output:
| |
X | | O
| |
-----------------
| |
| O |
| |
-----------------
| |
| | X
| |

Input:
2 0

Output:
| |
X | | O
| |
-----------------
| |
| O |
| |
-----------------
| |
X | | X
| |


Input:
1 0

Output:
| |
X | | O
| |
-----------------
| |
O | O |
| |
-----------------
| |
X | | X
| |

Input:
2 1

Output:
| |
X | | O
| |
-----------------
| |
O | O |
| |
-----------------
| |
X | X | X
| |

X Wins!


Notes:
-----
- Read only the integer row and column values
- Read until the board is full, or a row,column
pair of -1,-1 is entered, or there is a winner.
- The three row and column values will be 0,1,2
(C style counting.)
- Display the grid after each row,column entry is made
- Write functions to:
- read the row and column values
- populate the grid
- check for a full grid
- check if a square in the grid is open
- determine if there is a winner
- Attempt to keep main( ) as "clean" as possible
- Test your program with a variety of data sets that match the
problem description.
- X always goes first.
- Alternate X/O.

- When you think you are finished with your program, print it,
study it, tune it. (Do this until you really, really like
your final product.)

Explanation / Answer

Pseudo Code for Algorithm

Start

Declare global variable c A[][];
Declare global variable switchChar = false;

Start in Main
While( NOT (String -1 -1 is given by the user/customer) )
{
Get input myString;
Make sure input is formatted, otherwise return;
Delete spaces
Make sure input is less than or equal to 2, or Out of Bounds Exception catch.
if(switchChar = false)
{
A[myString.charAt[0].toInteger()][myString.charAt[1].toInteger()] = 'X';
switchChar = true;
}
else if(switchChar = true)
{
A[myString.charAt[0].toInteger()][myString.charAt[1].toInteger()] = 'O';
switchChar = false;
}

GoToPrintFunction()
}


Outside of Main
_______________________________

Have a print function that does the following.
- Easy. Have 2 for loops to iterate across the 2d array or matrix. One iterating j, i times where i = 0 to 2, and where j = 0 to 2.

Have fun!