public void ShuffleEigthPuzzleInitialState(AriciePropertyEditorControl ape)
        {
            var eightPuzzleBoard = new EightPuzzleBoard(EightPuzzleInitialState.ToArray());

            var actionsFunction = EightPuzzleFunctionFactory.getActionsFunction();
            var resultFunction  = EightPuzzleFunctionFactory.getResultFunction();
            var previousBoards  = new HashSet <EightPuzzleBoard>();

            for (int i = 0; i < EightPuzzleShuffleMoves; i++)
            {
                Object[] successors = actionsFunction.actions(eightPuzzleBoard).toArray();

                EightPuzzleBoard nextState;
                do
                {
                    var choosenSuccessorIdx = CryptoHelper.Random.Next(successors.Length);
                    var objAction           = (aima.core.agent.Action)successors[choosenSuccessorIdx];
                    nextState = (EightPuzzleBoard)resultFunction.result(eightPuzzleBoard, objAction);
                } while (previousBoards.Contains(nextState));

                previousBoards.Add(eightPuzzleBoard);
                eightPuzzleBoard = (EightPuzzleBoard)nextState;
            }
            EightPuzzleInitialState = new List <int>(eightPuzzleBoard.getState());
            ape.ItemChanged         = true;
        }
Example #2
0
 public void testGetBoard()
 {
     int[] expected  = new int[] { 5, 4, 0, 6, 1, 8, 7, 3, 2 };
     int[] boardRepr = board.getState();
     Assert.AreEqual(expected[0], boardRepr[0]);
     Assert.AreEqual(expected[1], boardRepr[1]);
     Assert.AreEqual(expected[2], boardRepr[2]);
     Assert.AreEqual(expected[3], boardRepr[3]);
     Assert.AreEqual(expected[4], boardRepr[4]);
     Assert.AreEqual(expected[5], boardRepr[5]);
     Assert.AreEqual(expected[6], boardRepr[6]);
     Assert.AreEqual(expected[7], boardRepr[7]);
     Assert.AreEqual(expected[8], boardRepr[8]);
 }