Tic Tac Toe, Help/Determine Winner

前端 未结 4 858
离开以前
离开以前 2021-01-28 23:42

I\'m creating a TicTacToe class that contains a 3 by 3 rectangular array of integers & is played by 2 human players. \"1\" is used for the first player\'s move & \"2\" i

4条回答
  •  有刺的猬
    2021-01-29 00:22

    I wont code it for you but here is the logic you can use:

    1) For each column check if all rows are the same, if yes declare winner. If not go to step 2.

    2) For each row check if all column values are the same, if yes declare winner. If not go to step 3.

    3) Now check diagonals, there are only two possibilities here [0,0] [1,1] [2,2] and also [0,2] [1,1] [2,0] if they are the same declare winner, if not check whether all values in array are filled, if yes declare draw if not make users enter values.

提交回复
热议问题