Demo poruszania się agenta, poprawka
This commit is contained in:
parent
d720d255c5
commit
bb4800eb33
21
agent.py
21
agent.py
@ -11,6 +11,24 @@ class Agent:
|
|||||||
self.is_loaded = False
|
self.is_loaded = False
|
||||||
|
|
||||||
|
|
||||||
|
def demo_agent_move(self, demo_agent_step, demo_step_max=5):
|
||||||
|
demo_agent_sign = 0
|
||||||
|
next_coords = self.get_next_move_coordinates()
|
||||||
|
can_move = self.check_if_can_move(next_coords)
|
||||||
|
if demo_agent_step >= demo_step_max:
|
||||||
|
demo_agent_sign = -1
|
||||||
|
self.direction = 'up'
|
||||||
|
elif demo_agent_step == 0:
|
||||||
|
demo_agent_sign = 1
|
||||||
|
self.direction = 'down'
|
||||||
|
if not can_move:
|
||||||
|
# alt_move_left =
|
||||||
|
# alt_move_right =
|
||||||
|
alternative_move = ('left' if self.check_if_can_move(self.move_left()) else None) or ('right' if self.check_if_can_move(self.move_right()) else self.direction)
|
||||||
|
self.direction = alternative_move
|
||||||
|
else:
|
||||||
|
self.x = next_coords.x
|
||||||
|
self.y = next_coords.y
|
||||||
def move(self):
|
def move(self):
|
||||||
next_coords = self.get_next_move_coordinates()
|
next_coords = self.get_next_move_coordinates()
|
||||||
can_move = self.check_if_can_move(next_coords)
|
can_move = self.check_if_can_move(next_coords)
|
||||||
@ -33,7 +51,8 @@ class Agent:
|
|||||||
# pdb.set_trace()
|
# pdb.set_trace()
|
||||||
next_tile = self.assigned_warehouse.tiles[next_coords.x][next_coords.y]
|
next_tile = self.assigned_warehouse.tiles[next_coords.x][next_coords.y]
|
||||||
tile_passable = isinstance(next_tile, Tile) and next_tile.category.passable
|
tile_passable = isinstance(next_tile, Tile) and next_tile.category.passable
|
||||||
return tile_passable
|
tile_on_map = 0 <= next_coords.x < self.assigned_warehouse.width and 0 <= next_coords.y < self.assigned_warehouse.height
|
||||||
|
return tile_passable and tile_on_map
|
||||||
|
|
||||||
def move_right(self):
|
def move_right(self):
|
||||||
pos_x = self.x + 1
|
pos_x = self.x + 1
|
||||||
|
@ -16,3 +16,13 @@ PACK_CATEGORIES = {
|
|||||||
'general',
|
'general',
|
||||||
'freezed',
|
'freezed',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
COLORS = {
|
||||||
|
'white': (255, 255, 255),
|
||||||
|
'black': (0, 0, 0),
|
||||||
|
'gray': (128, 128, 128),
|
||||||
|
'darkgray': (60, 60, 60),
|
||||||
|
'yellow': (235, 235, 0),
|
||||||
|
'lightgreen': (70, 238, 70),
|
||||||
|
'red': (255, 0, 0)
|
||||||
|
}
|
19
main.py
19
main.py
@ -3,18 +3,9 @@ import warehouse
|
|||||||
import agent
|
import agent
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
from attributes import PackSize, PackStatus
|
from attributes import PackSize, PackStatus, COLORS
|
||||||
|
|
||||||
WINDOW_SIZE = (600, 600)
|
WINDOW_SIZE = (600, 600)
|
||||||
COLORS = {
|
|
||||||
'white': (255, 255, 255),
|
|
||||||
'black': (0, 0, 0),
|
|
||||||
'gray': (128, 128, 128),
|
|
||||||
'darkgray': (60, 60, 60),
|
|
||||||
'yellow': (235, 235, 0),
|
|
||||||
'lightgreen': (70, 238, 70),
|
|
||||||
'red': (255, 0, 0)
|
|
||||||
}
|
|
||||||
COLOR_OF_FIELD = {
|
COLOR_OF_FIELD = {
|
||||||
'Floor': 'gray',
|
'Floor': 'gray',
|
||||||
'Rack': 'white',
|
'Rack': 'white',
|
||||||
@ -32,6 +23,7 @@ class MainGameFrame:
|
|||||||
starting_x, starting_y = self.set_starting_agent_position()
|
starting_x, starting_y = self.set_starting_agent_position()
|
||||||
self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map, agent_radius)
|
self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map, agent_radius)
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
demo_agent_step = 1
|
demo_agent_step = 1
|
||||||
demo_agent_sign = 1
|
demo_agent_sign = 1
|
||||||
@ -43,14 +35,13 @@ class MainGameFrame:
|
|||||||
self.draw_floor()
|
self.draw_floor()
|
||||||
self.draw_packages()
|
self.draw_packages()
|
||||||
self.draw_agent()
|
self.draw_agent()
|
||||||
self.agent.move()
|
self.agent.demo_agent_move(demo_agent_step, 8) #linijka w celu zademonstrowania poruszania się agenta
|
||||||
|
# self.agent.move() #oryginalna linijka
|
||||||
demo_agent_step += (1*demo_agent_sign)
|
demo_agent_step += (1*demo_agent_sign)
|
||||||
if demo_agent_step >= 10:
|
if demo_agent_step >= 8:
|
||||||
demo_agent_sign = -1
|
demo_agent_sign = -1
|
||||||
self.agent.direction = 'up'
|
|
||||||
if demo_agent_step == 0:
|
if demo_agent_step == 0:
|
||||||
demo_agent_sign = 1
|
demo_agent_sign = 1
|
||||||
self.agent.direction = 'down'
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
self.clock.tick(5)
|
self.clock.tick(5)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user