minor fixes

This commit is contained in:
Makrellka 2022-04-28 00:29:29 +02:00
parent 4caef2e9ae
commit 3c5dfc2e34

View File

@ -49,28 +49,28 @@ class PathFinderOnStates:
return currState.cost + self.heuristic(currState.agent_position, self.goal)
def getPositionAfterMove(self, currState: PathFinderState) -> GridLocation:
result : GridLocation
result: GridLocation = None
if currState.agent_position == Direction.top:
currState.agent_position[0] += 1
result = currState.agent_position
elif currState.agent_position == Direction.down:
currState.agent_position[0] -= 1
result= currState.agent_position
elif currState.agent_position == Direction.right:
currState.agent_position[1] += 1
result = currState.agent_position
elif currState.agent_position == Direction.right:
elif currState.agent_position == Direction.down:
currState.agent_position[1] -= 1
result = currState.agent_position
elif currState.agent_position == Direction.right:
currState.agent_position[0] += 1
result = currState.agent_position
elif currState.agent_position == Direction.left:
currState.agent_position[0] -= 1
result = currState.agent_position
return result
def isMovePossible(self, currState: PathFinderState)-> bool:
positionAfterMove =self.getPositionAfterMove(currState)
def isMovePossible(self, currState: PathFinderState) -> bool:
positionAfterMove = self.getPositionAfterMove(currState)
if positionAfterMove in self.game_constants.walls:
return False
elif positionAfterMove in self.game_constants.grid_height:
elif positionAfterMove[0] < 0 or positionAfterMove[0] > self.game_constants.grid_width:
return False
elif positionAfterMove in self.game_constants.grid_width:
elif positionAfterMove[1] < 0 or positionAfterMove[1] > self.game_constants.grid_height:
return False
else:
return True
@ -78,7 +78,8 @@ class PathFinderOnStates:
def createState(self, currState: PathFinderState, action: ActionType) -> PathFinderState:
cost = currState.cost + 1
last_action = action
action_taken = currState.action_taken.append(action)
action_taken: List[ActionType] = []
action_taken.extend(currState.action_taken)
agent_position = currState.agent_position
agent_direction = currState.agent_direction
@ -100,13 +101,13 @@ class PathFinderOnStates:
# reprezentacja kazdego stanu co moge podjac z tego miejsca
# generowanie stanu
# sprawdz w ktorym kierunku obrocony
possibleNextStates: List[PathFinderState]
possibleNextStates: List[PathFinderState] = []
if currState.agent_direction == Direction.top:
possibleNextStates.append(self.createState(currState, ActionType.ROTATE_RIGHT))
possibleNextStates.append(self.createState(currState, ActionType.ROTATE_LEFT))
possibleNextStates.append(self.createState(currState, ActionType.ROTATE_DOWN))
if self.isMovePossible(currState):
possibleNextStates.append(self.createState(currState,ActionType.MOVE))
possibleNextStates.append(self.createState(currState, ActionType.MOVE))
elif currState.agent_direction == Direction.down:
possibleNextStates.append(self.createState(currState, ActionType.ROTATE_RIGHT))
possibleNextStates.append(self.createState(currState, ActionType.ROTATE_LEFT))
@ -120,7 +121,7 @@ class PathFinderOnStates:
if self.isMovePossible(currState):
possibleNextStates.append(self.createState(currState, ActionType.MOVE))
elif currState.agent_direction == Direction.right:
possibleNextStates.append(self.createState(currState, ActionType.ROTATE_UPT))
possibleNextStates.append(self.createState(currState, ActionType.ROTATE_UP))
possibleNextStates.append(self.createState(currState, ActionType.ROTATE_LEFT))
possibleNextStates.append(self.createState(currState, ActionType.ROTATE_DOWN))
if self.isMovePossible(currState):
@ -131,7 +132,7 @@ class PathFinderOnStates:
best_state: PathFinderState = self.queue.get()
while best_state.agent_position != self.goal and not self.queue.empty():
#dodajesz do kolejki stany z expansion (po cost)
# dodajesz do kolejki stany z expansion (po cost)
for state in self.expansion(best_state):
self.queue.put(state, self.evaluate(state))