Zaktualizuj 'Traktorek/ran.py'
This commit is contained in:
parent
359928e011
commit
8818539c6c
@ -1,6 +1,7 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
|
import NataliaWisniewskaDrzewoDecyzyjne
|
||||||
from Tractor import Tractor
|
from Tractor import Tractor
|
||||||
|
|
||||||
|
|
||||||
@ -13,14 +14,14 @@ class Game(object):
|
|||||||
|
|
||||||
self.fields = []
|
self.fields = []
|
||||||
self.randomize_field()
|
self.randomize_field()
|
||||||
|
self.nawadnianie = []
|
||||||
# Initialization
|
# Initialization
|
||||||
pygame.init()
|
pygame.init()
|
||||||
self.screen = pygame.display.set_mode(self.res)
|
self.screen = pygame.display.set_mode(self.res)
|
||||||
pygame.display.set_caption('Traktorek')
|
pygame.display.set_caption('Traktorek')
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
self.dt = 0.0
|
self.dt = 0.0
|
||||||
|
my_tree = drzewoDecyzyjne.build_tree(drzewoDecyzyjne.training_data)
|
||||||
self.player = Tractor(self)
|
self.player = Tractor(self)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -62,13 +63,6 @@ class Game(object):
|
|||||||
pygame.draw.line(self.screen, color, (krat, 0), (krat, 720), 1)
|
pygame.draw.line(self.screen, color, (krat, 0), (krat, 720), 1)
|
||||||
|
|
||||||
def randomize_field(self):
|
def randomize_field(self):
|
||||||
ileDni = []
|
|
||||||
uprawaDni = []
|
|
||||||
woda = []
|
|
||||||
czyPada = []
|
|
||||||
kiedyPadalo =[]
|
|
||||||
pada = random.choice([True, False])
|
|
||||||
kiedyPada = random.randrange(9)
|
|
||||||
for x in range(25):
|
for x in range(25):
|
||||||
temp = []
|
temp = []
|
||||||
# nasiona
|
# nasiona
|
||||||
@ -76,12 +70,14 @@ class Game(object):
|
|||||||
# gleba
|
# gleba
|
||||||
temp.append(random.choice([True, False]))
|
temp.append(random.choice([True, False]))
|
||||||
# woda
|
# woda
|
||||||
temp.append(random.choice([True, False]))
|
temp.append(random.choice(['s', 'n']))
|
||||||
# ile dni temu pole bylo podlewane
|
# ile dni temu pole bylo podlewane
|
||||||
temp.append(random.randrange(7))
|
temp.append(random.randrange(7))
|
||||||
# czy ma padac
|
# czy ma padac
|
||||||
|
pada = random.choice(['t', 'n'])
|
||||||
temp.append(pada)
|
temp.append(pada)
|
||||||
# kiedy padalo
|
# kiedy padalo
|
||||||
|
kiedyPada = random.randrange(9)
|
||||||
temp.append(kiedyPada)
|
temp.append(kiedyPada)
|
||||||
|
|
||||||
# nawoz
|
# nawoz
|
||||||
@ -112,14 +108,22 @@ class Game(object):
|
|||||||
temp.append(6)
|
temp.append(6)
|
||||||
else:
|
else:
|
||||||
temp.append(0)
|
temp.append(0)
|
||||||
|
|
||||||
self.fields.append(temp)
|
self.fields.append(temp)
|
||||||
|
|
||||||
woda.append(temp[2])
|
self.nawadnianie.append([temp[3], temp[8], temp[4], temp[5], temp[2]])
|
||||||
ileDni.append(temp[3])
|
i=0
|
||||||
uprawaDni.append(temp[8])
|
print('\nPODLEWANIE: \n')
|
||||||
czyPada.append(temp[4])
|
|
||||||
kiedyPadalo.append(temp[5])
|
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
|
||||||
|
|
||||||
def draw_field(self):
|
def draw_field(self):
|
||||||
for x in range(25):
|
for x in range(25):
|
||||||
|
Loading…
Reference in New Issue
Block a user