2021-04-03 00:16:53 +02:00
|
|
|
import definitions
|
2021-06-13 16:28:40 +02:00
|
|
|
import graph
|
2021-06-04 14:01:17 +02:00
|
|
|
import random
|
2021-06-18 12:16:19 +02:00
|
|
|
|
|
|
|
|
2021-03-21 12:40:13 +01:00
|
|
|
class Plant:
|
2021-03-27 21:31:22 +01:00
|
|
|
def __init__(self, name, state):
|
2021-06-18 12:16:19 +02:00
|
|
|
self.name = name # nazwa rośliny np. "wheat"
|
|
|
|
self.state = state # etap rozwoju rośliny
|
|
|
|
|
2021-03-27 21:31:22 +01:00
|
|
|
def get_name(self):
|
|
|
|
return self.name
|
2021-06-18 12:16:19 +02:00
|
|
|
|
2021-03-27 21:31:22 +01:00
|
|
|
def set_name(self, name):
|
|
|
|
self.name = name
|
2021-06-18 12:16:19 +02:00
|
|
|
|
2021-03-23 17:14:46 +01:00
|
|
|
def get_state(self):
|
|
|
|
return self.state
|
2021-06-18 12:16:19 +02:00
|
|
|
|
2021-03-23 17:14:46 +01:00
|
|
|
def set_state(self, state):
|
2021-04-03 00:16:53 +02:00
|
|
|
self.state = state
|
2021-06-18 12:16:19 +02:00
|
|
|
|
2021-04-10 19:16:34 +02:00
|
|
|
@staticmethod
|
2021-06-18 12:16:19 +02:00
|
|
|
def get_closest_mature_plant(istate,
|
|
|
|
map): # pobiera miejsce najbliższej dojrzałej rośliny od miejsca, w którym znajduje się wózek
|
|
|
|
x = None # x'owa pola
|
|
|
|
y = None # y'kowa pola
|
2021-06-13 16:28:40 +02:00
|
|
|
min = None
|
|
|
|
for i in range(definitions.WIDTH_AMOUNT):
|
|
|
|
for j in range(definitions.HEIGHT_AMOUNT):
|
|
|
|
field = map.fields[i][j]
|
|
|
|
if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE:
|
|
|
|
if min is None:
|
|
|
|
x = i
|
|
|
|
y = j
|
|
|
|
min = len((graph.graphsearch([], [], (x, y), istate, graph.succ)))
|
|
|
|
else:
|
|
|
|
if len((graph.graphsearch([], [], (x, y), istate, graph.succ))) < min:
|
|
|
|
x = i
|
|
|
|
y = j
|
|
|
|
min = len((graph.graphsearch([], [], (x, y), istate, graph.succ)))
|
|
|
|
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE:
|
|
|
|
if min is None:
|
|
|
|
x = i
|
|
|
|
y = j
|
|
|
|
min = len((graph.graphsearch([], [], (x, y), istate, graph.succ)))
|
|
|
|
else:
|
|
|
|
if len((graph.graphsearch([], [], (x, y), istate, graph.succ))) < min:
|
|
|
|
x = i
|
|
|
|
y = j
|
|
|
|
min = len((graph.graphsearch([], [], (x, y), istate, graph.succ)))
|
|
|
|
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE:
|
|
|
|
if min is None:
|
|
|
|
x = i
|
|
|
|
y = j
|
|
|
|
min = len((graph.graphsearch([], [], (x, y), istate, graph.succ)))
|
|
|
|
else:
|
|
|
|
if len((graph.graphsearch([], [], (x, y), istate, graph.succ))) < min:
|
|
|
|
x = i
|
|
|
|
y = j
|
|
|
|
min = len((graph.graphsearch([], [], (x, y), istate, graph.succ)))
|
|
|
|
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE:
|
|
|
|
if min is None:
|
|
|
|
x = i
|
|
|
|
y = j
|
|
|
|
min = len((graph.graphsearch([], [], (x, y), istate, graph.succ)))
|
|
|
|
else:
|
|
|
|
if len((graph.graphsearch([], [], (x, y), istate, graph.succ))) < min:
|
|
|
|
x = i
|
|
|
|
y = j
|
|
|
|
min = len((graph.graphsearch([], [], (x, y), istate, graph.succ)))
|
|
|
|
return x, y
|
2021-06-18 12:16:19 +02:00
|
|
|
|
2021-06-13 16:28:40 +02:00
|
|
|
@staticmethod
|
2021-06-18 12:16:19 +02:00
|
|
|
def grow_flower_dandelion(map): # metoda statyczna, losująca czy na danym polu ma urosnąć kwiat dandelion
|
2021-06-04 14:01:17 +02:00
|
|
|
for i in range(definitions.WIDTH_AMOUNT):
|
|
|
|
for j in range(definitions.HEIGHT_AMOUNT):
|
|
|
|
field = map.get_fields()[i][j]
|
|
|
|
if field.get_plant().get_name() == "none":
|
|
|
|
random1 = random.uniform(0, 100)
|
|
|
|
if random1 <= definitions.FLOWER_DANDELION_GROW_PROBABILITY:
|
|
|
|
field.get_plant().set_name("flower_dandelion")
|
|
|
|
field.get_plant().set_state(definitions.FLOWER_DANDELION_MAXIMUM_STATE)
|
2021-06-18 12:16:19 +02:00
|
|
|
|
2021-06-04 14:01:17 +02:00
|
|
|
@staticmethod
|
2021-06-18 12:16:19 +02:00
|
|
|
def grow_plants(
|
|
|
|
map): # metoda statyczna, która zwiększa pole state (etap rozwoju rośliny) dla danej rośliny na danym polu o 1
|
2021-04-03 00:16:53 +02:00
|
|
|
for i in range(definitions.WIDTH_AMOUNT):
|
|
|
|
for j in range(definitions.HEIGHT_AMOUNT):
|
2021-05-31 18:16:14 +02:00
|
|
|
field = map.get_fields()[i][j]
|
2021-04-03 00:16:53 +02:00
|
|
|
if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.BEETROOTS_MAXIMUM_STATE:
|
|
|
|
field.get_plant().set_state(field.get_plant().get_state() + 1)
|
|
|
|
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.CARROTS_MAXIMUM_STATE:
|
|
|
|
field.get_plant().set_state(field.get_plant().get_state() + 1)
|
|
|
|
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.POTATOES_MAXIMUM_STATE:
|
|
|
|
field.get_plant().set_state(field.get_plant().get_state() + 1)
|
|
|
|
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.WHEAT_MAXIMUM_STATE:
|
2021-06-13 16:28:40 +02:00
|
|
|
field.get_plant().set_state(field.get_plant().get_state() + 1)
|
2021-06-18 12:16:19 +02:00
|
|
|
|
2021-06-13 16:28:40 +02:00
|
|
|
@staticmethod
|
2021-06-18 12:16:19 +02:00
|
|
|
def if_any_mature_plant(
|
|
|
|
map): # sprawdza czy na polu występuje choć jedna dojrzała roślina, jeśli tak zwraca prawdę, w przeciwnym razie zwraca fałsz
|
2021-06-13 16:28:40 +02:00
|
|
|
for i in range(definitions.WIDTH_AMOUNT):
|
|
|
|
for j in range(definitions.HEIGHT_AMOUNT):
|
|
|
|
field = map.get_fields()[i][j]
|
|
|
|
if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE:
|
|
|
|
return True
|
|
|
|
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE:
|
|
|
|
return True
|
|
|
|
elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE:
|
|
|
|
return True
|
|
|
|
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE:
|
|
|
|
return True
|
2021-06-18 12:16:19 +02:00
|
|
|
return False
|