Compare commits
No commits in common. "master" and "add_classes" have entirely different histories.
master
...
add_classe
@ -1,3 +0,0 @@
|
||||
{
|
||||
"CurrentProjectSetting": null
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"ExpandedNodes": [
|
||||
""
|
||||
],
|
||||
"SelectedNode": "\\C:\\Users\\zmysz\\Desktop\\nowy-inteligentny-traktor",
|
||||
"PreviewInSolutionExplorer": false
|
||||
}
|
BIN
.vs/slnx.sqlite
@ -1,82 +0,0 @@
|
||||
from PIL import Image
|
||||
import random
|
||||
|
||||
plants = [[], [], []]
|
||||
plants[0].append(Image.open("w1.png"))
|
||||
plants[0].append(Image.open("w2.png"))
|
||||
plants[0].append(Image.open("w3.png"))
|
||||
plants[1].append(Image.open("c1.png"))
|
||||
plants[1].append(Image.open("c2.png"))
|
||||
plants[1].append(Image.open("c3.png"))
|
||||
plants[2].append(Image.open("ca1.png"))
|
||||
plants[2].append(Image.open("ca2.png"))
|
||||
plants[2].append(Image.open("ca3.png"))
|
||||
b = [Image.open("b1.png").convert('RGBA'), Image.open("b2.png").convert('RGBA'), Image.open("b3.png").convert('RGBA')]
|
||||
|
||||
|
||||
def generate(water, fertilizer, plantf):
|
||||
if water == 1:
|
||||
new_im = Image.new('RGB', (100, 100),
|
||||
(160 + random.randint(-10, 10), 80 + random.randint(-10, 10), 40 + random.randint(-10, 10)))
|
||||
tmp = plants[plantf][random.randint(0, 2)].resize(
|
||||
(25 + random.randint(-10, 25), 25 + random.randint(-10, 25))).rotate(random.randint(0, 359))
|
||||
new_im.paste(tmp, (random.randint(0, 50), random.randint(0, 50)), tmp)
|
||||
if fertilizer:
|
||||
tmp = b[random.randint(0, 2)].resize(
|
||||
(20 + random.randint(0, 25), 20 + random.randint(0, 25))).rotate(random.randint(0, 359))
|
||||
new_im.paste(tmp, (random.randint(25, 75), random.randint(25, 75)), tmp)
|
||||
else:
|
||||
if fertilizer:
|
||||
new_im = Image.new('RGB', (100, 100),
|
||||
(
|
||||
50 + random.randint(-10, 10), 25 + random.randint(-10, 10),
|
||||
0 + random.randint(-10, 10)))
|
||||
tmp = plants[plantf][random.randint(0, 2)].resize(
|
||||
(25 + random.randint(-10, 25), 25 + random.randint(-10, 25))).rotate(random.randint(0, 359))
|
||||
new_im.paste(tmp, (random.randint(0, 50), random.randint(0, 50)), tmp)
|
||||
tmp = b[random.randint(0, 2)].resize(
|
||||
(20 + random.randint(0, 25), 20 + random.randint(0, 25))).rotate(random.randint(0, 359))
|
||||
new_im.paste(tmp, (random.randint(25, 75), random.randint(25, 75)), tmp)
|
||||
|
||||
else:
|
||||
if random.randint(0, 1) == 1:
|
||||
new_im = Image.new('RGB', (100, 100),
|
||||
(50 + random.randint(-10, 10), 25 + random.randint(-10, 10),
|
||||
0 + random.randint(-10, 10)))
|
||||
else:
|
||||
new_im = Image.new('RGB', (100, 100),
|
||||
(160 + random.randint(-10, 10), 80 + random.randint(-10, 10),
|
||||
40 + random.randint(-10, 10)))
|
||||
if random.randint(0, 1) == 1: # big
|
||||
tmp = plants[plantf][random.randint(0, 2)].resize(
|
||||
(75 + random.randint(-10, 25), 75 + random.randint(-10, 25))).rotate(random.randint(0, 359))
|
||||
new_im.paste(tmp, (random.randint(0, 15), random.randint(0, 15)), tmp)
|
||||
else:
|
||||
tmp = plants[plantf][random.randint(0, 2)].resize(
|
||||
(random.randint(10, 80), random.randint(10, 80))).rotate(random.randint(0, 359))
|
||||
datas = tmp.getdata()
|
||||
|
||||
new_image_data = []
|
||||
for item in datas:
|
||||
# change all white (also shades of whites) pixels to yellow
|
||||
if item[0] in list(range(190, 256)):
|
||||
new_image_data.append(
|
||||
(random.randint(0, 10), 255 + random.randint(-150, 0), random.randint(0, 10)))
|
||||
else:
|
||||
new_image_data.append(item)
|
||||
|
||||
# update image data
|
||||
tmp.putdata(new_image_data)
|
||||
new_im.paste(tmp, (random.randint(0, 30), random.randint(0, 30)), tmp)
|
||||
|
||||
return new_im
|
||||
|
||||
|
||||
for x in range(0, 1000):
|
||||
generate(0, 0, random.randint(0, 2)).save('datasets/00/' + str(x) + '.png')
|
||||
for x in range(0, 1000):
|
||||
generate(1, 0, random.randint(0, 2)).save('datasets/10/' + str(x) + '.png')
|
||||
for x in range(0, 1000):
|
||||
generate(0, 1, random.randint(0, 2)).save('datasets/01/' + str(x) + '.png')
|
||||
for x in range(0, 1000):
|
||||
generate(1, 1, random.randint(0, 2)).save('datasets/11/' + str(x) + '.png')
|
BIN
NN/ca1.png
Before Width: | Height: | Size: 448 KiB |
BIN
NN/ca2.png
Before Width: | Height: | Size: 397 KiB |
BIN
NN/ca3.png
Before Width: | Height: | Size: 821 KiB |
@ -1,48 +0,0 @@
|
||||
import pathlib
|
||||
import random
|
||||
|
||||
import torch
|
||||
from torch import nn
|
||||
from torch.utils.data import DataLoader
|
||||
from torchvision import datasets, transforms
|
||||
from torchvision.transforms import Lambda
|
||||
|
||||
|
||||
device = torch.device('cpu')
|
||||
|
||||
|
||||
def train(model, dataset, n_iter=100, batch_size=2560000):
|
||||
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
|
||||
criterion = nn.NLLLoss()
|
||||
dl = DataLoader(dataset, batch_size=batch_size)
|
||||
model.train()
|
||||
for epoch in range(n_iter):
|
||||
for images, targets in dl:
|
||||
optimizer.zero_grad()
|
||||
out = model(images.to(device))
|
||||
loss = criterion(out, targets.to(device))
|
||||
loss.backward()
|
||||
optimizer.step()
|
||||
if epoch % 10 == 0:
|
||||
print('epoch: %3d loss: %.4f' % (epoch, loss))
|
||||
|
||||
|
||||
image_path_list = list(pathlib.Path('./').glob("*/*/*.png"))
|
||||
|
||||
random_image_path = random.choice(image_path_list)
|
||||
data_transform = transforms.Compose([
|
||||
transforms.Resize(size=(100, 100)),
|
||||
transforms.RandomHorizontalFlip(p=0.5),
|
||||
transforms.ToTensor(),
|
||||
Lambda(lambda x: x.flatten())
|
||||
])
|
||||
|
||||
train_data = datasets.ImageFolder(root="./datasets",
|
||||
transform=data_transform,
|
||||
target_transform=None)
|
||||
|
||||
model1 = nn.Sequential(nn.Linear(30000, 10000), nn.ReLU(), nn.Linear(10000, 10000), nn.ReLU(), nn.Linear(10000, 0000), nn.Linear(10000, 4), nn.LogSoftmax(dim=-1)).to(device)
|
||||
model1.load_state_dict(torch.load("./trained"))
|
||||
train(model1, train_data)
|
||||
|
||||
torch.save(model1.state_dict(), "./trained")
|
195
astar.py
@ -1,195 +0,0 @@
|
||||
from operator import itemgetter
|
||||
import cart
|
||||
import copy
|
||||
|
||||
|
||||
class Istate:
|
||||
def __init__(self, direction, x, y):
|
||||
self.direction = direction
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def get_direction(self):
|
||||
return self.direction
|
||||
|
||||
def set_direction(self, direction):
|
||||
self.direction = direction
|
||||
|
||||
def get_x(self):
|
||||
return self.x
|
||||
|
||||
def set_x(self, x):
|
||||
self.x = x
|
||||
|
||||
def get_y(self):
|
||||
return self.y
|
||||
|
||||
def set_y(self, y):
|
||||
self.y = y
|
||||
|
||||
|
||||
class Node:
|
||||
def __init__(self, action, direction, parent, x, y):
|
||||
self.action = action
|
||||
self.direction = direction
|
||||
self.parent = parent
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def get_action(self):
|
||||
return self.action
|
||||
|
||||
def set_action(self, action):
|
||||
self.action = action
|
||||
|
||||
def get_direction(self):
|
||||
return self.direction
|
||||
|
||||
def set_direction(self, direction):
|
||||
self.direction = direction
|
||||
|
||||
def get_parent(self):
|
||||
return self.parent
|
||||
|
||||
def set_parent(self, parent):
|
||||
self.parent = parent
|
||||
|
||||
def get_x(self):
|
||||
return self.x
|
||||
|
||||
def set_x(self, x):
|
||||
self.x = x
|
||||
|
||||
def get_y(self):
|
||||
return self.y
|
||||
|
||||
def set_y(self, y):
|
||||
self.y = y
|
||||
|
||||
|
||||
def fieldCost(T, node):
|
||||
c = 0
|
||||
if T[node.x-1][node.y-1].plantType == 1:
|
||||
c = 2
|
||||
elif T[node.x-1][node.y-1].plantType == 2:
|
||||
c = 5
|
||||
elif T[node.x-1][node.y-1].plantType == 3:
|
||||
c = 13
|
||||
elif T[node.x-1][node.y-1].plantType == 4:
|
||||
c = 100000
|
||||
else:
|
||||
c = 0
|
||||
|
||||
if T[node.x-1][node.y-1].isWet == 1:
|
||||
c = c + 4
|
||||
else:
|
||||
c = c+1
|
||||
|
||||
return c
|
||||
|
||||
|
||||
def cost(T, node):
|
||||
cost = 0
|
||||
|
||||
while node.get_parent() is not None:
|
||||
cost = cost + fieldCost(T, node)
|
||||
node = node.get_parent()
|
||||
|
||||
return cost
|
||||
|
||||
|
||||
def f(goaltest, map, node):
|
||||
return cost(map, node) + heuristic(goaltest, node)
|
||||
|
||||
|
||||
def goal_test(elem, goaltest):
|
||||
if elem.get_x() == goaltest[0] and elem.get_y() == goaltest[1]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def graphsearch(explored, f, fringe, goaltest, istate, map, succ): # przeszukiwanie grafu wszerz
|
||||
node = Node(None, istate.get_direction(), None, istate.get_x(), istate.get_y())
|
||||
fringe.append((node, 0)) # wierzchołki do odwiedzenia z priorytetem
|
||||
while True:
|
||||
if not fringe:
|
||||
return False
|
||||
elem = fringe.pop(0) # zdejmujemy wierzchołek z kolejki fringe i rozpatrujemy go
|
||||
temp = copy.copy(elem[0])
|
||||
if goal_test(elem[0], goaltest) is True: # jeżeli osiągniemy cel w trakcie przeszukiwania grafu wszerz (wjedziemy na pole docelowe) : zwracamy listę ruchów, po których wykonaniu dotrzemy na miejsce
|
||||
return print_moves(elem[0])
|
||||
explored.append(elem) # dodajemy wierzchołek do listy wierzchołków odwiedzonych
|
||||
for (action, state) in succ(temp): # iterujemy po wszystkich możliwych akcjach i stanach otrzymanych dla danego wierzchołka grafu
|
||||
fringe_tuple = []
|
||||
fringe_tuple_prio = []
|
||||
explored_tuple = []
|
||||
for (x, y) in fringe:
|
||||
fringe_tuple.append((x.get_direction(), x.get_x(), x.get_y()))
|
||||
fringe_tuple_prio.append(((x.get_direction(), x.get_x(), x.get_y()), y))
|
||||
for (x, y) in explored:
|
||||
explored_tuple.append((x.get_direction(), x.get_x(), x.get_y()))
|
||||
x = Node(action, state[0], elem[0], state[1], state[2]) # stworzenie nowego wierzchołka, którego rodzicem jest elem
|
||||
p = f(goaltest, map, x) # liczy priorytet
|
||||
# print('Koszt =', p)
|
||||
if state not in fringe_tuple and state not in explored_tuple: # jeżeli stan nie znajduje się na fringe oraz nie znajduje się w liście wierzchołków odwiedzonych
|
||||
fringe.append((x, p)) # dodanie wierzchołka na fringe
|
||||
fringe = sorted(fringe, key=itemgetter(1)) # sortowanie fringe'a według priorytetu
|
||||
elif state in fringe_tuple:
|
||||
i = 0
|
||||
for (state_prio, r) in fringe_tuple_prio:
|
||||
if str(state_prio) == str(state):
|
||||
if r > p:
|
||||
fringe.insert(i, (x, p)) # zamiana state, który należy do fringe z priorytetem r na state z priorytetem p (niższym)
|
||||
fringe.pop(i + 1)
|
||||
fringe = sorted(fringe, key=itemgetter(1)) # sortowanie fringe'a według priorytetu
|
||||
break
|
||||
i = i + 1
|
||||
|
||||
|
||||
def heuristic(goaltest, node):
|
||||
return abs(node.get_x() - goaltest[0]) + abs(node.get_y() - goaltest[1])
|
||||
|
||||
|
||||
def print_moves(elem):
|
||||
moves_list = []
|
||||
while elem.get_parent() is not None:
|
||||
moves_list.append(elem.get_action())
|
||||
elem = elem.get_parent()
|
||||
moves_list.reverse()
|
||||
return moves_list
|
||||
|
||||
|
||||
def succ(elem):
|
||||
actions_list = []
|
||||
temp = copy.copy(elem.get_direction())
|
||||
|
||||
if temp == 1:
|
||||
temp = 4
|
||||
else:
|
||||
temp = temp - 1
|
||||
|
||||
actions_list.append(("rotate_right", (temp, elem.get_x(), elem.get_y())))
|
||||
temp = copy.copy(elem.get_direction())
|
||||
|
||||
if temp == 4:
|
||||
temp = 1
|
||||
else:
|
||||
temp = temp + 1
|
||||
|
||||
actions_list.append(("rotate_left", (temp, elem.get_x(), elem.get_y())))
|
||||
temp_move_south = elem.get_y() - 1
|
||||
temp_move_west = elem.get_x() - 1
|
||||
temp_move_east = elem.get_x() + 1
|
||||
temp_move_north = elem.get_y() + 1
|
||||
|
||||
if cart.Cart.is_move_allowed_succ(elem) == "x + 1":
|
||||
actions_list.append(("move", (elem.get_direction(), temp_move_east, elem.get_y())))
|
||||
elif cart.Cart.is_move_allowed_succ(elem) == "y + 1":
|
||||
actions_list.append(("move", (elem.get_direction(), elem.get_x(), temp_move_north)))
|
||||
elif cart.Cart.is_move_allowed_succ(elem) == "y - 1":
|
||||
actions_list.append(("move", (elem.get_direction(), elem.get_x(), temp_move_south)))
|
||||
elif cart.Cart.is_move_allowed_succ(elem) == "x - 1":
|
||||
actions_list.append(("move", (elem.get_direction(), temp_move_west, elem.get_y())))
|
||||
|
||||
return actions_list
|
146
bfs.py
@ -1,146 +0,0 @@
|
||||
import cart
|
||||
import copy
|
||||
|
||||
|
||||
class Istate:
|
||||
def __init__(self, direction, x, y):
|
||||
self.direction = direction
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def get_direction(self):
|
||||
return self.direction
|
||||
|
||||
def set_direction(self, direction):
|
||||
self.direction = direction
|
||||
|
||||
def get_x(self):
|
||||
return self.x
|
||||
|
||||
def set_x(self, x):
|
||||
self.x = x
|
||||
|
||||
def get_y(self):
|
||||
return self.y
|
||||
|
||||
def set_y(self, y):
|
||||
self.y = y
|
||||
|
||||
|
||||
class Node:
|
||||
def __init__(self, action, direction, parent, x, y):
|
||||
self.action = action
|
||||
self.direction = direction
|
||||
self.parent = parent
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def get_action(self):
|
||||
return self.action
|
||||
|
||||
def set_action(self, action):
|
||||
self.action = action
|
||||
|
||||
def get_direction(self):
|
||||
return self.direction
|
||||
|
||||
def set_direction(self, direction):
|
||||
self.direction = direction
|
||||
|
||||
def get_parent(self):
|
||||
return self.parent
|
||||
|
||||
def set_parent(self, parent):
|
||||
self.parent = parent
|
||||
|
||||
def get_x(self):
|
||||
return self.x
|
||||
|
||||
def set_x(self, x):
|
||||
self.x = x
|
||||
|
||||
def get_y(self):
|
||||
return self.y
|
||||
|
||||
def set_y(self, y):
|
||||
self.y = y
|
||||
|
||||
|
||||
def goal_test(goaltest, elem):
|
||||
if elem.get_x() == goaltest[0] and elem.get_y() == goaltest[1]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def graphsearch(goaltest, istate): # przeszukiwanie grafu wszerz
|
||||
node = Node(None, istate.get_direction(), None, istate.get_x(), istate.get_y())
|
||||
|
||||
fringe = []
|
||||
explored = []
|
||||
fringe.append(node) # wierzchołki do odwiedzenia
|
||||
while True:
|
||||
if not fringe:
|
||||
return False
|
||||
elem = fringe.pop(0) # zdejmujemy wierzchołek z kolejki fringe i rozpatrujemy go
|
||||
temp = copy.copy(elem)
|
||||
if goal_test(goaltest,
|
||||
elem) is True: # jeżeli osiągniemy cel w trakcie przeszukiwania grafu wsszerz, zwracamy listę ruchów, po których wykonaniu dotrzemy na miejsce
|
||||
return print_moves(elem)
|
||||
explored.append(elem) # dodajemy wierzchołek do listy wierzchołków odwiedzonych
|
||||
|
||||
for action, state in succ(temp): # iterujemy po wszystkich możliwych akcjach i stanach otrzymanych dla danego wierzchołka grafu
|
||||
|
||||
fringe_tuple = []
|
||||
explored_tuple = []
|
||||
for x in fringe:
|
||||
fringe_tuple.append((x.get_direction(), x.get_x(), x.get_y()))
|
||||
for x in explored:
|
||||
explored_tuple.append((x.get_direction(), x.get_x(), x.get_y()))
|
||||
if state not in fringe_tuple and state not in explored_tuple: # jeżeli stan nie znajduje się na fringe oraz nie znajduje się w liście wierzchołków odwiedzonych
|
||||
x = Node(action, state[0], elem, state[1], state[2]) # stworzenie nowego wierzchołka, którego rodzicem jest elem
|
||||
fringe.append(x) # dodanie wierzchołka na fringe
|
||||
|
||||
|
||||
def print_moves(elem):
|
||||
moves_list = []
|
||||
while elem.get_parent() is not None:
|
||||
moves_list.append(elem.get_action())
|
||||
elem = elem.get_parent()
|
||||
moves_list.reverse()
|
||||
return moves_list
|
||||
|
||||
|
||||
def succ(elem):
|
||||
actions_list = []
|
||||
temp = copy.copy(elem.get_direction())
|
||||
|
||||
if temp == 1:
|
||||
temp = 4
|
||||
else:
|
||||
temp = temp - 1
|
||||
|
||||
actions_list.append(("rotate_right", (temp, elem.get_x(), elem.get_y())))
|
||||
temp = copy.copy(elem.get_direction())
|
||||
|
||||
if temp == 4:
|
||||
temp = 1
|
||||
else:
|
||||
temp = temp + 1
|
||||
|
||||
actions_list.append(("rotate_left", (temp, elem.get_x(), elem.get_y())))
|
||||
temp_move_south = elem.get_y() - 1
|
||||
temp_move_west = elem.get_x() - 1
|
||||
temp_move_east = elem.get_x() + 1
|
||||
temp_move_north = elem.get_y() + 1
|
||||
|
||||
if cart.Cart.is_move_allowed_succ(elem) == "x + 1":
|
||||
actions_list.append(("move", (elem.get_direction(), temp_move_east, elem.get_y())))
|
||||
elif cart.Cart.is_move_allowed_succ(elem) == "y + 1":
|
||||
actions_list.append(("move", (elem.get_direction(), elem.get_x(), temp_move_north)))
|
||||
elif cart.Cart.is_move_allowed_succ(elem) == "y - 1":
|
||||
actions_list.append(("move", (elem.get_direction(), elem.get_x(), temp_move_south)))
|
||||
elif cart.Cart.is_move_allowed_succ(elem) == "x - 1":
|
||||
actions_list.append(("move", (elem.get_direction(), temp_move_west, elem.get_y())))
|
||||
|
||||
return actions_list
|
73
board.py
@ -1,73 +0,0 @@
|
||||
import pygame
|
||||
from screen import SCREEN
|
||||
|
||||
# global SCREEN
|
||||
global BLACK
|
||||
global gridObjects
|
||||
global imgTree
|
||||
global imgTree
|
||||
imgTree = pygame.image.load('img/tree.png')
|
||||
gridObjects = {} # Store grid-box objects from Grid Class
|
||||
|
||||
|
||||
class Grid(object):
|
||||
# ta klasa rysuje kratę na ekranie
|
||||
def __init__(self, x, y, sx, sy):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.sx = sx
|
||||
self.sy = sy
|
||||
self.width = 1
|
||||
|
||||
def draw(self):
|
||||
# global SCREEN
|
||||
global BLACK
|
||||
# SCREEN = pygame.display.set_mode([600,650])
|
||||
BLACK = (0, 0, 0)
|
||||
pygame.draw.rect(SCREEN, BLACK, (self.x, self.y, self.sx, self.sy), self.width)
|
||||
|
||||
|
||||
class Box(object):
|
||||
# global SCREEN
|
||||
|
||||
def __init__(self, x, y, sx, sy, color):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.sx = sx
|
||||
self.sy = sy
|
||||
self.color = color
|
||||
|
||||
def draw(self):
|
||||
# global SCREEN
|
||||
# SCREEN = pygame.display.set_mode([600,650])
|
||||
# global BLACK
|
||||
pygame.draw.rect(SCREEN, self.color, pygame.Rect(self.x, self.y, self.sx, self.sy))
|
||||
|
||||
|
||||
class Obstacle(object):
|
||||
def __init__(self, mouseObj):
|
||||
self.mseX = mouseObj[0]
|
||||
self.mseY = mouseObj[1]
|
||||
|
||||
for grid in gridObjects:
|
||||
g = getGridBoxes(grid)
|
||||
self.x = g.x
|
||||
self.y = g.y
|
||||
self.sx = g.sx
|
||||
self.sy = g.sy
|
||||
if self.x < self.mseX < self.x + self.sx:
|
||||
if self.y < self.mseY < self.y + self.sy:
|
||||
self.posX = self.x
|
||||
self.posY = self.y
|
||||
self.gridBox = grid
|
||||
|
||||
def draw(self):
|
||||
# pygame.draw.rect(SCREEN, GREY, pygame.Rect(self.posX, self.posY, self.sx, self.sy))
|
||||
global imgTree
|
||||
SCREEN.blit(imgTree, (self.posX, self.posY))
|
||||
# pygame.display.update()
|
||||
|
||||
|
||||
def getGridBoxes(grid_box):
|
||||
global gridObjects
|
||||
return gridObjects[grid_box]
|
74
cart.py
@ -1,74 +0,0 @@
|
||||
import definitions
|
||||
|
||||
|
||||
class Cart:
|
||||
def __init__(self, direction, x, y):
|
||||
self.direction = direction # w którą stronę patrzy, zgodnie ze wskazówkami zegara (1 -: godzina 12, 2 : godzina 3, 3 : godzina 6, 4 : godzina 9)
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def get_direction(self):
|
||||
return self.direction
|
||||
|
||||
def set_direction(self, direction):
|
||||
self.direction = direction
|
||||
|
||||
def get_x(self):
|
||||
return self.x
|
||||
|
||||
def set_x(self, x):
|
||||
self.x = x
|
||||
|
||||
def get_y(self):
|
||||
return self.y
|
||||
|
||||
def set_y(self, y):
|
||||
self.y = y
|
||||
|
||||
def is_move_allowed(self, cart_rect): # sprawdza czy dany ruch, który chce wykonać wózek jest możliwy, zwraca prawdę lub fałsz
|
||||
if self.direction == definitions.CART_DIRECTION_EAST and cart_rect.x + definitions.BLOCK_SIZE < definitions.WIDTH_MAP:
|
||||
return True
|
||||
elif self.direction == definitions.CART_DIRECTION_SOUTH and cart_rect.y - definitions.BLOCK_SIZE > 0:
|
||||
return True
|
||||
elif self.direction == definitions.CART_DIRECTION_NORTH and cart_rect.y + definitions.BLOCK_SIZE < definitions.HEIGHT_MAP:
|
||||
return True
|
||||
elif self.direction == definitions.CART_DIRECTION_WEST and cart_rect.x - definitions.BLOCK_SIZE > 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def is_move_allowed_succ(
|
||||
node): # sprawdza czy dany ruch, który chce wykonać wózek jest możliwy, zwraca pozycje po wykonaniu ruchu, wersja node
|
||||
if node.get_direction() == definitions.CART_DIRECTION_EAST and node.get_x() * definitions.BLOCK_SIZE + definitions.BLOCK_SIZE < definitions.WIDTH_MAP:
|
||||
return "x + 1"
|
||||
elif node.get_direction() == definitions.CART_DIRECTION_NORTH and node.get_y() * definitions.BLOCK_SIZE - definitions.BLOCK_SIZE > 0:
|
||||
return "y - 1"
|
||||
elif node.get_direction() == definitions.CART_DIRECTION_SOUTH and node.get_y() * definitions.BLOCK_SIZE + definitions.BLOCK_SIZE < definitions.HEIGHT_MAP:
|
||||
return "y + 1"
|
||||
elif node.get_direction() == definitions.CART_DIRECTION_WEST and node.get_x() * definitions.BLOCK_SIZE - definitions.BLOCK_SIZE > 0:
|
||||
return "x - 1"
|
||||
else:
|
||||
return False
|
||||
|
||||
def move(self):
|
||||
if self.direction == definitions.CART_DIRECTION_EAST:
|
||||
self.x = self.x + definitions.BLOCK_SIZE
|
||||
elif self.direction == definitions.CART_DIRECTION_NORTH:
|
||||
self.y = self.y + definitions.BLOCK_SIZE
|
||||
elif self.direction == definitions.CART_DIRECTION_SOUTH:
|
||||
self.y = self.y - definitions.BLOCK_SIZE
|
||||
elif self.direction == definitions.CART_DIRECTION_WEST:
|
||||
self.x = self.x - definitions.BLOCK_SIZE
|
||||
|
||||
def rotate_right(self):
|
||||
if self.direction == 1:
|
||||
self.direction = 4
|
||||
else:
|
||||
self.direction = self.direction - 1
|
||||
|
||||
def rotate_left(self):
|
||||
if self.direction == 4:
|
||||
self.direction = 1
|
||||
else:
|
||||
self.direction = self.direction + 1
|
38
classes.py
@ -1,38 +0,0 @@
|
||||
class Field:
|
||||
def __init__(self, fieldType, plantType, isWet, wetTime, isFertilized, fertilizedTime):
|
||||
self.fieldType = fieldType # good/bad
|
||||
self.plantType = plantType # wheat/carrot/cabbage
|
||||
self.isWet = isWet # yes/no
|
||||
self.wetTime = wetTime # number
|
||||
self.isFertilized = isFertilized # yes/no
|
||||
self.fertilizedTime = fertilizedTime # number
|
||||
|
||||
|
||||
|
||||
class Plant:
|
||||
def __init__(self, plantType, growthState):
|
||||
self.plantType = plantType # wheat/carrot/cabbage
|
||||
self.growthState = growthState # growing/grown
|
||||
|
||||
|
||||
class Fertilizer:
|
||||
def __init__(self, fertilizerType):
|
||||
self.fertilizerType = fertilizerType # wheat/carrot/cabbage
|
||||
|
||||
|
||||
class Player:
|
||||
x = 0
|
||||
y = 0
|
||||
rotation = 0
|
||||
|
||||
|
||||
class Watering:
|
||||
def __init__(self, rain, planted, temperature, sunny, snowy, moist, rotten, dayTime ):
|
||||
self.rain = rain # yes/no
|
||||
self.planted = planted # yes/no
|
||||
self.temperature = temperature # good/bad
|
||||
self.sunny = sunny
|
||||
self.snowy = snowy # yes/no
|
||||
self.moist = moist # yes/no
|
||||
self.rotten = rotten # yes/no
|
||||
self.dayTime = dayTime # 1 2 3 4
|
@ -1,200 +0,0 @@
|
||||
11100101
|
||||
11011110
|
||||
00001101
|
||||
11101002
|
||||
11111000
|
||||
11101013
|
||||
00100102
|
||||
00000001
|
||||
10011002
|
||||
01011000
|
||||
01111112
|
||||
00010113
|
||||
10111011
|
||||
00111000
|
||||
10010002
|
||||
01011100
|
||||
00110001
|
||||
11001000
|
||||
11011103
|
||||
01100002
|
||||
01110011
|
||||
11101113
|
||||
10110101
|
||||
01010113
|
||||
11101111
|
||||
11000013
|
||||
01001011
|
||||
10101111
|
||||
01110112
|
||||
10000001
|
||||
00110000
|
||||
10000112
|
||||
01111013
|
||||
10100012
|
||||
11010100
|
||||
11001011
|
||||
10001002
|
||||
01001103
|
||||
00011110
|
||||
10101102
|
||||
01111102
|
||||
01000111
|
||||
01000010
|
||||
00110002
|
||||
11111010
|
||||
11101000
|
||||
11000100
|
||||
01010100
|
||||
01001112
|
||||
00101011
|
||||
11101010
|
||||
00010011
|
||||
01001113
|
||||
01001002
|
||||
01101111
|
||||
11100102
|
||||
11111112
|
||||
00111001
|
||||
11110111
|
||||
11011112
|
||||
10001101
|
||||
11100001
|
||||
10101101
|
||||
00111110
|
||||
00101112
|
||||
11100111
|
||||
00100002
|
||||
01011103
|
||||
10111100
|
||||
00100100
|
||||
00001010
|
||||
00001012
|
||||
10100102
|
||||
00001013
|
||||
01011003
|
||||
11111102
|
||||
00011000
|
||||
00101013
|
||||
10111103
|
||||
10100010
|
||||
11111003
|
||||
11000000
|
||||
01100101
|
||||
10010101
|
||||
10011101
|
||||
10101000
|
||||
01100000
|
||||
00111103
|
||||
11000011
|
||||
10010012
|
||||
00111003
|
||||
01001010
|
||||
10101003
|
||||
00010003
|
||||
10000102
|
||||
10110113
|
||||
00011013
|
||||
01011012
|
||||
01100112
|
||||
10010111
|
||||
01110100
|
||||
00110113
|
||||
10000012
|
||||
01100010
|
||||
01100100
|
||||
00110010
|
||||
00110102
|
||||
10100003
|
||||
10000111
|
||||
11010103
|
||||
11011012
|
||||
01111100
|
||||
00000100
|
||||
11100113
|
||||
11101103
|
||||
10111003
|
||||
00110101
|
||||
00011100
|
||||
01100001
|
||||
11100011
|
||||
10110010
|
||||
01001102
|
||||
10101011
|
||||
10000002
|
||||
11100000
|
||||
11101102
|
||||
01110101
|
||||
01100102
|
||||
01001012
|
||||
11111101
|
||||
01110001
|
||||
11000010
|
||||
01010011
|
||||
01100004
|
||||
01000001
|
||||
11010112
|
||||
10110003
|
||||
00010012
|
||||
00001110
|
||||
01001100
|
||||
01001111
|
||||
11010003
|
||||
00000110
|
||||
00110112
|
||||
10110102
|
||||
01111002
|
||||
11110110
|
||||
11010111
|
||||
11111100
|
||||
10111013
|
||||
10001003
|
||||
11100003
|
||||
00110013
|
||||
10100103
|
||||
01010002
|
||||
00001100
|
||||
10001010
|
||||
00100110
|
||||
10110100
|
||||
10000011
|
||||
10101112
|
||||
11110003
|
||||
11011013
|
||||
10101110
|
||||
00001011
|
||||
10010112
|
||||
01100110
|
||||
01010112
|
||||
11011111
|
||||
01011001
|
||||
01101103
|
||||
10000010
|
||||
00110111
|
||||
01001110
|
||||
11001003
|
||||
11110002
|
||||
00111113
|
||||
00000112
|
||||
10100002
|
||||
10110002
|
||||
10001102
|
||||
10010000
|
||||
01111103
|
||||
00000012
|
||||
10000003
|
||||
00011103
|
||||
11000110
|
||||
11001002
|
||||
11010002
|
||||
01110012
|
||||
00100013
|
||||
00010103
|
||||
01110111
|
||||
10010113
|
||||
01010003
|
||||
11001110
|
||||
00011112
|
||||
00010101
|
||||
10100101
|
||||
01011101
|
@ -1,200 +0,0 @@
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
@ -1,23 +0,0 @@
|
||||
import random
|
||||
|
||||
|
||||
# Generowanie unikalnej losowej linii tekstu
|
||||
def generate_unique_line(existing_lines):
|
||||
while True:
|
||||
line = ''.join(random.choice(['0', '1']) for _ in range(7))
|
||||
last_digit = random.choice(['1', '2', '3', '0'])
|
||||
line += last_digit
|
||||
if line not in existing_lines:
|
||||
return line
|
||||
|
||||
|
||||
# Generowanie 200 unikalnych linii tekstu
|
||||
lines = []
|
||||
while len(lines) < 200:
|
||||
line = generate_unique_line(lines)
|
||||
lines.append(line)
|
||||
|
||||
# Zapisywanie linii tekstu do pliku
|
||||
with open('decisionTree/database.txt', 'w') as file:
|
||||
for line in lines:
|
||||
file.write(line + '\n')
|
@ -1,200 +0,0 @@
|
||||
['rainy', 'planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'noon']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'snow', 'moist', 'rot', 'morning']
|
||||
['clear', 'not planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'noon']
|
||||
['rainy', 'planted', 'good', 'good', 'snow', 'dry', 'healthy', 'sunset']
|
||||
['rainy', 'planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'morning']
|
||||
['rainy', 'planted', 'good', 'good', 'snow', 'dry', 'rot', 'night']
|
||||
['clear', 'not planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'sunset']
|
||||
['clear', 'not planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'noon']
|
||||
['rainy', 'not planted', 'bad', 'too strong', 'snow', 'dry', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'bad', 'too strong', 'snow', 'dry', 'healthy', 'morning']
|
||||
['clear', 'planted', 'good', 'too strong', 'snow', 'moist', 'rot', 'sunset']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'night']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'snow', 'dry', 'rot', 'noon']
|
||||
['clear', 'not planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'morning']
|
||||
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'morning']
|
||||
['clear', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'noon']
|
||||
['rainy', 'planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'morning']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'night']
|
||||
['clear', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'good', 'too strong', 'no snow', 'dry', 'rot', 'noon']
|
||||
['rainy', 'planted', 'good', 'good', 'snow', 'moist', 'rot', 'night']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'noon']
|
||||
['clear', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'night']
|
||||
['rainy', 'planted', 'good', 'good', 'snow', 'moist', 'rot', 'noon']
|
||||
['rainy', 'planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'night']
|
||||
['clear', 'planted', 'bad', 'good', 'snow', 'dry', 'rot', 'noon']
|
||||
['rainy', 'not planted', 'good', 'good', 'snow', 'moist', 'rot', 'noon']
|
||||
['clear', 'planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'sunset']
|
||||
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'noon']
|
||||
['clear', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'morning']
|
||||
['rainy', 'not planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'sunset']
|
||||
['clear', 'planted', 'good', 'too strong', 'snow', 'dry', 'rot', 'night']
|
||||
['rainy', 'not planted', 'good', 'good', 'no snow', 'dry', 'rot', 'sunset']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'morning']
|
||||
['rainy', 'planted', 'bad', 'good', 'snow', 'dry', 'rot', 'noon']
|
||||
['rainy', 'not planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'night']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'snow', 'moist', 'rot', 'morning']
|
||||
['rainy', 'not planted', 'good', 'good', 'snow', 'moist', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'noon']
|
||||
['clear', 'planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'morning']
|
||||
['clear', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
|
||||
['rainy', 'planted', 'good', 'too strong', 'snow', 'dry', 'rot', 'morning']
|
||||
['rainy', 'planted', 'good', 'good', 'snow', 'dry', 'healthy', 'morning']
|
||||
['rainy', 'planted', 'bad', 'good', 'no snow', 'moist', 'healthy', 'morning']
|
||||
['clear', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'morning']
|
||||
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'rot', 'sunset']
|
||||
['clear', 'not planted', 'good', 'good', 'snow', 'dry', 'rot', 'noon']
|
||||
['rainy', 'planted', 'good', 'good', 'snow', 'dry', 'rot', 'morning']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'rot', 'noon']
|
||||
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'rot', 'night']
|
||||
['clear', 'planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'good', 'good', 'snow', 'moist', 'rot', 'noon']
|
||||
['rainy', 'planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'sunset']
|
||||
['rainy', 'planted', 'good', 'too strong', 'snow', 'moist', 'rot', 'sunset']
|
||||
['clear', 'not planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'noon']
|
||||
['rainy', 'planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'noon']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'snow', 'moist', 'rot', 'sunset']
|
||||
['rainy', 'not planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'noon']
|
||||
['rainy', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'noon']
|
||||
['rainy', 'not planted', 'good', 'good', 'snow', 'moist', 'healthy', 'noon']
|
||||
['clear', 'not planted', 'good', 'too strong', 'snow', 'moist', 'rot', 'morning']
|
||||
['clear', 'not planted', 'good', 'good', 'snow', 'moist', 'rot', 'sunset']
|
||||
['rainy', 'planted', 'good', 'good', 'no snow', 'moist', 'rot', 'noon']
|
||||
['clear', 'not planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'night']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'morning']
|
||||
['clear', 'not planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'morning']
|
||||
['clear', 'not planted', 'bad', 'good', 'snow', 'dry', 'rot', 'morning']
|
||||
['clear', 'not planted', 'bad', 'good', 'snow', 'dry', 'rot', 'sunset']
|
||||
['rainy', 'not planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'sunset']
|
||||
['clear', 'not planted', 'bad', 'good', 'snow', 'dry', 'rot', 'night']
|
||||
['clear', 'planted', 'bad', 'too strong', 'snow', 'dry', 'healthy', 'night']
|
||||
['rainy', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'sunset']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'snow', 'dry', 'healthy', 'morning']
|
||||
['clear', 'not planted', 'good', 'good', 'snow', 'dry', 'rot', 'night']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'night']
|
||||
['rainy', 'not planted', 'good', 'good', 'no snow', 'dry', 'rot', 'morning']
|
||||
['rainy', 'planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'night']
|
||||
['rainy', 'planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'morning']
|
||||
['clear', 'planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'noon']
|
||||
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'noon']
|
||||
['rainy', 'not planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'noon']
|
||||
['rainy', 'not planted', 'good', 'good', 'snow', 'dry', 'healthy', 'morning']
|
||||
['clear', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'morning']
|
||||
['clear', 'not planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'night']
|
||||
['rainy', 'planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'noon']
|
||||
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'rot', 'sunset']
|
||||
['clear', 'not planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'night']
|
||||
['clear', 'planted', 'bad', 'good', 'snow', 'dry', 'rot', 'morning']
|
||||
['rainy', 'not planted', 'good', 'good', 'snow', 'dry', 'healthy', 'night']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'night']
|
||||
['rainy', 'not planted', 'bad', 'good', 'no snow', 'moist', 'healthy', 'sunset']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'night']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'snow', 'dry', 'rot', 'night']
|
||||
['clear', 'planted', 'bad', 'too strong', 'snow', 'dry', 'rot', 'sunset']
|
||||
['clear', 'planted', 'good', 'good', 'no snow', 'moist', 'rot', 'sunset']
|
||||
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'noon']
|
||||
['clear', 'planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'morning']
|
||||
['clear', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'night']
|
||||
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'sunset']
|
||||
['clear', 'planted', 'good', 'good', 'no snow', 'dry', 'rot', 'morning']
|
||||
['clear', 'planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'morning']
|
||||
['clear', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'rot', 'morning']
|
||||
['clear', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'sunset']
|
||||
['rainy', 'not planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'night']
|
||||
['rainy', 'not planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'noon']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'night']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'snow', 'dry', 'rot', 'sunset']
|
||||
['clear', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'morning']
|
||||
['clear', 'not planted', 'bad', 'good', 'no snow', 'moist', 'healthy', 'morning']
|
||||
['rainy', 'planted', 'good', 'good', 'no snow', 'moist', 'rot', 'night']
|
||||
['rainy', 'planted', 'good', 'good', 'snow', 'moist', 'healthy', 'night']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'night']
|
||||
['clear', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'noon']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'morning']
|
||||
['clear', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'noon']
|
||||
['rainy', 'planted', 'good', 'good', 'no snow', 'dry', 'rot', 'noon']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'rot', 'morning']
|
||||
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'sunset']
|
||||
['rainy', 'not planted', 'good', 'good', 'snow', 'dry', 'rot', 'noon']
|
||||
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'sunset']
|
||||
['rainy', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'morning']
|
||||
['rainy', 'planted', 'good', 'good', 'snow', 'moist', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'noon']
|
||||
['clear', 'planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'bad', 'good', 'snow', 'dry', 'rot', 'sunset']
|
||||
['rainy', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'noon']
|
||||
['clear', 'planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'noon']
|
||||
['rainy', 'planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'morning']
|
||||
['clear', 'planted', 'bad', 'too strong', 'no snow', 'dry', 'rot', 'noon']
|
||||
['clear', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'night']
|
||||
['clear', 'planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'noon']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'sunset']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'night']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'rot', 'sunset']
|
||||
['clear', 'not planted', 'bad', 'good', 'snow', 'moist', 'rot', 'morning']
|
||||
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'morning']
|
||||
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'rot', 'noon']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'night']
|
||||
['clear', 'not planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'morning']
|
||||
['clear', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'sunset']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'sunset']
|
||||
['rainy', 'planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'morning']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'noon']
|
||||
['rainy', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'morning']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'snow', 'dry', 'rot', 'night']
|
||||
['rainy', 'not planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'night']
|
||||
['rainy', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'night']
|
||||
['clear', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'rot', 'night']
|
||||
['rainy', 'not planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'night']
|
||||
['clear', 'planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
|
||||
['clear', 'not planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'morning']
|
||||
['rainy', 'not planted', 'bad', 'good', 'snow', 'dry', 'rot', 'morning']
|
||||
['clear', 'not planted', 'good', 'good', 'no snow', 'moist', 'rot', 'morning']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'morning']
|
||||
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'noon']
|
||||
['rainy', 'not planted', 'good', 'good', 'snow', 'moist', 'rot', 'sunset']
|
||||
['rainy', 'planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'night']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'snow', 'dry', 'rot', 'night']
|
||||
['rainy', 'not planted', 'good', 'good', 'snow', 'moist', 'rot', 'morning']
|
||||
['clear', 'not planted', 'bad', 'good', 'snow', 'dry', 'rot', 'noon']
|
||||
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'sunset']
|
||||
['clear', 'planted', 'good', 'good', 'no snow', 'moist', 'rot', 'morning']
|
||||
['clear', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'sunset']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'snow', 'moist', 'rot', 'noon']
|
||||
['clear', 'planted', 'bad', 'too strong', 'snow', 'dry', 'healthy', 'noon']
|
||||
['clear', 'planted', 'good', 'good', 'snow', 'moist', 'healthy', 'night']
|
||||
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'morning']
|
||||
['clear', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'noon']
|
||||
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'rot', 'morning']
|
||||
['rainy', 'planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'night']
|
||||
['rainy', 'planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
|
||||
['clear', 'not planted', 'good', 'too strong', 'snow', 'moist', 'rot', 'night']
|
||||
['clear', 'not planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'sunset']
|
||||
['rainy', 'not planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'sunset']
|
||||
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
|
||||
['rainy', 'not planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'sunset']
|
||||
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'morning']
|
||||
['clear', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'night']
|
||||
['clear', 'not planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'sunset']
|
||||
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'night']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'night']
|
||||
['rainy', 'planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'morning']
|
||||
['rainy', 'planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'sunset']
|
||||
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
|
||||
['clear', 'planted', 'good', 'too strong', 'no snow', 'dry', 'rot', 'sunset']
|
||||
['clear', 'not planted', 'good', 'good', 'no snow', 'dry', 'rot', 'night']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'night']
|
||||
['clear', 'planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'noon']
|
||||
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'night']
|
||||
['clear', 'planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'night']
|
||||
['rainy', 'planted', 'bad', 'good', 'snow', 'moist', 'rot', 'morning']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'snow', 'moist', 'rot', 'sunset']
|
||||
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'noon']
|
||||
['rainy', 'not planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'noon']
|
||||
['clear', 'planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'noon']
|
@ -1,77 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
# from sklearn.datasets import load_iris
|
||||
from sklearn.tree import export_text
|
||||
|
||||
from sklearn.tree import DecisionTreeClassifier
|
||||
import joblib
|
||||
|
||||
X1 = []
|
||||
view = []
|
||||
with open("database.txt", 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
test_list = [int(i) for i in line]
|
||||
x = []
|
||||
if line[0] == "0":
|
||||
x.append("clear")
|
||||
else:
|
||||
x.append("rainy")
|
||||
if line[1] == "0":
|
||||
x.append("not planted")
|
||||
else:
|
||||
x.append("planted")
|
||||
if line[2] == "0":
|
||||
x.append("bad")
|
||||
else:
|
||||
x.append("good")
|
||||
if line[3] == "0":
|
||||
x.append("good")
|
||||
else:
|
||||
x.append("too strong")
|
||||
if line[4] == "0":
|
||||
x.append("no snow")
|
||||
else:
|
||||
x.append("snow")
|
||||
if line[5] == "0":
|
||||
x.append("dry")
|
||||
else:
|
||||
x.append("moist")
|
||||
if line[6] == "0":
|
||||
x.append("healthy")
|
||||
else:
|
||||
x.append("rot")
|
||||
if line[7] == "0":
|
||||
x.append("morning")
|
||||
elif line[7] == "1":
|
||||
x.append("noon")
|
||||
elif line[7] == "2":
|
||||
x.append("sunset")
|
||||
else:
|
||||
x.append("night")
|
||||
view.append(x)
|
||||
X1.append(test_list)
|
||||
|
||||
f = open("learning_set.txt", "w") # zapisuje atrybuty s³ownie
|
||||
for i in view:
|
||||
f.write(str(i)+"\n")
|
||||
f.close()
|
||||
|
||||
|
||||
Y1 = []
|
||||
with open("decissions.txt", 'r') as f: # czyta decyzje
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
test = int(line)
|
||||
Y1.append(test)
|
||||
|
||||
dataset = X1
|
||||
decision = Y1
|
||||
labels = ['Rain', 'Plant', 'Temperature', 'Sun', 'Snow', 'Moisture', 'Rotten', 'Time']
|
||||
model = DecisionTreeClassifier(random_state=0, max_depth=20).fit(dataset, decision)
|
||||
filename = 'decisionTree.sav'
|
||||
print("Model trained")
|
||||
print("Decision tree:")
|
||||
print(export_text(model, feature_names=labels))
|
||||
joblib.dump(model, filename)
|
@ -1,22 +0,0 @@
|
||||
import pygame
|
||||
|
||||
pygame.init()
|
||||
BLOCK_SIZE = 50
|
||||
|
||||
WHEAT_COST = 2
|
||||
CARROT_COST = 5
|
||||
CABBAGE_COST = 13
|
||||
TREE_COST = 100000
|
||||
DIRT_COST = 1
|
||||
WET_DIRT_COST = 4
|
||||
|
||||
CART_DIRECTION_EAST = 1
|
||||
CART_DIRECTION_NORTH = 2
|
||||
CART_DIRECTION_SOUTH = 4
|
||||
CART_DIRECTION_WEST = 3
|
||||
|
||||
HEIGHT_AMOUNT, WIDTH_AMOUNT = 11, 11
|
||||
HEIGHT_MAP, WIDTH_MAP = BLOCK_SIZE * HEIGHT_AMOUNT, BLOCK_SIZE * WIDTH_AMOUNT
|
||||
HEIGHT, WIDTH = HEIGHT_MAP + BLOCK_SIZE, WIDTH_MAP
|
||||
IMAGE_SIZE_NEURAL_NETWORK = 16
|
||||
WINDOW = pygame.display.set_mode((WIDTH, HEIGHT))
|
@ -1,90 +0,0 @@
|
||||
import random
|
||||
import math
|
||||
|
||||
|
||||
def create_initial_population(population_size, new_list, player):
|
||||
population = []
|
||||
for _ in range(population_size):
|
||||
chromosome = new_list.copy()
|
||||
chromosome.remove((player.x+1, player.y+1))
|
||||
random.shuffle(chromosome)
|
||||
chromosome.insert(0, (player.x+1, player.y+1))
|
||||
population.append(chromosome)
|
||||
return population
|
||||
|
||||
|
||||
def calculate_distance(node1, node2):
|
||||
x1, y1 = node1
|
||||
x2, y2 = node2
|
||||
distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
|
||||
return distance
|
||||
|
||||
|
||||
def calculate_fitness(individual):
|
||||
total_distance = 0
|
||||
num_nodes = len(individual)
|
||||
|
||||
for i in range(num_nodes - 1):
|
||||
node1 = individual[i]
|
||||
node2 = individual[i + 1]
|
||||
distance = calculate_distance(node1, node2)
|
||||
|
||||
total_distance += distance
|
||||
|
||||
if total_distance == 0:
|
||||
fitness = float('inf')
|
||||
return fitness
|
||||
|
||||
fitness = 1 / total_distance
|
||||
return fitness
|
||||
|
||||
|
||||
def crossover(parent1, parent2, player):
|
||||
child = [(player.x+1, player.y+1)] + [None] * (len(parent1) - 1)
|
||||
start_index = random.randint(1, len(parent1) - 1)
|
||||
end_index = random.randint(start_index + 1, len(parent1))
|
||||
child[start_index:end_index] = parent1[start_index:end_index]
|
||||
remaining_nodes = [node for node in parent2 if node not in child]
|
||||
child[1:start_index] = remaining_nodes[:start_index - 1]
|
||||
child[end_index:] = remaining_nodes[start_index - 1:]
|
||||
return child
|
||||
|
||||
|
||||
def mutate(individual, mutation_rate):
|
||||
for i in range(1, len(individual)):
|
||||
if random.random() < mutation_rate:
|
||||
j = random.randint(1, len(individual) - 1)
|
||||
individual[i], individual[j] = individual[j], individual[i]
|
||||
return individual
|
||||
|
||||
|
||||
def genetic_algorithm(new_list, player):
|
||||
max_generations = 200
|
||||
population_size = 200
|
||||
mutation_rate = 0.1
|
||||
population = create_initial_population(population_size, new_list, player)
|
||||
best_individual = None
|
||||
best_fitness = float('-inf')
|
||||
|
||||
for generation in range(max_generations):
|
||||
fitness_values = [calculate_fitness(individual) for individual in population]
|
||||
population = [x for _, x in sorted(zip(fitness_values, population), reverse=True)]
|
||||
fitness_values.sort(reverse=True)
|
||||
best_individuals = population[:10]
|
||||
new_population = best_individuals.copy()
|
||||
|
||||
while len(new_population) < population_size:
|
||||
parent1, parent2 = random.choices(best_individuals, k=2)
|
||||
child = crossover(parent1, parent2, player)
|
||||
child = mutate(child, mutation_rate)
|
||||
new_population.append(child)
|
||||
|
||||
for individual in best_individuals:
|
||||
fitness = calculate_fitness(individual)
|
||||
if fitness > best_fitness:
|
||||
best_fitness = fitness
|
||||
best_individual = individual
|
||||
|
||||
population = new_population[:population_size]
|
||||
|
||||
return best_individual
|
BIN
img/player.png
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 16 KiB |
BIN
img/tree.png
Before Width: | Height: | Size: 3.9 KiB |
840
main.py
@ -1,823 +1,105 @@
|
||||
import joblib
|
||||
import numpy as np
|
||||
import pygame
|
||||
import random
|
||||
|
||||
from genetic_algorithm import genetic_algorithm
|
||||
|
||||
import torch
|
||||
from torch import nn
|
||||
from torchvision import datasets, transforms
|
||||
from torchvision.transforms import Lambda
|
||||
from PIL import Image
|
||||
class Field:
|
||||
def __init__(self, fieldType, plantType, isWet, wetTime, isFertilized, fertilizedTime):
|
||||
self.fieldType = fieldType # good/bad
|
||||
self.plantType = plantType # wheat/carrot/cabbage
|
||||
self.isWet = isWet # yes/no
|
||||
self.wetTime = wetTime # number
|
||||
self.isFertilized = isFertilized # yes/no
|
||||
self.fertilizedTime = fertilizedTime # number
|
||||
|
||||
import astar
|
||||
from classes import Field, Player, Watering
|
||||
from bfs import Istate, succ
|
||||
from bfs import graphsearch
|
||||
from board import Grid, Box, Obstacle, getGridBoxes, gridObjects
|
||||
from screen import SCREEN
|
||||
|
||||
# pygame.init()
|
||||
class Plant:
|
||||
def __init__(self, plantType, growthState):
|
||||
self.plantType = plantType # wheat/carrot/cabbage
|
||||
self.growthState = growthState # growing/grown
|
||||
|
||||
# Game Constants
|
||||
Ucelu = False
|
||||
SCREENX = 500
|
||||
SCREENY = 500
|
||||
device = torch.device('cpu')
|
||||
model1 = nn.Sequential(nn.Linear(30000, 10000), nn.ReLU(), nn.Linear(10000, 10000), nn.ReLU(), nn.Linear(10000, 10000), nn.Linear(10000, 4), nn.LogSoftmax(dim=-1)).to(device)
|
||||
# model1.load_state_dict(torch.load("./NN/trained"))
|
||||
|
||||
pygame.display.set_caption('Inteligentny Traktor')
|
||||
plants = [[], [], []]
|
||||
plants[0].append(Image.open("NN/w1.png"))
|
||||
plants[0].append(Image.open("NN/w2.png"))
|
||||
plants[0].append(Image.open("NN/w3.png"))
|
||||
plants[1].append(Image.open("NN/c1.png"))
|
||||
plants[1].append(Image.open("NN/c2.png"))
|
||||
plants[1].append(Image.open("NN/c3.png"))
|
||||
plants[2].append(Image.open("NN/ca1.png"))
|
||||
plants[2].append(Image.open("NN/ca2.png"))
|
||||
plants[2].append(Image.open("NN/ca3.png"))
|
||||
b = [Image.open("NN/b1.png").convert('RGBA'), Image.open("NN/b2.png").convert('RGBA'), Image.open("NN/b3.png").convert('RGBA')]
|
||||
class Fertilizer:
|
||||
def __init__(self, fertilizerType):
|
||||
self.fertilizerType = fertilizerType # wheat/carrot/cabbage
|
||||
|
||||
|
||||
def generate(water, fertilizer, plantf):
|
||||
if water == 1:
|
||||
new_im = Image.new('RGB', (100, 100),
|
||||
(160 + random.randint(-10, 10), 80 + random.randint(-10, 10), 40 + random.randint(-10, 10)))
|
||||
tmp = plants[plantf][random.randint(0, 2)].resize(
|
||||
(25 + random.randint(-10, 25), 25 + random.randint(-10, 25))).rotate(random.randint(0, 359))
|
||||
new_im.paste(tmp, (random.randint(0, 50), random.randint(0, 50)), tmp)
|
||||
if fertilizer:
|
||||
tmp = b[random.randint(0, 2)].resize(
|
||||
(20 + random.randint(0, 25), 20 + random.randint(0, 25))).rotate(random.randint(0, 359))
|
||||
new_im.paste(tmp, (random.randint(25, 75), random.randint(25, 75)), tmp)
|
||||
else:
|
||||
if fertilizer:
|
||||
new_im = Image.new('RGB', (100, 100),
|
||||
(
|
||||
50 + random.randint(-10, 10), 25 + random.randint(-10, 10),
|
||||
0 + random.randint(-10, 10)))
|
||||
tmp = plants[plantf][random.randint(0, 2)].resize(
|
||||
(25 + random.randint(-10, 25), 25 + random.randint(-10, 25))).rotate(random.randint(0, 359))
|
||||
new_im.paste(tmp, (random.randint(0, 50), random.randint(0, 50)), tmp)
|
||||
tmp = b[random.randint(0, 2)].resize(
|
||||
(20 + random.randint(0, 25), 20 + random.randint(0, 25))).rotate(random.randint(0, 359))
|
||||
new_im.paste(tmp, (random.randint(25, 75), random.randint(25, 75)), tmp)
|
||||
class Player:
|
||||
x = 0
|
||||
y = 0
|
||||
rotation = 0
|
||||
|
||||
else:
|
||||
if random.randint(0, 1) == 1:
|
||||
new_im = Image.new('RGB', (100, 100),
|
||||
(50 + random.randint(-10, 10), 25 + random.randint(-10, 10),
|
||||
0 + random.randint(-10, 10)))
|
||||
else:
|
||||
new_im = Image.new('RGB', (100, 100),
|
||||
(160 + random.randint(-10, 10), 80 + random.randint(-10, 10),
|
||||
40 + random.randint(-10, 10)))
|
||||
if random.randint(0, 1) == 1: # big
|
||||
tmp = plants[plantf][random.randint(0, 2)].resize(
|
||||
(75 + random.randint(-10, 25), 75 + random.randint(-10, 25))).rotate(random.randint(0, 359))
|
||||
new_im.paste(tmp, (random.randint(0, 15), random.randint(0, 15)), tmp)
|
||||
else:
|
||||
tmp = plants[plantf][random.randint(0, 2)].resize(
|
||||
(random.randint(10, 80), random.randint(10, 80))).rotate(random.randint(0, 359))
|
||||
datas = tmp.getdata()
|
||||
|
||||
new_image_data = []
|
||||
for item in datas:
|
||||
# change all white (also shades of whites) pixels to yellow
|
||||
if item[0] in list(range(190, 256)):
|
||||
new_image_data.append(
|
||||
(random.randint(0, 10), 255 + random.randint(-150, 0), random.randint(0, 10)))
|
||||
else:
|
||||
new_image_data.append(item)
|
||||
|
||||
# update image data
|
||||
tmp.putdata(new_image_data)
|
||||
new_im.paste(tmp, (random.randint(0, 30), random.randint(0, 30)), tmp)
|
||||
|
||||
return new_im
|
||||
|
||||
|
||||
# COLORS
|
||||
WHITE = (255, 255, 255)
|
||||
BLACK = (0, 0, 0)
|
||||
RED = (255, 0, 0)
|
||||
GREEN = (0, 255, 0, 0)
|
||||
BLUE = (0, 0, 255, 0)
|
||||
GREY = (128, 128, 128)
|
||||
|
||||
CLOCK = pygame.time.Clock()
|
||||
FPS = 30
|
||||
DELAY = 300
|
||||
|
||||
# np. 10 pól x 10 pól = 100 pól
|
||||
GRIDX = 10
|
||||
GRIDY = 10
|
||||
|
||||
obstacleObjects = {} # Store the obstacle objects (Blocks on the path) from Obstacle class
|
||||
# global gridObjects
|
||||
# gridObjects = {} # Store grid-box objects from Grid Class
|
||||
gridObstacle = {} # Store the grid:obstacle pair stuck together
|
||||
boxObjects = {}
|
||||
boxes = 1
|
||||
obstacles = 1
|
||||
|
||||
# BFS Variables
|
||||
|
||||
startNode = Istate(1, 1, 1)
|
||||
goalNode = [1, 1]
|
||||
|
||||
graph = dict()
|
||||
pathFound = [] # Store the path in a list box index to draw on later
|
||||
|
||||
wheat_path = []
|
||||
carrot_path = []
|
||||
cabbage_path = []
|
||||
|
||||
def drawGrid(sizex, sizey):
|
||||
spaceX = SCREENX // sizex
|
||||
spaceY = SCREENY // sizey
|
||||
|
||||
counter = 1
|
||||
for i in range(sizex):
|
||||
for j in range(sizey):
|
||||
# g = Grid(i*spaceX, j*spaceY, spaceX, spaceY)
|
||||
g = Grid(50 + i*50, 50 + j*50, spaceX, spaceY)
|
||||
gridObjects[counter] = g
|
||||
counter += 1
|
||||
|
||||
|
||||
def generateGraph(row, col):
|
||||
# This function generates a graph based on the gridObjects instantiated!
|
||||
# sample_graph = {'A': ['B', 'C', 'E'],
|
||||
# 'B': ['A', 'D', 'E'],
|
||||
# 'C': ['A', 'F', 'G'],
|
||||
# 'D': ['B'],
|
||||
# 'E': ['A', 'B', 'D'],
|
||||
# 'F': ['C'],
|
||||
# 'G': ['C']
|
||||
# }
|
||||
|
||||
miniG = {}
|
||||
for grid in range(len(gridObjects)):
|
||||
grid += 1 # Synchronize index
|
||||
mod = grid % col # Used to check the Top and Bottom Grid Boxes!
|
||||
gN = grid - 1
|
||||
gS = grid + 1
|
||||
gE = grid + col
|
||||
gW = grid - col
|
||||
|
||||
# CHECK THE NEIGHBORS TO THE GRID-BOXES, ACCOUNTING FOR THE EXTREME GRID-BOXES(BORDERS)
|
||||
if mod == 0: # 5,10,15,20,25 - You can't go south from here (Bottom Boxes)
|
||||
if grid > col: # Away from the Left Border of the Screen
|
||||
if grid > (col*row)-col: # You are on the Right Border of the screen - You can't go East
|
||||
miniG[grid] = [gN, gW]
|
||||
else: # Away from the Right Border of the Screen - You can go East
|
||||
miniG[grid] = [gN, gE, gW]
|
||||
else: # You are on the Left Edge of the screen - You can't go West
|
||||
miniG[grid] = [gN, gE]
|
||||
|
||||
elif mod == 1: # 6,11,16,21 :> You can't go North from here (Top Boxes)
|
||||
if grid > col: # Away from the Left Border of the Screen
|
||||
if grid > (col*row)-col: # You are on the Right Border of the screen - You can't go East
|
||||
miniG[grid] = [gS, gW]
|
||||
else: # Away from the Right Border of the Screen - You can go east
|
||||
miniG[grid] = [gS, gE, gW]
|
||||
else: # You are on the Left Edge of the screen - You can't go West
|
||||
miniG[grid] = [gS, gE]
|
||||
|
||||
else: # All the rest (Not Top or Bottom Boxes) - You can go North or South
|
||||
if grid > col: # Away from the Left Border of the Screen
|
||||
if grid > (col*row)-col: # You are on the Right Border of the screen - You can't go East
|
||||
miniG[grid] = [gN, gS, gW]
|
||||
else: # Away from the Right Border of the Screen - You can go East
|
||||
miniG[grid] = [gN, gS, gE, gW]
|
||||
else: # You are on the Left Edge of the screen - You can't go West
|
||||
miniG[grid] = [gN, gS, gE]
|
||||
|
||||
# FILTER OUT OBSTACLES FROM THE GRAPH
|
||||
miniG2 = {}
|
||||
for grid in range(len(gridObjects)):
|
||||
grid += 1
|
||||
if grid not in gridObstacle:
|
||||
# gridObjects.remove(grid) # Dict object has no attribute : 'remove'
|
||||
# HACK
|
||||
miniG2[grid] = miniG[grid] # Created a new dictionary that stored the values required
|
||||
# IN-DEPTH FILTER - Filter out obstacles from the neighbors-list
|
||||
for neigbor in miniG2[grid]:
|
||||
if neigbor in gridObstacle:
|
||||
miniG2[grid].remove(neigbor)
|
||||
|
||||
# Filtering again as the first Filter block didn't clear out everything
|
||||
# Filtering through the neighbors
|
||||
for grid in miniG2:
|
||||
for item in miniG2[grid]:
|
||||
if item in gridObstacle:
|
||||
miniG2[grid].remove(item)
|
||||
|
||||
return miniG2
|
||||
|
||||
|
||||
def drawGraph(pathF):
|
||||
# Draws the path given the path-list
|
||||
global Ucelu
|
||||
# print(pathF)
|
||||
|
||||
if not Ucelu:
|
||||
for grid in pathF:
|
||||
# g = gridObjects[grid] # Get the grid-box object mentioned in the path
|
||||
# x = g.x
|
||||
# y = g.y
|
||||
# sx = g.sx
|
||||
# sy = g.sy
|
||||
# a = 0
|
||||
# pygame.draw.rect(SCREEN, GREEN, pygame.Rect(x, y, sx, sy))
|
||||
|
||||
if grid == 'rotate_right':
|
||||
player.rotation = (player.rotation - 90) % 360
|
||||
if grid == 'rotate_left':
|
||||
player.rotation = (player.rotation + 90) % 360
|
||||
|
||||
# (player.rotation)
|
||||
|
||||
if grid == 'move':
|
||||
if player.rotation == 0:
|
||||
if player.x < 9:
|
||||
player.x = player.x + 1
|
||||
if player.rotation == 180:
|
||||
if player.x > 0:
|
||||
player.x = player.x - 1
|
||||
if player.rotation == 270:
|
||||
if player.y < 9:
|
||||
player.y = player.y + 1
|
||||
if player.rotation == 90:
|
||||
if player.y > 0:
|
||||
player.y = player.y - 1
|
||||
|
||||
i = 0
|
||||
while i < len(T):
|
||||
j = 0
|
||||
while j < len(T[i]):
|
||||
# color = (255, 255, 255, 0)
|
||||
if T[i][j].isWet == 0:
|
||||
# a = 1
|
||||
color = (160, 80, 40, 0)
|
||||
else:
|
||||
# a = 1
|
||||
color = (50, 25, 0, 0)
|
||||
|
||||
# Covers 'player' on the way
|
||||
pygame.draw.rect(SCREEN, color, pygame.Rect(50 + 50 * i, 50 + 50 * j, 50, 50))
|
||||
if T[i][j].plantType == 1:
|
||||
SCREEN.blit(imgWheat, (50 + 50 * i, 50 + 50 * j))
|
||||
if T[i][j].plantType == 2:
|
||||
SCREEN.blit(imgCarrot, (50 + 50 * i, 50 + 50 * j))
|
||||
if T[i][j].plantType == 3:
|
||||
SCREEN.blit(imgCabbage, (50 + 50 * i, 50 + 50 * j))
|
||||
if T[i][j].plantType == 4:
|
||||
SCREEN.blit(imgTree, (50 + 50 * i, 50 + 50 * j))
|
||||
|
||||
j = j + 1
|
||||
i = i + 1
|
||||
|
||||
# Render the trees
|
||||
for obs in obstacleObjects:
|
||||
obstacleObjects[obs].draw()
|
||||
|
||||
for bx in boxObjects:
|
||||
boxObjects[bx].draw()
|
||||
|
||||
i = 0
|
||||
while i < len(T)+1:
|
||||
pygame.draw.line(SCREEN, (0, 0, 0), (50 + i * 50, 50), (50 + i * 50, 50 + len(T) * 50), 1)
|
||||
pygame.draw.line(SCREEN, (0, 0, 0), (50, 50 + i * 50), (50 + len(T) * 50, 50 + i * 50), 1)
|
||||
i = i + 1
|
||||
|
||||
tmpImg = pygame.transform.rotate(imgPlayer, player.rotation)
|
||||
if player.rotation == 180:
|
||||
tmpImg = pygame.transform.flip(tmpImg, True, True)
|
||||
tmpImg = pygame.transform.flip(tmpImg, True, False)
|
||||
|
||||
# player is seen on the way
|
||||
SCREEN.blit(tmpImg, (55 + 50 * player.x, 55 + 50 * player.y))
|
||||
|
||||
pygame.display.update()
|
||||
pygame.time.wait(300)
|
||||
SCREEN.fill(WHITE)
|
||||
# pygame.time.wait(50)
|
||||
# pygame.draw.rect(SCREEN, WHITE, pygame.Rect(x, y, sx, sy))
|
||||
Ucelu = True
|
||||
|
||||
|
||||
def UIHandler():
|
||||
# drawGrid(GRIDX, GRIDY)
|
||||
global Ucelu
|
||||
drawGrid(10, 10)
|
||||
|
||||
for grid in gridObjects:
|
||||
gridObjects[grid].draw()
|
||||
|
||||
for bx in boxObjects:
|
||||
boxObjects[bx].draw()
|
||||
|
||||
for obs in obstacleObjects:
|
||||
obstacleObjects[obs].draw()
|
||||
|
||||
if pathFound:
|
||||
drawGraph(pathFound)
|
||||
|
||||
|
||||
def eventHandler(kbdObj, mouseObj):
|
||||
global boxes
|
||||
global obstacles
|
||||
global startNode
|
||||
global goalNode
|
||||
global pathFound
|
||||
global Ucelu
|
||||
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit()
|
||||
|
||||
if event.type == pygame.KEYDOWN:
|
||||
pygame.time.wait(DELAY)
|
||||
if event.key == pygame.K_LEFT:
|
||||
if player.x > 0:
|
||||
player.x = player.x - 1
|
||||
player.rotation = 180
|
||||
|
||||
if event.key == pygame.K_UP:
|
||||
if player.y > 0:
|
||||
player.y = player.y - 1
|
||||
player.rotation = 90
|
||||
|
||||
if event.key == pygame.K_RIGHT:
|
||||
if player.x < 9:
|
||||
player.x = player.x + 1
|
||||
player.rotation = 0
|
||||
|
||||
if event.key == pygame.K_DOWN:
|
||||
if player.y < 9:
|
||||
player.y = player.y + 1
|
||||
player.rotation = 270
|
||||
|
||||
# Aga start lewo prawo, naprzód
|
||||
if event.key == pygame.K_a:
|
||||
player.rotation = (player.rotation + 90) % 360
|
||||
if event.key == pygame.K_d:
|
||||
player.rotation = (player.rotation - 90) % 360
|
||||
if event.key == pygame.K_w:
|
||||
if player.rotation == 0:
|
||||
if player.x < 9:
|
||||
player.x = player.x + 1
|
||||
if player.rotation == 180:
|
||||
if player.x > 0:
|
||||
player.x = player.x - 1
|
||||
if player.rotation == 270:
|
||||
if player.y < 9:
|
||||
player.y = player.y + 1
|
||||
if player.rotation == 90:
|
||||
if player.y > 0:
|
||||
player.y = player.y - 1
|
||||
|
||||
# If Key_f is pressed, set goal node
|
||||
if kbdObj[pygame.K_f]:
|
||||
gBox = getGridBoxes(int(len(gridObjects)))
|
||||
|
||||
sx = gBox.sx
|
||||
sy = gBox.sy
|
||||
|
||||
mseX = mouseObj[0]
|
||||
mseY = mouseObj[1]
|
||||
|
||||
for grid in gridObjects:
|
||||
g = getGridBoxes(grid)
|
||||
x = g.x
|
||||
y = g.y
|
||||
sx = g.sx
|
||||
sy = g.sy
|
||||
if x < mseX < x + sx:
|
||||
if y < mseY < y + sy:
|
||||
posX = x
|
||||
posY = y
|
||||
|
||||
bo = Box(posX, posY, sx, sy, BLUE)
|
||||
boxObjects[boxes] = bo
|
||||
boxes = 1
|
||||
|
||||
goalNode = [int(posX/50), int(posY/50)]
|
||||
|
||||
# drzewo decyzyjne:
|
||||
W = np.random.randint(2, size=(10, 10, 8))
|
||||
|
||||
# Wczytywanie modelu z pliku
|
||||
labels = ['Rain', 'Planted', 'Temperature', 'Sun', 'Snow', 'Moisture', 'Rotten', 'Time']
|
||||
loaded_model = joblib.load('decisionTree/decisionTree.sav')
|
||||
sample = W[goalNode[0]-1][goalNode[1]-1]
|
||||
|
||||
# Klasyfikacja przy użyciu wczytanego modelu
|
||||
predicted_class = loaded_model.predict([sample])
|
||||
print(labels)
|
||||
print(sample)
|
||||
print('Predicted class:', predicted_class)
|
||||
|
||||
# Decyzja dotycząca podlania grządek na podstawie przewidzianej etykiety
|
||||
if predicted_class == [1]:
|
||||
print('Podlej grządkę')
|
||||
else:
|
||||
print('Nie podlewaj grządki')
|
||||
|
||||
print('goalNode x = ', goalNode[0], 'goalNode y = ', goalNode[1])
|
||||
|
||||
# Delay to avoid multiple spawning of objects
|
||||
pygame.time.wait(DELAY)
|
||||
|
||||
if kbdObj[pygame.K_t]:
|
||||
w = random.randint(0, 1)
|
||||
f = random.randint(0, 1)
|
||||
print(w)
|
||||
print(f)
|
||||
img = generate(w, f, random.randint(0, 2))
|
||||
img.save('./test/00/test.png')
|
||||
|
||||
data_transform = transforms.Compose([
|
||||
transforms.Resize(size=(100, 100)),
|
||||
transforms.RandomHorizontalFlip(p=0.5),
|
||||
transforms.ToTensor(),
|
||||
Lambda(lambda x: x.flatten())
|
||||
])
|
||||
datasets.ImageNet
|
||||
train_data = datasets.ImageFolder(root="./test",
|
||||
transform=data_transform,
|
||||
target_transform=None)
|
||||
model1.eval()
|
||||
res = model1(train_data[0][0])
|
||||
if res[0] == res.max():
|
||||
print("0 0")
|
||||
if res[1] == res.max():
|
||||
print("0 1")
|
||||
if res[2] == res.max():
|
||||
print("1 0")
|
||||
if res[3] == res.max():
|
||||
print("1 1")
|
||||
# img.show()
|
||||
if kbdObj[pygame.K_x]:
|
||||
obs = Obstacle(mouseObj)
|
||||
obstacleObjects[obstacles] = obs
|
||||
# print(obs.gridBox)
|
||||
obstacles += 1
|
||||
# print(obstacleObjects)
|
||||
gridObstacle[obs.gridBox] = obstacles
|
||||
# Delay to avoid multiple spawning of objects
|
||||
|
||||
mseX = mouseObj[0]
|
||||
mseY = mouseObj[1]
|
||||
|
||||
for grid in gridObjects:
|
||||
g = getGridBoxes(grid)
|
||||
x = g.x
|
||||
y = g.y
|
||||
sx = g.sx
|
||||
sy = g.sy
|
||||
if x < mseX < x + sx:
|
||||
if y < mseY < y + sy:
|
||||
posX = x
|
||||
posY = y
|
||||
|
||||
T[int((posX/50)-1)][int((posY/50)-1)].plantType = 4
|
||||
|
||||
pygame.display.update()
|
||||
pygame.time.wait(DELAY)
|
||||
|
||||
# if Key_SPACE is pressed, start the magic
|
||||
if kbdObj[pygame.K_SPACE]:
|
||||
Ucelu = False
|
||||
|
||||
boxes = 1
|
||||
|
||||
startNode.x = player.x + 1
|
||||
startNode.y = player.y + 1
|
||||
|
||||
if player.rotation == 0:
|
||||
startNode.direction = 1
|
||||
elif player.rotation == 90:
|
||||
startNode.direction = 2
|
||||
elif player.rotation == 180:
|
||||
startNode.direction = 3
|
||||
elif player.rotation == 270:
|
||||
startNode.direction = 4
|
||||
|
||||
print('startNode x = ', startNode.x, 'startNode y = ', startNode.y, 'startNode direction = ', startNode.direction)
|
||||
|
||||
graph = generateGraph(GRIDY, GRIDX)
|
||||
print(graph)
|
||||
|
||||
if startNode.x != goalNode[0] or startNode.y != goalNode[1]:
|
||||
|
||||
move_list = (graphsearch(goalNode, startNode)) # przeszukiwanie grafu wszerz
|
||||
|
||||
pathFound = move_list
|
||||
|
||||
# pathFound = bfs.graphsearch()
|
||||
print('akcje które wykonuję by znalezc sie u celu')
|
||||
print(move_list)
|
||||
print('\n')
|
||||
# Delay to avoid multiple spawning of objects
|
||||
pygame.time.wait(DELAY)
|
||||
# startNode = goalNode
|
||||
|
||||
if kbdObj[pygame.K_b]:
|
||||
|
||||
Ucelu = False
|
||||
boxes = 1
|
||||
|
||||
startNode.x = player.x + 1
|
||||
startNode.y = player.y + 1
|
||||
|
||||
if player.rotation == 0:
|
||||
startNode.direction = 1
|
||||
elif player.rotation == 90:
|
||||
startNode.direction = 2
|
||||
elif player.rotation == 180:
|
||||
startNode.direction = 3
|
||||
elif player.rotation == 270:
|
||||
startNode.direction = 4
|
||||
|
||||
print('startNode x = ', startNode.x, 'startNode y = ', startNode.y, 'startNode direction = ', startNode.direction)
|
||||
|
||||
graph = generateGraph(GRIDY, GRIDX)
|
||||
print(graph)
|
||||
|
||||
if startNode.x != goalNode[0] or startNode.y != goalNode[1]:
|
||||
|
||||
move_list = (astar.graphsearch([], astar.f, [], goalNode, startNode, T, succ)) # przeszukiwanie grafu wszerz
|
||||
|
||||
pathFound = move_list
|
||||
|
||||
# pathFound = bfs.graphsearch()
|
||||
print('akcje które wykonuję by znalezc sie u celu')
|
||||
print(move_list)
|
||||
print('\n')
|
||||
|
||||
# Delay to avoid multiple spawning of objects
|
||||
pygame.time.wait(DELAY)
|
||||
|
||||
if kbdObj[pygame.K_g]:
|
||||
|
||||
global wheat_path
|
||||
|
||||
if not wheat_path:
|
||||
wheat = [(player.x+1, player.y+1), (4, 3), (6, 3), (7, 3), (9, 3), (10, 3), (5, 4), (5, 5), (6, 5), (10, 5), (3, 6), (4, 6), (6, 7), (7, 7), (8, 7)]
|
||||
wheat_path = genetic_algorithm(wheat, player)
|
||||
print("Best wheat path:", wheat_path)
|
||||
|
||||
if T[player.x][player.y].plantType != 0:
|
||||
T[player.x][player.y].plantType = 0
|
||||
|
||||
if len(wheat_path) > 1:
|
||||
|
||||
Ucelu = False
|
||||
boxes = 1
|
||||
|
||||
startNode.x = player.x + 1
|
||||
startNode.y = player.y + 1
|
||||
|
||||
if player.rotation == 0:
|
||||
startNode.direction = 1
|
||||
elif player.rotation == 90:
|
||||
startNode.direction = 2
|
||||
elif player.rotation == 180:
|
||||
startNode.direction = 3
|
||||
elif player.rotation == 270:
|
||||
startNode.direction = 4
|
||||
|
||||
generateGraph(GRIDY, GRIDX)
|
||||
|
||||
goalNode = [wheat_path[1][0], wheat_path[1][1]]
|
||||
|
||||
if startNode.x != goalNode[0] or startNode.y != goalNode[1]:
|
||||
|
||||
move_list = astar.graphsearch([], astar.f, [], goalNode, startNode, T, succ) # przeszukiwanie grafu wszerz
|
||||
pathFound = move_list
|
||||
|
||||
wheat_path.pop(0)
|
||||
|
||||
# Delay to avoid multiple spawning of objects
|
||||
pygame.time.wait(DELAY)
|
||||
|
||||
else:
|
||||
|
||||
print("All wheat collected!")
|
||||
|
||||
if kbdObj[pygame.K_h]:
|
||||
|
||||
global carrot_path
|
||||
|
||||
if not carrot_path:
|
||||
carrot = [(player.x+1, player.y+1), (3, 1), (9, 2), (1, 3), (5, 3), (4, 4), (6, 4), (7, 4), (8, 4), (3, 5), (9, 5), (6, 6), (10, 10)]
|
||||
carrot_path = genetic_algorithm(carrot, player)
|
||||
print("Best carrot path:", carrot_path)
|
||||
|
||||
if T[player.x][player.y].plantType != 0:
|
||||
T[player.x][player.y].plantType = 0
|
||||
|
||||
if len(carrot_path) > 1:
|
||||
|
||||
Ucelu = False
|
||||
boxes = 1
|
||||
|
||||
startNode.x = player.x + 1
|
||||
startNode.y = player.y + 1
|
||||
|
||||
if player.rotation == 0:
|
||||
startNode.direction = 1
|
||||
elif player.rotation == 90:
|
||||
startNode.direction = 2
|
||||
elif player.rotation == 180:
|
||||
startNode.direction = 3
|
||||
elif player.rotation == 270:
|
||||
startNode.direction = 4
|
||||
|
||||
generateGraph(GRIDY, GRIDX)
|
||||
|
||||
goalNode = [carrot_path[1][0], carrot_path[1][1]]
|
||||
|
||||
if startNode.x != goalNode[0] or startNode.y != goalNode[1]:
|
||||
|
||||
move_list = astar.graphsearch([], astar.f, [], goalNode, startNode, T, succ) # przeszukiwanie grafu wszerz
|
||||
pathFound = move_list
|
||||
|
||||
carrot_path.pop(0)
|
||||
|
||||
# Delay to avoid multiple spawning of objects
|
||||
pygame.time.wait(DELAY)
|
||||
|
||||
else:
|
||||
|
||||
print("All carrot collected!")
|
||||
|
||||
if kbdObj[pygame.K_j]:
|
||||
|
||||
global cabbage_path
|
||||
|
||||
if not cabbage_path:
|
||||
cabbage = [(player.x+1, player.y+1), (5, 1), (5, 2), (8, 3), (1, 4), (2, 4), (1, 5), (4, 5), (9, 6), (1, 8), (2, 8), (3, 8), (4, 8), (5, 8)]
|
||||
cabbage_path = genetic_algorithm(cabbage, player)
|
||||
print("Best cabbage path:", cabbage_path)
|
||||
|
||||
if T[player.x][player.y].plantType != 0:
|
||||
T[player.x][player.y].plantType = 0
|
||||
|
||||
if len(cabbage_path) > 1:
|
||||
|
||||
Ucelu = False
|
||||
boxes = 1
|
||||
|
||||
startNode.x = player.x + 1
|
||||
startNode.y = player.y + 1
|
||||
|
||||
if player.rotation == 0:
|
||||
startNode.direction = 1
|
||||
elif player.rotation == 90:
|
||||
startNode.direction = 2
|
||||
elif player.rotation == 180:
|
||||
startNode.direction = 3
|
||||
elif player.rotation == 270:
|
||||
startNode.direction = 4
|
||||
|
||||
generateGraph(GRIDY, GRIDX)
|
||||
|
||||
goalNode = [cabbage_path[1][0], cabbage_path[1][1]]
|
||||
|
||||
if startNode.x != goalNode[0] or startNode.y != goalNode[1]:
|
||||
|
||||
move_list = astar.graphsearch([], astar.f, [], goalNode, startNode, T, succ) # przeszukiwanie grafu wszerz
|
||||
pathFound = move_list
|
||||
|
||||
cabbage_path.pop(0)
|
||||
|
||||
# Delay to avoid multiple spawning of objects
|
||||
pygame.time.wait(DELAY)
|
||||
|
||||
else:
|
||||
|
||||
print("All cabbage collected!")
|
||||
|
||||
|
||||
T = [[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,2,1,0,0,0),Field(1,3,0,0,0,0),Field(0,3,0,0,0,0),Field(0,0,1,0,0,0),Field(0,0,0,0,0,0),Field(1,3,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,0,1,0,0,0),Field(1,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,3,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(0,2,1,0,0,0),Field(0,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,0,0,0,0),Field(0,2,1,0,0,0),Field(0,1,1,0,0,0),Field(0,0,0,0,0,0),Field(1,3,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,1,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,1,0,0,0,0),Field(0,0,0,0,0,0),Field(1,3,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,3,0,0,0,0),Field(0,3,1,0,0,0),Field(1,2,1,0,0,0),Field(1,1,1,0,0,0),Field(0,1,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,3,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,1,0,0,0,0),Field(0,2,0,0,0,0),Field(0,1,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,0,1,0,0,0),Field(0,0,1,0,0,0),Field(0,1,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,3,1,0,0,0),Field(1,2,1,0,0,0),Field(0,0,1,0,0,0),Field(0,0,0,0,0,0),Field(0,1,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,2,0,0,0,0),Field(1,1,0,0,0,0),Field(1,0,1,0,0,0),Field(0,2,1,0,0,0),Field(0,3,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,1,0,0,0),Field(0,0,0,0,0,0),Field(1,1,1,0,0,0),Field(1,0,0,0,0,0),Field(0,1,1,0,0,0),Field(0,0,1,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,2,1,0,0,0)]]
|
||||
|
||||
|
||||
# =========================================================================================
|
||||
# no i tutaj mamy główna pętlę programu
|
||||
T = [[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)]]
|
||||
|
||||
pygame.init()
|
||||
|
||||
player = Player()
|
||||
|
||||
screen = pygame.display.set_mode([600, 600])
|
||||
|
||||
running = True
|
||||
# clock = pygame.time.Clock()
|
||||
|
||||
SCREEN.fill(WHITE)
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
while running:
|
||||
|
||||
for event in pygame.event.get():
|
||||
kbd = pygame.key.get_pressed()
|
||||
mse = pygame.mouse.get_pos()
|
||||
UIHandler()
|
||||
eventHandler(kbd, mse)
|
||||
pygame.display.update()
|
||||
# CLOCK.tick(FPS)
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_LEFT:
|
||||
if player.x > 0:
|
||||
player.x = player.x - 1
|
||||
if event.key == pygame.K_UP:
|
||||
if player.y > 0:
|
||||
player.y = player.y - 1
|
||||
if event.key == pygame.K_RIGHT:
|
||||
if player.x < 9:
|
||||
player.x = player.x + 1
|
||||
if event.key == pygame.K_DOWN:
|
||||
if player.y < 9:
|
||||
player.y = player.y + 1
|
||||
|
||||
# screen.fill((175, 255, 50, 0))
|
||||
|
||||
# SCREEN.fill((WHITE))
|
||||
screen.fill((175, 255, 50))
|
||||
imgWheat = pygame.image.load('img/wheat.png')
|
||||
imgCarrot = pygame.image.load('img/carrot.png')
|
||||
imgCabbage = pygame.image.load('img/cabbage.png')
|
||||
imgPlayer = pygame.image.load('img/player.png')
|
||||
global imgTree
|
||||
imgTree = pygame.image.load('img/tree.png')
|
||||
# pygame.display.update()
|
||||
|
||||
i = 0
|
||||
while i < len(T):
|
||||
j = 0
|
||||
while j < len(T[i]):
|
||||
# color = (255, 255, 255, 0)
|
||||
color = (0, 0, 0)
|
||||
if T[i][j].isWet == 0:
|
||||
# a = 1
|
||||
color = (160, 80, 40, 0)
|
||||
color = (160, 80, 40)
|
||||
else:
|
||||
# a = 1
|
||||
color = (50, 25, 0, 0)
|
||||
# colour from the beginning
|
||||
pygame.draw.rect(SCREEN, color, pygame.Rect(50 + 50 * i, 50 + 50 * j, 50, 50))
|
||||
if T[i][j].plantType == 0:
|
||||
pygame.draw.rect(SCREEN, color, pygame.Rect(50 + 50 * i, 50 + 50 * j, 50, 50))
|
||||
color = (50, 25, 0)
|
||||
pygame.draw.rect(screen, color, pygame.Rect(50 + 50 * i, 50 + 50 * j, 50, 50))
|
||||
if T[i][j].plantType == 1:
|
||||
SCREEN.blit(imgWheat, (50 + 50 * i, 50 + 50 * j))
|
||||
screen.blit(imgWheat, (50 + 50 * i, 50 + 50 * j))
|
||||
if T[i][j].plantType == 2:
|
||||
SCREEN.blit(imgCarrot, (50 + 50 * i, 50 + 50 * j))
|
||||
screen.blit(imgCarrot, (50 + 50 * i, 50 + 50 * j))
|
||||
if T[i][j].plantType == 3:
|
||||
SCREEN.blit(imgCabbage, (50 + 50 * i, 50 + 50 * j))
|
||||
if T[i][j].plantType == 4:
|
||||
SCREEN.blit(imgTree, (50 + 50 * i, 50 + 50 * j))
|
||||
|
||||
screen.blit(imgCabbage, (50 + 50 * i, 50 + 50 * j))
|
||||
j = j + 1
|
||||
i = i + 1
|
||||
|
||||
font = pygame.font.SysFont('comicsans', 22)
|
||||
labelx = font.render('temp:22 |rain:none |snow:none |sun:cloudy |time:evening', True, (0, 0, 0))
|
||||
SCREEN.blit(labelx, (10, 10))
|
||||
|
||||
i = 0
|
||||
while i < len(T)+1:
|
||||
pygame.draw.line(SCREEN, (0, 0, 0), (50 + i * 50, 50), (50 + i * 50, 50 + len(T) * 50), 1)
|
||||
pygame.draw.line(SCREEN, (0, 0, 0), (50, 50 + i * 50), (50 + len(T) * 50, 50 + i * 50), 1)
|
||||
pygame.draw.line(screen, (0, 0, 0), (50 + i * 50, 50), (50 + i * 50, 50 + len(T) * 50), 5)
|
||||
pygame.draw.line(screen, (0, 0, 0), (50, 50 + i * 50), (50 + len(T) * 50, 50 + i * 50), 5)
|
||||
i = i + 1
|
||||
|
||||
for obs in obstacleObjects:
|
||||
obstacleObjects[obs].draw()
|
||||
|
||||
# if startNode.state != goalNode.state:
|
||||
if startNode.x != goalNode[0] or startNode.y != goalNode[1]:
|
||||
for bx in boxObjects:
|
||||
boxObjects[bx].draw()
|
||||
|
||||
tmpImg = pygame.transform.rotate(imgPlayer, player.rotation)
|
||||
if player.rotation == 180:
|
||||
tmpImg = pygame.transform.flip(tmpImg, True, True)
|
||||
tmpImg = pygame.transform.flip(tmpImg, True, False)
|
||||
|
||||
# player seen at the beginning
|
||||
SCREEN.blit(tmpImg, (55 + 50 * player.x, 55 + 50 * player.y))
|
||||
|
||||
|
||||
label = font.render('F - cel | X - drzewo', True, (0, 0, 0))
|
||||
label1 = font.render('ARROWS - ręczne poruszanie', True, (0, 0, 0))
|
||||
label2 = font.render('A - lewo | D - prawo | W - ruch', True, (0, 0, 0))
|
||||
label3 = font.render('SPACE - BFS | B - A*', True, (0, 0, 0))
|
||||
label4 = font.render('G - GA pszenica | H - GA marchewki | J - GA kapusty', True, (0, 0, 0))
|
||||
SCREEN.blit(label, (10, 555))
|
||||
SCREEN.blit(label1, (10, 580))
|
||||
SCREEN.blit(label2, (10, 605))
|
||||
SCREEN.blit(label3, (10, 630))
|
||||
SCREEN.blit(label4, (10, 655))
|
||||
|
||||
# pygame.display.flip()
|
||||
|
||||
pygame.display.update()
|
||||
CLOCK.tick(FPS)
|
||||
screen.blit(tmpImg, (55 + 50 * player.x, 55 + 50 * player.y))
|
||||
pygame.display.flip()
|
||||
# clock.tick(30)
|
||||
|
||||
# Done! Time to quit.
|
||||
|
||||
|
BIN
test/00/test.png
Before Width: | Height: | Size: 3.1 KiB |