Assignment 10 Solution

$30.00 $26.70


Write a class called GBoard that represents the board for a game that is like tic-tac-toe, but on a larger scale. Instead of a 3×3 board, it is played on a 15×15 board, and instead of 3 in a row, each player is trying to get 5 in row.

The class should have two data members – a 2D array of char that represents the board, and an enum variable called gameState that holds one of the four following values: X_WON, O_WON, DRAW, or UNFINISHED – use an enum for this, not strings (the enum definition should go in GBoard.hpp, before the class, not inside it).

It should have a default constructor that initializes all elements of the array to being empty (you can use whatever character you want to represent that a square is empty), and initializes the gameState to UNFINISHED.

It should have a method called getGameState that returns the value of gameState.

It should have a method called makeMove that takes as parameters an int for the row, an int for the column, and a char for the player. The row and column will be in the range 0-14. The player will be either ‘x’ or ‘o’. This method should return false if the square is already occupied or the game had already finished. Otherwise it should add the move to the board, update the gameState, and return true. Be careful to not access your array out of bounds – including in the condition of an if statement or loop.

It’s not required, but you’ll probably find it useful for testing and debugging to have a method that prints out the board.

Whether you think of the array indices as being [row][column] or [column][row] doesn’t matter as long as you’re consistent.

Your class only represents the board, it doesn’t actually allow two players to play the game. Other code (that you don’t have to write) would use your Board class to make that happen.

The files must be named: GBoard.hpp and GBoard.cpp