public static IState MoveRight(IState currentState, int blockSize) { GridWorldState state = (GridWorldState)currentState; GridWorldState new_state = new GridWorldState(state.X + blockSize, state.Y); return(new_state); }
public IOutcome act(IState currentState, IOperator op) { GridWorldState state = (GridWorldState)currentState; IState succ; if (op.Equals(MoveOperators.Up)) { if (!GWMap.isUpFree(state.X, state.Y, blockSize)) { throw new NotApplicableOperatorException("not applicable operator"); } succ = MoveOperators.MoveUp(currentState, blockSize); return(new Outcome(succ, cost)); } if (op.Equals(MoveOperators.Down)) { if (!GWMap.isDownFree(state.X, state.Y, blockSize)) { throw new NotApplicableOperatorException("not applicable operator"); } succ = MoveOperators.MoveDown(currentState, blockSize); return(new Outcome(succ, cost)); } if (op.Equals(MoveOperators.Left)) { if (!GWMap.isLeftFree(state.X, state.Y, blockSize)) { throw new NotApplicableOperatorException("not applicable operator"); } succ = MoveOperators.MoveLeft(currentState, blockSize); return(new Outcome(succ, cost)); } if (op.Equals(MoveOperators.Right)) { if (!GWMap.isRightFree(state.X, state.Y, blockSize)) { throw new NotApplicableOperatorException("not applicable operator"); } succ = MoveOperators.MoveRight(currentState, blockSize); return(new Outcome(succ, cost)); } throw new NotApplicableOperatorException("Unknown operator"); }
public int Calculate(ANode Node, ANode Goal) { var node = Node; var goal = Goal; GridWorldState node_state = (GridWorldState)node.State; GridWorldState goal_state = (GridWorldState)goal.State; int positive1 = (node_state.X - goal_state.X) / blockSize; positive1 = positive1 > 0 ? positive1 : -positive1; int positive2 = (node_state.Y - goal_state.Y) / blockSize; positive2 = positive2 > 0 ? positive2 : -positive2; return(positive1 + positive2); }
public IEnumerable <IOperator> ApplicableOperators(IState currentState) { GridWorldState state = (GridWorldState)currentState; List <IOperator> applicableOperators = new List <IOperator>(); if (GWMap.isDownFree(state.X, state.Y, blockSize)) { applicableOperators.Add(MoveOperators.Down); } if (GWMap.isLeftFree(state.X, state.Y, blockSize)) { applicableOperators.Add(MoveOperators.Left); } if (GWMap.isRightFree(state.X, state.Y, blockSize)) { applicableOperators.Add(MoveOperators.Right); } if (GWMap.isUpFree(state.X, state.Y, blockSize)) { applicableOperators.Add(MoveOperators.Up); } return(applicableOperators); }