2020-04-28 21:08:11 +02:00
|
|
|
import pygame
|
|
|
|
import sys
|
|
|
|
import random
|
2020-06-14 16:29:16 +02:00
|
|
|
import NataliaWisniewskaDrzewoDecyzyjne
|
2020-04-28 21:08:11 +02:00
|
|
|
from Tractor import Tractor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Game(object):
|
|
|
|
def __init__(self):
|
|
|
|
# Config
|
|
|
|
self.max_tps = 2.0
|
|
|
|
self.res = (720, 720)
|
|
|
|
|
|
|
|
self.fields = []
|
|
|
|
self.randomize_field()
|
2020-06-14 16:29:16 +02:00
|
|
|
self.nawadnianie = []
|
2020-04-28 21:08:11 +02:00
|
|
|
# Initialization
|
|
|
|
pygame.init()
|
|
|
|
self.screen = pygame.display.set_mode(self.res)
|
|
|
|
pygame.display.set_caption('Traktorek')
|
|
|
|
self.clock = pygame.time.Clock()
|
|
|
|
self.dt = 0.0
|
2020-06-14 16:29:16 +02:00
|
|
|
my_tree = drzewoDecyzyjne.build_tree(drzewoDecyzyjne.training_data)
|
2020-04-28 21:08:11 +02:00
|
|
|
self.player = Tractor(self)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
# Handle events
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
sys.exit(0)
|
|
|
|
elif event.type == pygame.K_ESCAPE:
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
# Ticking
|
|
|
|
self.dt += self.clock.tick() / 1000.0
|
|
|
|
while self.dt > 1 / self.max_tps:
|
|
|
|
self.tick()
|
|
|
|
self.dt -= 1 / self.max_tps
|
|
|
|
|
|
|
|
# Rendering
|
|
|
|
self.screen.fill((0, 0, 0))
|
|
|
|
self.draw()
|
|
|
|
pygame.display.flip()
|
|
|
|
|
|
|
|
def tick(self):
|
|
|
|
self.player.tick()
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
self.screen.fill((0, 0, 0))
|
|
|
|
self.draw_field()
|
|
|
|
self.draw_net()
|
|
|
|
self.player.draw()
|
|
|
|
pygame.display.update()
|
|
|
|
|
|
|
|
def draw_net(self):
|
|
|
|
color = (255, 255, 255)
|
|
|
|
for i in range(1, 5):
|
|
|
|
krat = int(720 / 5 * i)
|
|
|
|
# linia pozioma
|
|
|
|
pygame.draw.line(self.screen, color, (0, krat), (720, krat), 1)
|
|
|
|
# linia pionowa
|
|
|
|
pygame.draw.line(self.screen, color, (krat, 0), (krat, 720), 1)
|
|
|
|
|
|
|
|
def randomize_field(self):
|
|
|
|
for x in range(25):
|
|
|
|
temp = []
|
|
|
|
# nasiona
|
|
|
|
temp.append(random.choice(["żyto", "jęczmień", "owies", "marchew", "rzodkiew", "pietruszka", "puste"]))
|
|
|
|
# gleba
|
|
|
|
temp.append(random.choice([True, False]))
|
|
|
|
# woda
|
2020-06-14 16:29:16 +02:00
|
|
|
temp.append(random.choice(['s', 'n']))
|
2020-05-20 11:42:28 +02:00
|
|
|
# ile dni temu pole bylo podlewane
|
|
|
|
temp.append(random.randrange(7))
|
2020-06-10 11:11:45 +02:00
|
|
|
# czy ma padac
|
2020-06-14 16:29:16 +02:00
|
|
|
pada = random.choice(['t', 'n'])
|
2020-06-10 11:11:45 +02:00
|
|
|
temp.append(pada)
|
|
|
|
# kiedy padalo
|
2020-06-14 16:29:16 +02:00
|
|
|
kiedyPada = random.randrange(9)
|
2020-06-10 11:11:45 +02:00
|
|
|
temp.append(kiedyPada)
|
|
|
|
|
|
|
|
# nawoz
|
|
|
|
temp.append(random.choice([True, False]))
|
2020-04-28 21:08:11 +02:00
|
|
|
# # growth rate
|
|
|
|
# temp.append(random)
|
2020-06-10 11:11:45 +02:00
|
|
|
# # cost + co ile dni nalezy podlewac dana uprawe
|
2020-04-28 21:08:11 +02:00
|
|
|
if temp[0] == "żyto":
|
|
|
|
temp.append(10)
|
2020-05-20 11:42:28 +02:00
|
|
|
temp.append(4)
|
2020-04-28 21:08:11 +02:00
|
|
|
elif temp[0] == "jęczmień":
|
|
|
|
temp.append(12)
|
2020-05-20 11:42:28 +02:00
|
|
|
temp.append(3)
|
2020-04-28 21:08:11 +02:00
|
|
|
elif temp[0] == "owies":
|
|
|
|
temp.append(8)
|
2020-05-20 11:42:28 +02:00
|
|
|
temp.append(2)
|
2020-04-28 21:08:11 +02:00
|
|
|
elif temp[0] == "marchew":
|
|
|
|
temp.append(14)
|
2020-05-20 11:42:28 +02:00
|
|
|
temp.append(5)
|
2020-04-28 21:08:11 +02:00
|
|
|
elif temp[0] == "rzodkiew":
|
|
|
|
temp.append(7)
|
2020-05-20 11:42:28 +02:00
|
|
|
temp.append(5)
|
2020-04-28 21:08:11 +02:00
|
|
|
elif temp[0] == "pietruszka":
|
|
|
|
temp.append(6)
|
2020-05-20 11:42:28 +02:00
|
|
|
temp.append(1)
|
2020-04-28 21:08:11 +02:00
|
|
|
elif temp[0] == "puste":
|
|
|
|
temp.append(2)
|
2020-05-20 11:42:28 +02:00
|
|
|
temp.append(6)
|
2020-04-28 21:08:11 +02:00
|
|
|
else:
|
|
|
|
temp.append(0)
|
2020-06-14 16:29:16 +02:00
|
|
|
|
2020-04-28 21:08:11 +02:00
|
|
|
self.fields.append(temp)
|
2020-06-10 11:11:45 +02:00
|
|
|
|
2020-06-14 16:29:16 +02:00
|
|
|
self.nawadnianie.append([temp[3], temp[8], temp[4], temp[5], temp[2]])
|
|
|
|
i=0
|
|
|
|
print('\nPODLEWANIE: \n')
|
|
|
|
|
|
|
|
while i<25:
|
|
|
|
wynik = drzewoDecyzyjne.finalAnswer(self.nawadnianie[i], drzewoDecyzyjne.my_tree)
|
|
|
|
#print(self.nawadnianie[i])
|
|
|
|
#print(wynik)
|
|
|
|
if (wynik == 's'):
|
|
|
|
print('należy podlać pole ' + str(i))
|
|
|
|
else:
|
|
|
|
print('nie podlewać pola ' + str(i))
|
|
|
|
i=i+1
|
2020-04-28 21:08:11 +02:00
|
|
|
|
|
|
|
def draw_field(self):
|
|
|
|
for x in range(25):
|
|
|
|
self.screen.fill(self.color(x), (144 * (x % 5), 144 * (x // 5), 144 * (x % 5 + 1), 144 * (x // 5 + 1)))
|
|
|
|
|
|
|
|
def color(self, z):
|
|
|
|
if self.fields[z][0] == 'owies':
|
|
|
|
return (255, 200, 55)
|
|
|
|
elif self.fields[z][0] == 'jęczmień':
|
|
|
|
return (170, 150, 40)
|
|
|
|
elif self.fields[z][0] == 'żyto':
|
|
|
|
return (100, 215, 80)
|
|
|
|
elif self.fields[z][0] == 'marchew':
|
|
|
|
return (224, 60, 14)
|
|
|
|
elif self.fields[z][0] == 'rzodkiew':
|
|
|
|
return (142, 24, 104)
|
|
|
|
elif self.fields[z][0] == 'pietruszka':
|
|
|
|
return (254, 247, 246)
|
|
|
|
else:
|
|
|
|
return (0,0,0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
Game()
|