public int GetIndex(Move move) { return this.GetIndex(move.X, move.Y); }
public static bool GetDiagonalWinningMove(bool reverse, bool playerPiece, BrainResult result, Board board) { // setup int notPlayerPieceCount = 0; // get direction values int num = reverse ? board.BoardWidth - 1 : 0; int step = reverse ? -1 : 1; int x = 0, y = 0; // find lines for (int i = num; i < board.BoardSize - num; i += board.BoardWidth + step) { if (!board.IsSamePlayerPiece(playerPiece, i)) { notPlayerPieceCount++; if (notPlayerPieceCount > 1) { notPlayerPieceCount = 0; break; } // get the xy co-ords x = reverse ? i % board.BoardWidth : i / board.BoardWidth; y = i / board.BoardHeight; } } var move = new Move(x, y); if (notPlayerPieceCount == 1 && board.IsValidMove(x, y)) { // we found a place result.Moves.Add(move); return true; } // no place return false; }
public bool IsSamePlayerPiece(bool playerPiece, Move move) { return this.IsSamePlayerPiece(playerPiece, this.GetIndex(move.X, move.Y)); }