-Added support to precalculated BFS2 -Added way to set HydrateValue by HydrateIndex -Minor changes in Tractor.py -Added flags to make handling different BFS implements easier
This commit is contained in:
parent
d38c4d9593
commit
e0397b95a7
8
BFS.py
8
BFS.py
@ -1,4 +1,6 @@
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
|
import pygame
|
||||||
import Node
|
import Node
|
||||||
from displayControler import NUM_X, NUM_Y
|
from displayControler import NUM_X, NUM_Y
|
||||||
|
|
||||||
@ -84,6 +86,9 @@ def BFS1(istate):
|
|||||||
x.parent = elem
|
x.parent = elem
|
||||||
x.action = resp[0]
|
x.action = resp[0]
|
||||||
fringe.append(x)
|
fringe.append(x)
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
quit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -159,6 +164,9 @@ def BFS2(istate):
|
|||||||
x.parent = elem
|
x.parent = elem
|
||||||
x.action = resp[0]
|
x.action = resp[0]
|
||||||
fringe.append(x)
|
fringe.append(x)
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
quit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
8
Slot.py
8
Slot.py
@ -60,3 +60,11 @@ class Slot:
|
|||||||
def irrigatePlant(self):
|
def irrigatePlant(self):
|
||||||
self.plant.stan.nawodnienie = 100
|
self.plant.stan.nawodnienie = 100
|
||||||
|
|
||||||
|
def setHydrate(self,index):
|
||||||
|
if(index==0):
|
||||||
|
self.plant.stan.nawodnienie=random.randint(0,60)
|
||||||
|
elif(index==1):
|
||||||
|
self.plant.stan.nawodnienie=random.randint(61,100)
|
||||||
|
elif(index==-1):
|
||||||
|
pass
|
||||||
|
|
25
Tractor.py
25
Tractor.py
@ -6,6 +6,11 @@ import Slot
|
|||||||
import Osprzet
|
import Osprzet
|
||||||
import Node
|
import Node
|
||||||
|
|
||||||
|
tab = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
|
||||||
|
1, 1, 1, 1, 1, 0, 1, 0, 1, 1,
|
||||||
|
0, 1, 0, 1, 0, 1, 1, 1, 1, 1,
|
||||||
|
1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
|
||||||
|
|
||||||
|
|
||||||
class Tractor:
|
class Tractor:
|
||||||
@ -13,7 +18,7 @@ class Tractor:
|
|||||||
DIRECTION_SOUTH = 'S'
|
DIRECTION_SOUTH = 'S'
|
||||||
DIRECTION_WEST = 'W'
|
DIRECTION_WEST = 'W'
|
||||||
DIRECTION_EAST = 'E'
|
DIRECTION_EAST = 'E'
|
||||||
def __init__(self,slot,screen, osprzet,clock):
|
def __init__(self,slot,screen, osprzet,clock,bfs2_flag):
|
||||||
self.tractor_images = {
|
self.tractor_images = {
|
||||||
Tractor.DIRECTION_NORTH: pygame.transform.scale(pygame.image.load('images/traktorN.png'),
|
Tractor.DIRECTION_NORTH: pygame.transform.scale(pygame.image.load('images/traktorN.png'),
|
||||||
(dCon.CUBE_SIZE, dCon.CUBE_SIZE)),
|
(dCon.CUBE_SIZE, dCon.CUBE_SIZE)),
|
||||||
@ -31,6 +36,7 @@ class Tractor:
|
|||||||
self.osprzet = osprzet
|
self.osprzet = osprzet
|
||||||
self.clock=clock
|
self.clock=clock
|
||||||
self.slot_hydrate_dict={}
|
self.slot_hydrate_dict={}
|
||||||
|
self.bfs2_flag=bfs2_flag
|
||||||
|
|
||||||
|
|
||||||
def draw_tractor(self):
|
def draw_tractor(self):
|
||||||
@ -102,6 +108,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):
|
||||||
|
if (self.bfs2_flag==True):
|
||||||
|
index=0
|
||||||
|
|
||||||
|
for y in range (0,dCon.NUM_Y):
|
||||||
|
if(y%2==0):
|
||||||
|
for x in range(0,dCon.NUM_X):
|
||||||
|
if(pole.is_valid_move((x,y))):
|
||||||
|
pole.get_slot_from_cord((x,y)).setHydrate(tab[index])
|
||||||
|
self.snake_move(pole,x,y)
|
||||||
|
index=index+1
|
||||||
|
else:
|
||||||
|
for x in range(dCon.NUM_X,-1,-1):
|
||||||
|
if(pole.is_valid_move((x,y))):
|
||||||
|
pole.get_slot_from_cord((x,y)).setHydrate(tab[index])
|
||||||
|
self.snake_move(pole,x,y)
|
||||||
|
index=index+1
|
||||||
|
else:
|
||||||
for y in range (0,dCon.NUM_Y):
|
for y in range (0,dCon.NUM_Y):
|
||||||
if(y%2==0):
|
if(y%2==0):
|
||||||
for x in range(0,dCon.NUM_X):
|
for x in range(0,dCon.NUM_X):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
CUBE_SIZE = 64
|
CUBE_SIZE = 64
|
||||||
NUM_X = 6
|
NUM_X = 10
|
||||||
NUM_Y = 3
|
NUM_Y = 5
|
||||||
|
|
||||||
#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