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); }
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); }