Beispiel #1
0
 public AppearNode(GameBoard board, Direction moveDirection, PositionEvaluator evaluator)
 {
     instances++;
     this.board = board.move(moveDirection);
     this.lastDirection = moveDirection;
     this.evaluator = evaluator;
 }
Beispiel #2
0
 public Direction getDirection(GameBoard board)
 {
     if (!board.Equals(board.move(Direction.Up)))
     {
         return Direction.Up;
     }
     else if (!board.Equals(board.move(Direction.Left)))
     {
         return Direction.Left;
     }
     else if (!board.Equals(board.move(Direction.Right)))
     {
         return Direction.Right;
     }
     else if (!board.Equals(board.move(Direction.Down)))
     {
         return Direction.Down;
     }
     else
     {
         return Direction.None;
     }
 }
Beispiel #3
0
 public Direction getDirection(GameBoard board)
 {
     double bestScore = -1;
     Direction bestDirection = Direction.None;
     foreach (Direction tryDirection in (Direction[])Enum.GetValues(typeof(Direction)))
     {
         if (tryDirection == Direction.None) continue;
         GameBoard newBoard = board.move(tryDirection);
         if (newBoard.Equals(board)) continue;
         double newScore = evaluator.score(newBoard);
         if (newScore > bestScore)
         {
             bestScore = newScore;
             bestDirection = tryDirection;
         }
     }
     return bestDirection;
 }
Beispiel #4
0
        public void compressRight()
        {
            GameBoard board = new GameBoard(new int[,]{
                                             {2, 2, 2, 0},
                                             {0, 2, 2 , 0},
                                             {0, 0, 4 , 8},
                                             {0, 0, 4 , 4}
                                             }
                                           );

            GameBoard actual = board.move(Direction.Right);

            GameBoard expected = new GameBoard(new int[,]{
                                             {0, 0, 2, 4},
                                             {0, 0, 0, 4},
                                             {0, 0, 4 , 8},
                                             {0, 0, 0 , 8}
                                             }
                                           );

            Assert.IsTrue(expected.Equals(actual));
        }
Beispiel #5
0
        public void compressLeft()
        {
            GameBoard board = new GameBoard(new int[,]{
                                             {2, 2, 0, 0},
                                             {0, 2, 2 , 2},
                                             {0, 0, 4 , 8},
                                             {0, 0, 4 , 4}
                                             }
                                           );

            GameBoard actual = board.move(Direction.Left);

            GameBoard expected = new GameBoard(new int[,]{
                                             {4, 0, 0, 0},
                                             {4, 2, 0 , 0},
                                             {4, 8, 0 , 0},
                                             {8, 0, 0 , 0}
                                             }
                                           );

            Assert.IsTrue(expected.Equals(actual));
        }
Beispiel #6
0
        public void compressDown()
        {
            GameBoard board = new GameBoard(new int[,]{
                                             {2, 2, 0, 0},
                                             {0, 2, 2 , 0},
                                             {0, 2, 4 , 8},
                                             {0, 0, 4 , 4}
                                             }
                                           );

            GameBoard actual = board.move(Direction.Down);
            board.print();

            GameBoard expected = new GameBoard(new int[,]{
                                             {0, 0, 0, 0},
                                             {0, 0,  0, 0},
                                             {0, 2, 2, 8},
                                             {2, 4, 8, 4}
                                             }
                                           );

            Assert.IsTrue(expected.Equals(actual));
        }