public static void Main(params string[] args)
        {
            IRandom          r     = CommonFactory.CreateRandom();
            EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 0, 1, 2, 3,
                                                                      4, 5, 6, 7, 8 });

            for (int i = 0; i < 50; ++i)
            {
                int th = r.Next(4);
                if (th == 0)
                {
                    board.moveGapUp();
                }
                if (th == 1)
                {
                    board.moveGapDown();
                }
                if (th == 2)
                {
                    board.moveGapLeft();
                }
                if (th == 3)
                {
                    board.moveGapRight();
                }
            }
            System.Console.WriteLine(board);
        }
        public void testGenerateCorrectWhenGapMovedRightward()
        {
            board.moveGapLeft();// gives { 1, 2, 5, 3, 0, 4, 6, 7, 8 }
            Assert.AreEqual(new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 0, 4,
                                                             6, 7, 8 }), board);

            ICollection <IAction> actions = CollectionFactory.CreateQueue <IAction>(EightPuzzleFunctions.getActions(board));

            Assert.AreEqual(4, actions.Size());

            EightPuzzleBoard expectedFourth = new EightPuzzleBoard(new int[] { 1,
                                                                               2, 5, 3, 4, 0, 6, 7, 8 });
            EightPuzzleBoard actualFourth = (EightPuzzleBoard)EightPuzzleFunctions.getResult(board, actions.Get(3));

            Assert.AreEqual(expectedFourth, actualFourth);
            Assert.AreEqual(EightPuzzleBoard.RIGHT, actions.Get(3));
        }
Exemplo n.º 3
0
 public void testPosition1MoveLeft()
 {
     board.moveGapLeft();
     Assert.AreEqual(new EightPuzzleBoard(new int[] { 0, 5, 4, 6, 1, 8,
                                                      7, 3, 2 }), board);
 }