Designing a tic-tac-toe player (CPU) that never loses, and wins whenever possible. This programme has used basic concepts like conditionals, loops, jumps, functions.
Our program first asks whether the user chooses to be Player 1 or Player 2. The symbols in the grid for players 1 and 2 will be X and O respectively. As a move, the player will be expected to input a number from 1 to 9, considering the cells in the top, middle, and bottom rows to be numbered 1-3, 4-6, and 7-9 from left to right, respectively. After each move, Our program displays the tic-tac-toe grid in the terminal. For example, a typical state of the game could look like this:
| O | X
------------
| |
------------
X | |
The game concludes when a player wins, or all the cells are filled if it is a draw. After the conclusion of a game, the program asks the user whether he wants to play another game or not, and proceed accordingly.
Submitted by Hritwick Manna (hritwickmanna)
Download packets of source code on Coders Packet
Comments