示例#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);
 }