예제 #1
0
 private bool IsSquareValid(Square square)
 {
     return (square.X >= 0 &&
         square.X < _board.RowSize &&
         square.Y >= 0 &&
         square.Y < _board.RowSize);
 }
예제 #2
0
        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;
        }
예제 #3
0
        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);
                }
            }
        }
예제 #4
0
 private Square VerticalDownRight(Square square)
 {
     return new Square(square.X + 2, square.Y + 1);
 }
예제 #5
0
 private Square VerticalDownLeft(Square square)
 {
     return new Square(square.X + 2, square.Y - 1);
 }
예제 #6
0
 private Square HorizontalRightUp(Square square)
 {
     return new Square(square.X - 1, square.Y + 2);
 }
예제 #7
0
 private Square HorizontalRightDown(Square square)
 {
     return new Square(square.X + 1, square.Y + 2);
 }
예제 #8
0
 private Square HorizontalLeftUp(Square square)
 {
     return new Square(square.X - 1, square.Y - 2);
 }
예제 #9
0
 private Square HorizontalLeftDown(Square square)
 {
     return new Square(square.X + 1, square.Y - 2);
 }
예제 #10
0
 /// <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;
 }
예제 #11
0
 private Square VerticalUpRight(Square square)
 {
     return new Square(square.X - 2, square.Y + 1);
 }
예제 #12
0
 private Square VerticalUpLeft(Square square)
 {
     return new Square(square.X - 2, square.Y - 1);
 }