void DoHorizontalTests() { for (int y = 0; y < ConnectFour.BOARD_HEIGHT; y++) { // Create a board where we shift the four occupied cells right each loop until they no longer fit for (int startX = 0; startX <= ConnectFour.BOARD_WIDTH - ConnectFour.SEQ_COUNT; startX++) { byte[,] board = new byte[ConnectFour.BOARD_WIDTH, ConnectFour.BOARD_HEIGHT]; for (int x = 0; x < ConnectFour.SEQ_COUNT; x++) { board[startX + x, y] = 1; } // Set the board directly connectFour.SetBoard(board); // Print the board connectFour.PrintBoard(); // Try to solve the board in its entirity connectFour.CheckForWin(1); // Try to solve just the row connectFour.CheckForWinIncremental(1, new Vector2Int(0, y)); } } }
// Does the move for this board in a specific column. // If this returns true, the move resulted in a win and we should stop constructing the board deeper than this point public bool DoMove(int column) { if (!ConnectFour.IsPlayerValid(move.playerId)) { Debug.LogError("BoardState : Set valid playerId first!"); return(false); } move.column = column; board.Drop(move.playerId, column, out move.row); UpdateScore(); // Return true if the column is now occupied, or the move won, or if it was a stalemate return(board.IsSpaceOccupied(column, 0) || board.CheckForWinIncremental(move.playerId, move.coord) || board.CheckForStalemate()); }