/// <summary> /// Gets a list of all valid moves that could be performed on the board in its current state. /// </summary> /// <returns></returns> private List<Move> GetAllCurrentValidMoves() { List<Move> moves = new List<Move>(); for (int x = 0; x < 7; x++) { for (int y = 0; y < 7; y++) { // If the initial coordinate is not full, the move isn't valid if (_board[x, y] != State.Full) continue; Coordinate coordinate = new Coordinate(x, y); for (int d = 0; d < 4; d++) { Direction direction = (Direction)d; Move move = new Move(coordinate, GetJumpedCoordinate(coordinate, direction), GetFinalCoordinate(coordinate, direction), direction); if (IsMoveValid(move)) { moves.Add(move); } } } } return moves; }
/// <summary> /// Determines whether or not a move is valid given the current state of the board. /// </summary> /// <param name="move">The move to test.</param> /// <returns>Returns true if the move is valid, otherwise false.</returns> private bool IsMoveValid(Move move) { int initialX = move.InitialLocation.X; int initialY = move.InitialLocation.Y; int jumpedX = move.JumpedLocation.X; int jumpedY = move.JumpedLocation.Y; int finalX = move.FinalLocation.X; int finalY = move.FinalLocation.Y; if (initialX < 0 || initialX > 6 || initialY < 0 || initialY > 6) return false; if (finalX < 0 || finalX > 6 || finalY < 0 || finalY > 6) return false; if (_board[initialX, initialY] != State.Full) return false; if (_board[jumpedX, jumpedY] != State.Full) return false; if (_board[finalX, finalY] != State.Open) return false; return true; }
/// <summary> /// Executes a move on the board. This method does NOT check to ensure that the move is valid. /// </summary> /// <param name="move">The move to perform.</param> private void ExecuteMove(Move move) { _board[move.InitialLocation.X, move.InitialLocation.Y] = State.Open; _board[move.JumpedLocation.X, move.JumpedLocation.Y] = State.Open; _board[move.FinalLocation.X, move.FinalLocation.Y] = State.Full; }