Starting from:
$35

$29

TIC TAC TOE Solution

Problem Description:
The game is that of a simple tic tac toe. We used a function to call the grid which we made using a 2D array. The grid has numbers 1 to 9 stored so the person choses the place to put his X or O. The numbers are stored as string and the person enters a move which is stored in a variable. We had to find a way to allow the players make move alternatively and if the box is occupied then the game asks for the player to enter again. Win needed to be checked after the players move. We had to add AI to allow the computer to play against player. We had to ask players name and keep a track of score after multiple games. Same needed to be done for the computer.

Problem Handling:
Player vs player has separate functions for each player making a move. A variable declared as 1 keeps track of move and changes to -1 after a move and when it is -1 the move shifts to the other player. A function that checks if the player has won, is called after every player move. The win function has horizontal, vertical and diagonal checks using for loops and searching in 2D array. The same is done for player vs computer but the computer move function has 2 function within, 1 for easy and 1 for hard. Easy function uses random number generation. The number is converted to string using atoi() and then compared to grid to make a move. In Hard version, the computer checks grid to see if there are 2 similar characters, that the computer uses, in line and then places move to win. If not, then the computer uses checks to see if the player has 2 moves in line and then blocks him. If not, then the computer makes a random move. Counter is used to keeps track of total moves and total wins. When error comes, player is asked again and counter is not incremented. When player wins, the counters keep track of wins using player names.

Future Improvement:
The code can be updated to ask the player if he wants to play a game with grid different than 3x3. If yes, then there is an option for playing a game of grid nxn where user enters value of n. Then project is converted so the checks are altered accordingly to see how many moves are in line. Incorporate GUI to allow user to choose box using mouse. Make a new level where computer plays in such a way as to use double cross every time and making it impossible to win (tough in making a game this is not very smart as it won’t have appeal). Allow for the game to be saved by the user and reproduced at a later time.

More products