Tic Tac Toe, Help/Determine Winner

前端 未结 4 901
离开以前
离开以前 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:14

    One simple approach is to try every square (for i = 0; i < 3; for j = 0; j < 3) then if that square is not blank go in every of the eight possible directions, counting each square with the same 'color' until you go off the board. If your count ever reaches the value three then you have a winner position for the color of the starting square.

提交回复
热议问题