private bool IsSquareValid(Square square) { return (square.X >= 0 && square.X < _board.RowSize && square.Y >= 0 && square.Y < _board.RowSize); }
public List<Square> GetMove(Square square) { var movesList = new List<Square>(); var move = HorizontalLeftUp(square); if (IsSquareValid(move)) movesList.Add(move); move = HorizontalLeftDown(square); if (IsSquareValid(move)) movesList.Add(move); move = HorizontalRightUp(square); if (IsSquareValid(move)) movesList.Add(move); move = HorizontalRightDown(square); if (IsSquareValid(move)) movesList.Add(move); move = VerticalUpLeft(square); if (IsSquareValid(move)) movesList.Add(move); move = VerticalUpRight(square); if (IsSquareValid(move)) movesList.Add(move); move = VerticalDownLeft(square); if (IsSquareValid(move)) movesList.Add(move); move = VerticalDownRight(square); if (IsSquareValid(move)) movesList.Add(move); movesList.RemoveAll(Visited); // randomize the order of a list to provide various detours each time movesList.Shuffle(); return movesList; }
public Board(int size) { RowSize = size; // Create the array to store the squares. _board = new Square[RowSize, RowSize]; // Populate the board with Square objects. for (int i = 0; i < RowSize; ++i) { for (int j = 0; j < RowSize; ++j) { _board[i, j] = new Square(i, j); } } }
private Square VerticalDownRight(Square square) { return new Square(square.X + 2, square.Y + 1); }
private Square VerticalDownLeft(Square square) { return new Square(square.X + 2, square.Y - 1); }
private Square HorizontalRightUp(Square square) { return new Square(square.X - 1, square.Y + 2); }
private Square HorizontalRightDown(Square square) { return new Square(square.X + 1, square.Y + 2); }
private Square HorizontalLeftUp(Square square) { return new Square(square.X - 1, square.Y - 2); }
private Square HorizontalLeftDown(Square square) { return new Square(square.X + 1, square.Y - 2); }
/// <summary> /// Search predicate. /// </summary> /// <param name="square">square</param> /// <returns>Returns true if a Square had visited.</returns> private bool Visited(Square s) { return _board.GetSquare(s.X, s.Y).HasVisited; }
private Square VerticalUpRight(Square square) { return new Square(square.X - 2, square.Y + 1); }
private Square VerticalUpLeft(Square square) { return new Square(square.X - 2, square.Y - 1); }