Coders Packet

winner of the tic-tac-toe game using C++

By deepshikha

This project is about finding the winner in Tic-tac-toe game using C++. Tic-tac-toe is played by two players A and B on a 3 x 3 grid.

Rules for Tic-tac-toe

  • Players perform their turns by placing characters into the empty squares (" ").
  • The first player A always place's "X" character, while the second player B always place "O" characters
  • "X" and "O" characters should be placed into the empty squares, never on the filled ones you cannot overwrite the characters nor change the characters.
  • The game will end if there are 3 of the same "X" characters or "Y" Characters filling any row, column, or diagonal. 
  • The game will also end if all the squares are non-empty, and if no one wins then the game is "Draw".
  • You cannot place any moves if the game is over and there are no squares left to be filled.

It will Return the winner of the game if it exists (A or B), the game ends in a draw if neither of them wins and all the squares are filled, it will return "Draw" if there are still movements to play return "Pending".

For example

Input: For the moves = { [0,0], [2,0], [1,1], [2,1], [2,2] }

Output: "A is the winner"


A always plays first : 

| X |      | X  |     | X  |      | X |      | X |

|    | -> |     | -> | X  | -> | X | -> | X |

|    |      | O |      | O  |     | O |      | |



Download Complete Code


No comments yet