public List<GridState> getAdjacentStates(GridState s) { List<GridState> result = new ArrayList<GridState>(); GridState northState = this.getState(s.getRow() - 1, s.getColumn()); GridState southState = this.getState(s.getRow() + 1, s.getColumn()); GridState eastState = this.getState(s.getRow(), s.getColumn() + 1); GridState westState = this.getState(s.getRow(), s.getColumn() - 1); if (!isStateBlocked(northState)) { result.add(northState); } if (!isStateBlocked(southState)) { result.add(southState); } if (!isStateBlocked(eastState)) { result.add(eastState); } if (!isStateBlocked(westState)) { result.add(westState); } if (!isStateBlocked(s)) { result.add(s); } return result; }
public Action determineActionToState(GridState currentState, GridState targetState) { int rowDiff = currentState.getRow() - targetState.getRow(); int colDiff = currentState.getColumn() - targetState.getColumn(); if (rowDiff == 0 && colDiff == 0) return null; if (Math.abs(rowDiff) >= Math.abs(colDiff)) { if (rowDiff < 0) return GridWorld.ACTION_SOUTH; else return GridWorld.ACTION_NORTH; } else { if (colDiff < 0) return GridWorld.ACTION_EAST; else return GridWorld.ACTION_WEST; } }
public static double euclideanDistance(GridState s1, GridState s2) { double d = EncogMath.square(s1.getRow() - s2.getRow()) + EncogMath.square(s1.getColumn() - s2.getColumn()); return Math.sqrt(d); }