Compare commits
No commits in common. "066894d85c8a170a178ea7cfe63ad7d9b3052dcb" and "9ca821bab87006e541cc6754e1645933c02a8c5d" have entirely different histories.
066894d85c
...
9ca821bab8
8
App.py
8
App.py
@ -21,7 +21,7 @@ pole.draw_grid() #musi byc tutaj wywołane ponieważ inicjalizuje sloty do slown
|
|||||||
ui=Ui.Ui(screen)
|
ui=Ui.Ui(screen)
|
||||||
#Tractor creation
|
#Tractor creation
|
||||||
traktor_slot = pole.get_slot_from_cord((0, 0))
|
traktor_slot = pole.get_slot_from_cord((0, 0))
|
||||||
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.opryskiwacz,clock)
|
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.plug,clock)
|
||||||
|
|
||||||
|
|
||||||
def init_demo(): #Demo purpose
|
def init_demo(): #Demo purpose
|
||||||
@ -37,12 +37,8 @@ def init_demo(): #Demo purpose
|
|||||||
ui.render_text_to_console(string_to_print="Przejazd inicjalizujacy- traktor sprawdza poziom nawodnienia")
|
ui.render_text_to_console(string_to_print="Przejazd inicjalizujacy- traktor sprawdza poziom nawodnienia")
|
||||||
traktor.initial_move(pole)
|
traktor.initial_move(pole)
|
||||||
traktor.reset_pos(pole)
|
traktor.reset_pos(pole)
|
||||||
bfsRoot = Tractor.BFS({"x": 0, "y": 0, "direction": "E", "hydradeIndex": traktor.slot_hydrate_dict})
|
|
||||||
bfsRoot.reverse()
|
|
||||||
# ui.render_text_to_console(string_to_print="traktor porusza się ścieżką bfs")
|
|
||||||
traktor.move_by_root(bfsRoot, pole, [traktor.irrigateSlot])
|
|
||||||
start_flag=False
|
start_flag=False
|
||||||
# demo_move()
|
demo_move()
|
||||||
old_info=get_info(old_info)
|
old_info=get_info(old_info)
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
|
4
Pole.py
4
Pole.py
@ -55,8 +55,8 @@ class Pole:
|
|||||||
def check_collision(self,mouse_x,mouse_y):
|
def check_collision(self,mouse_x,mouse_y):
|
||||||
mouse_x=math.floor(mouse_x/dCon.CUBE_SIZE)
|
mouse_x=math.floor(mouse_x/dCon.CUBE_SIZE)
|
||||||
mouse_y=math.floor(mouse_y/dCon.CUBE_SIZE)
|
mouse_y=math.floor(mouse_y/dCon.CUBE_SIZE)
|
||||||
if(mouse_x<dCon.NUM_X):
|
if(mouse_x<20):
|
||||||
if(mouse_y<dCon.NUM_Y):
|
if(mouse_y<12):
|
||||||
collided=self.get_slot_from_cord((mouse_x,mouse_y))
|
collided=self.get_slot_from_cord((mouse_x,mouse_y))
|
||||||
return collided.print_status()
|
return collided.print_status()
|
||||||
return ""
|
return ""
|
2
Slot.py
2
Slot.py
@ -51,6 +51,4 @@ class Slot:
|
|||||||
|
|
||||||
def print_status(self):
|
def print_status(self):
|
||||||
return f"wspolrzedne: (X:{self.x_axis} Y:{self.y_axis}) "+self.plant.report_status()
|
return f"wspolrzedne: (X:{self.x_axis} Y:{self.y_axis}) "+self.plant.report_status()
|
||||||
def irrigatePlant(self):
|
|
||||||
self.plant.stan.nawodnienie = 100
|
|
||||||
|
|
34
Tractor.py
34
Tractor.py
@ -72,12 +72,7 @@ def BFS(istate):
|
|||||||
elem = fringe.pop(0)
|
elem = fringe.pop(0)
|
||||||
|
|
||||||
if goalTest(elem.state["hydradeIndex"]):
|
if goalTest(elem.state["hydradeIndex"]):
|
||||||
x = elem
|
return elem #TODO ciąg akcji zbudowany z wykorzystaniem pól parent i action
|
||||||
tab = []
|
|
||||||
while x.parent != None:
|
|
||||||
tab.append(x.action)
|
|
||||||
x = x.parent
|
|
||||||
return tab
|
|
||||||
|
|
||||||
explored.append(elem)
|
explored.append(elem)
|
||||||
|
|
||||||
@ -186,40 +181,23 @@ class Tractor:
|
|||||||
self.do_move_if_valid(pole,(0,0))
|
self.do_move_if_valid(pole,(0,0))
|
||||||
|
|
||||||
def initial_move(self,pole):
|
def initial_move(self,pole):
|
||||||
for y in range (0,dCon.NUM_Y):
|
for y in range (0,12):
|
||||||
if(y%2==0):
|
if(y%2==0):
|
||||||
for x in range(0,dCon.NUM_X):
|
for x in range(0,20):
|
||||||
self.snake_move(pole,x,y)
|
self.snake_move(pole,x,y)
|
||||||
else:
|
else:
|
||||||
for x in range(dCon.NUM_X,-1,-1):
|
for x in range(20,0,-1):
|
||||||
self.snake_move(pole,x,y)
|
self.snake_move(pole,x,y)
|
||||||
|
|
||||||
|
|
||||||
def snake_move(self,pole,x,y):
|
def snake_move(self,pole,x,y):
|
||||||
next_slot_coordinates=(x,y)
|
next_slot_coordinates=(x,y)
|
||||||
if(self.do_move_if_valid(pole,next_slot_coordinates)):
|
if(self.do_move_if_valid(pole,next_slot_coordinates)):
|
||||||
if pole.get_slot_from_cord((x,y)).get_hydrate_stats() < 60:
|
self.slot_hydrate_dict[(x,y)]= pole.get_slot_from_cord((x,y)).get_hydrate_stats() #Budowanie slownika slotow z poziomem nawodnienia dla traktorka
|
||||||
hydrateIndex = 0
|
|
||||||
else:
|
|
||||||
hydrateIndex = 1
|
|
||||||
self.slot_hydrate_dict[(x,y)]= hydrateIndex #Budowanie slownika slotow z poziomem nawodnienia dla traktorka
|
|
||||||
self.clock.tick(10)
|
self.clock.tick(10)
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
quit()
|
quit()
|
||||||
def move_by_root(self, root, pole, actions = None):
|
|
||||||
for move in root:
|
|
||||||
self.slot.redraw_image()
|
|
||||||
if move == 'forward':
|
|
||||||
self.move_forward(pole)
|
|
||||||
if move == 'right':
|
|
||||||
self.turn_right()
|
|
||||||
if move == 'left':
|
|
||||||
self.turn_left()
|
|
||||||
for a in actions:
|
|
||||||
a()
|
|
||||||
|
|
||||||
self.clock.tick(3)
|
|
||||||
|
|
||||||
#to tak zrobiłam już na później, może się przyda
|
#to tak zrobiłam już na później, może się przyda
|
||||||
def change_osprzet(self, new_osprzet):
|
def change_osprzet(self, new_osprzet):
|
||||||
@ -235,6 +213,4 @@ class Tractor:
|
|||||||
print("- Typ:", akcja.typ)
|
print("- Typ:", akcja.typ)
|
||||||
else:
|
else:
|
||||||
print("Brak akcji przypisanych do tego sprzętu.")
|
print("Brak akcji przypisanych do tego sprzętu.")
|
||||||
def irrigateSlot(self):
|
|
||||||
self.slot.irrigatePlant()
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
CUBE_SIZE = 64
|
CUBE_SIZE = 64
|
||||||
NUM_X = 5
|
NUM_X = 20
|
||||||
NUM_Y = 3
|
NUM_Y = 12
|
||||||
|
|
||||||
#returns true if tractor can move to specified slot
|
#returns true if tractor can move to specified slot
|
||||||
def isValidMove(x, y):
|
def isValidMove(x, y):
|
||||||
|
Loading…
Reference in New Issue
Block a user