コード例 #1
0
        public static EightPuzzleBoard getResult(EightPuzzleBoard state, IAction action)
        {
            EightPuzzleBoard result = new EightPuzzleBoard(state);

            if (EightPuzzleBoard.UP.Equals(action) && state.canMoveGap(EightPuzzleBoard.UP))
            {
                result.moveGapUp();
            }
            else if (EightPuzzleBoard.DOWN.Equals(action) && state.canMoveGap(EightPuzzleBoard.DOWN))
            {
                result.moveGapDown();
            }
            else if (EightPuzzleBoard.LEFT.Equals(action) && state.canMoveGap(EightPuzzleBoard.LEFT))
            {
                result.moveGapLeft();
            }
            else if (EightPuzzleBoard.RIGHT.Equals(action) && state.canMoveGap(EightPuzzleBoard.RIGHT))
            {
                result.moveGapRight();
            }
            return(result);
        }
コード例 #2
0
        public static ICollection <IAction> getActions(EightPuzzleBoard state)
        {
            ICollection <IAction> actions = CollectionFactory.CreateQueue <IAction>();

            if (state.canMoveGap(EightPuzzleBoard.UP))
            {
                actions.Add(EightPuzzleBoard.UP);
            }
            if (state.canMoveGap(EightPuzzleBoard.DOWN))
            {
                actions.Add(EightPuzzleBoard.DOWN);
            }
            if (state.canMoveGap(EightPuzzleBoard.LEFT))
            {
                actions.Add(EightPuzzleBoard.LEFT);
            }
            if (state.canMoveGap(EightPuzzleBoard.RIGHT))
            {
                actions.Add(EightPuzzleBoard.RIGHT);
            }

            return(actions);
        }