Reorganising files:
- added AI dictionary with AI classes and functions - added src directory with raw data or simple classes - removed unused libraries
87
AI/decision_tree.py
Normal file
@ -0,0 +1,87 @@
|
||||
# used in Plant
|
||||
|
||||
def decision_tree(plant):
|
||||
if plant.field.hydration == 4:
|
||||
if plant.is_healthy == 1:
|
||||
if plant.field.tractor_there == 0:
|
||||
if plant.ticks == 0:
|
||||
return 0
|
||||
elif plant.ticks == 1:
|
||||
return 1
|
||||
elif plant.field.tractor_there == 1:
|
||||
return 0
|
||||
elif plant.is_healthy == 0:
|
||||
return 0
|
||||
elif plant.field.hydration == 2:
|
||||
if plant.species == "sorrel":
|
||||
if plant.ticks == 1:
|
||||
if plant.is_healthy == 1:
|
||||
return 1
|
||||
elif plant.is_healthy == 0:
|
||||
return 0
|
||||
elif plant.ticks == 0:
|
||||
return 0
|
||||
elif plant.species == "potato":
|
||||
return 0
|
||||
elif plant.species == "wheat":
|
||||
return 0
|
||||
elif plant.species == "strawberry":
|
||||
return 0
|
||||
elif plant.field.hydration == 1:
|
||||
if plant.species == "potato":
|
||||
return 0
|
||||
elif plant.species == "strawberry":
|
||||
if plant.ticks == 1:
|
||||
return -1
|
||||
elif plant.ticks == 0:
|
||||
return 0
|
||||
elif plant.species == "wheat":
|
||||
return 0
|
||||
elif plant.species == "sorrel":
|
||||
if plant.is_healthy == 0:
|
||||
return 0
|
||||
elif plant.is_healthy == 1:
|
||||
if plant.field.tractor_there == 0:
|
||||
if plant.ticks == 0:
|
||||
return 0
|
||||
elif plant.ticks == 1:
|
||||
return 1
|
||||
elif plant.field.tractor_there == 1:
|
||||
return 0
|
||||
elif plant.field.hydration == 3:
|
||||
if plant.ticks == 1:
|
||||
if plant.field.tractor_there == 0:
|
||||
if plant.is_healthy == 1:
|
||||
if plant.species == "potato":
|
||||
if plant.field.fertility == 1:
|
||||
return 1
|
||||
elif plant.field.fertility == 0:
|
||||
return 0
|
||||
elif plant.species == "strawberry":
|
||||
return 1
|
||||
elif plant.species == "sorrel":
|
||||
return 1
|
||||
elif plant.species == "wheat":
|
||||
return 1
|
||||
elif plant.is_healthy == 0:
|
||||
return 0
|
||||
elif plant.field.tractor_there == 1:
|
||||
return 0
|
||||
elif plant.ticks == 0:
|
||||
return 0
|
||||
elif plant.field.hydration == 5:
|
||||
if plant.field.tractor_there == 1:
|
||||
return 0
|
||||
elif plant.field.tractor_there == 0:
|
||||
if plant.is_healthy == 0:
|
||||
return 0
|
||||
elif plant.is_healthy == 1:
|
||||
if plant.ticks == 1:
|
||||
return 1
|
||||
elif plant.ticks == 0:
|
||||
return 0
|
||||
elif plant.field.hydration == 0:
|
||||
if plant.ticks == 0:
|
||||
return 0
|
||||
elif plant.ticks == 1:
|
||||
return -1
|
@ -1,16 +1,7 @@
|
||||
import torch
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
import torch.nn as nn
|
||||
import torch.nn.functional as f
|
||||
import torch.optim as optim
|
||||
import numpy as np
|
||||
from matplotlib.pyplot import imshow
|
||||
import os
|
||||
import PIL
|
||||
import numpy as np
|
||||
import neural_network
|
||||
from matplotlib.pyplot import imshow
|
||||
import torchvision.transforms as transforms
|
||||
|
||||
from AI import neural_network
|
||||
|
||||
# Create the model
|
||||
model = neural_network.Net()
|
||||
@ -22,10 +13,10 @@ neural_network.load_network_from_structure(model)
|
||||
transform = transforms.Compose([neural_network.Negative(), transforms.ToTensor()])
|
||||
|
||||
# load your image(s)
|
||||
img = PIL.Image.open('test\\0_100.jpg')
|
||||
img2 = PIL.Image.open('test\\1_100.jpg')
|
||||
img3 = PIL.Image.open('test\\4_100.jpg')
|
||||
img4 = PIL.Image.open('test\\5_100.jpg')
|
||||
img = PIL.Image.open('../src/test/0_100.jpg')
|
||||
img2 = PIL.Image.open('../src/test/1_100.jpg')
|
||||
img3 = PIL.Image.open('../src/test/4_100.jpg')
|
||||
img4 = PIL.Image.open('../src/test/5_100.jpg')
|
||||
|
||||
# Transform
|
||||
input = transform(img)
|
@ -1,15 +1,18 @@
|
||||
from cases import *
|
||||
from collections import Counter
|
||||
import operator
|
||||
from types import prepare_class
|
||||
import numpy as np
|
||||
import copy
|
||||
import operator
|
||||
from collections import Counter
|
||||
|
||||
import numpy as np
|
||||
|
||||
from src.cases import *
|
||||
|
||||
|
||||
class Node:
|
||||
def __init__(self, Class, tag=None):
|
||||
self.Class = Class
|
||||
self.childs = []
|
||||
|
||||
|
||||
def classes_of_cases(cases):
|
||||
classes = []
|
||||
for case in cases:
|
||||
@ -17,6 +20,7 @@ def classes_of_cases (cases):
|
||||
classes.append(case.Class)
|
||||
return classes
|
||||
|
||||
|
||||
def count_classes(cases):
|
||||
classes = []
|
||||
for case in cases:
|
||||
@ -24,6 +28,7 @@ def count_classes (cases):
|
||||
c = Counter(classes)
|
||||
return max(c.items(), key=operator.itemgetter(1))[0]
|
||||
|
||||
|
||||
def chose_attribute(cases, attributes):
|
||||
a = ""
|
||||
max = float("-inf")
|
||||
@ -33,6 +38,7 @@ def chose_attribute (cases, attributes):
|
||||
a = attribute
|
||||
return a
|
||||
|
||||
|
||||
def I(cases):
|
||||
i = 0
|
||||
all = len(cases)
|
||||
@ -45,6 +51,7 @@ def I (cases):
|
||||
i -= (noc / all) * np.log2(noc / all)
|
||||
return i
|
||||
|
||||
|
||||
def E(cases, attribute):
|
||||
e = 0
|
||||
values = []
|
||||
@ -95,6 +102,7 @@ def treelearn(cases, attributes, default_class):
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def pretty_print(root, n):
|
||||
if len(root.childs) == 0:
|
||||
for _ in range(n):
|
||||
@ -114,9 +122,3 @@ def pretty_print(root, n):
|
||||
|
||||
tree = treelearn(cases, attributes, 0)
|
||||
pretty_print(tree, 0)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,20 +1,18 @@
|
||||
import torch
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
import torch.nn as nn
|
||||
import torch.nn.functional as f
|
||||
import torch.optim as optim
|
||||
import numpy as np
|
||||
from matplotlib.pyplot import imshow
|
||||
import os
|
||||
import PIL
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import torch.optim as optim
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
from matplotlib.pyplot import imshow
|
||||
|
||||
|
||||
def to_negative(img):
|
||||
img = PIL.ImageOps.invert(img)
|
||||
return img
|
||||
|
||||
|
||||
class Negative(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
@ -22,10 +20,12 @@ class Negative(object):
|
||||
def __call__(self, img):
|
||||
return to_negative(img)
|
||||
|
||||
|
||||
def plotdigit(image):
|
||||
img = np.reshape(image, (-1, 100))
|
||||
imshow(img, cmap='Greys')
|
||||
|
||||
|
||||
transform = transforms.Compose([Negative(), transforms.ToTensor()])
|
||||
train_set = torchvision.datasets.ImageFolder(root='train', transform=transform)
|
||||
classes = ("apple", "potato")
|
||||
@ -35,6 +35,7 @@ train_loader = torch.utils.data.DataLoader(train_set, batch_size=BATCH_SIZE, shu
|
||||
|
||||
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
||||
|
||||
|
||||
class Net(nn.Module):
|
||||
def __init__(self):
|
||||
super(Net, self).__init__()
|
||||
@ -54,6 +55,7 @@ class Net(nn.Module):
|
||||
logits = self.linear_relu_stack(x).to(device)
|
||||
return logits
|
||||
|
||||
|
||||
def training_network():
|
||||
net = Net()
|
||||
net = net.to(device)
|
||||
@ -100,4 +102,3 @@ def load_network_from_structure(network):
|
||||
if __name__ == "__main__":
|
||||
print(torch.cuda.is_available())
|
||||
training_network()
|
||||
|
156
basic_grid.py
@ -1,156 +0,0 @@
|
||||
# Import the pygame module
|
||||
import pygame
|
||||
|
||||
# Import pygame.locals for easier access to key coordinates
|
||||
from pygame.locals import (
|
||||
K_UP,
|
||||
K_LEFT,
|
||||
K_RIGHT,
|
||||
K_ESCAPE,
|
||||
KEYDOWN,
|
||||
QUIT
|
||||
)
|
||||
|
||||
# Import other files from project
|
||||
import field as F
|
||||
import tractor as T
|
||||
import plant as P
|
||||
import colors as C
|
||||
import dimensions as D
|
||||
import node as N
|
||||
import mapschema as maps
|
||||
|
||||
# Initialize pygame
|
||||
pygame.init()
|
||||
|
||||
# Name the window
|
||||
pygame.display.set_caption("Inteligentny Traktor")
|
||||
|
||||
# Create the screen object
|
||||
# The size is determined by the constant SCREEN_WIDTH and SCREEN_HEIGHT
|
||||
screen = pygame.display.set_mode((D.SCREEN_WIDTH, D.SCREEN_HEIGHT))
|
||||
|
||||
# Define the map of the field
|
||||
mapschema = maps.createField()
|
||||
|
||||
# Create field array
|
||||
field = []
|
||||
|
||||
# Populate the field array
|
||||
for row in range(D.GSIZE):
|
||||
field.append([])
|
||||
for column in range(D.GSIZE):
|
||||
fieldbit = F.Field(row, column, mapschema[column][row])
|
||||
field[row].append(fieldbit)
|
||||
|
||||
# Create Tractor object
|
||||
tractor = T.Tractor(field, [0,0])
|
||||
|
||||
# Define the map of plants
|
||||
mapschema = maps.createPlants()
|
||||
|
||||
# Createt plants array
|
||||
plants = []
|
||||
|
||||
# Populate the plants array
|
||||
for row in range(D.GSIZE):
|
||||
plants.append([])
|
||||
for column in range(D.GSIZE):
|
||||
if mapschema[column][row] != 0:
|
||||
plantbit = P.Plant(field[row][column], mapschema[column][row])
|
||||
plants[row].append(plantbit)
|
||||
|
||||
# Create list for tractor instructions
|
||||
path = []
|
||||
|
||||
# Variable to keep the main loop running
|
||||
RUNNING = True
|
||||
|
||||
# Variable conroling timed eventes
|
||||
TICKER = 0
|
||||
|
||||
# Initialize clock
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
|
||||
# Main loop
|
||||
while RUNNING:
|
||||
|
||||
# Look at every event in the queue
|
||||
for event in pygame.event.get():
|
||||
# Did the user hit a key?
|
||||
if event.type == KEYDOWN:
|
||||
# Was it the Escape key? If so, stop the loop.
|
||||
if event.key == K_ESCAPE:
|
||||
RUNNING = False
|
||||
# Did the user click the window close button? If so, stop the loop.
|
||||
elif event.type == QUIT:
|
||||
RUNNING = False
|
||||
|
||||
# Create key Node that will be used to calculate tractor instructions
|
||||
processor = N.Node(field, tractor.position, tractor.direction)
|
||||
|
||||
# If path is empty or nonexistent, create new one
|
||||
if path is None or len(path) == 0:
|
||||
path = processor.findPathToPlant()
|
||||
|
||||
# control tractor by poping instructions from path list
|
||||
if path is not None:
|
||||
if path[0] == "move":
|
||||
tractor.move()
|
||||
path.pop(0)
|
||||
elif path[0] =="left":
|
||||
tractor.rotate_left()
|
||||
path.pop(0)
|
||||
elif path[0] == "right":
|
||||
tractor.rotate_right()
|
||||
path.pop(0)
|
||||
elif path[0] == "hydrate":
|
||||
tractor.hydrate(field)
|
||||
path.pop(0)
|
||||
else:
|
||||
path.pop(0)
|
||||
|
||||
# Get all keys pressed at a time CURRENTLY UNUSED
|
||||
pressed_keys = pygame.key.get_pressed()
|
||||
|
||||
# control tractor with pressed keys CURRENTLY UNUSED
|
||||
if pressed_keys[K_UP]:
|
||||
tractor.move()
|
||||
elif pressed_keys[K_LEFT]:
|
||||
tractor.rotate_left()
|
||||
elif pressed_keys[K_RIGHT]:
|
||||
tractor.rotate_right()
|
||||
|
||||
# Set the screen background
|
||||
screen.fill(C.DBROWN)
|
||||
|
||||
# Draw the field
|
||||
for row in range(D.GSIZE):
|
||||
for column in range(D.GSIZE):
|
||||
screen.blit(field[row][column].surf, field[row][column].rect)
|
||||
|
||||
# Draw the tactor
|
||||
screen.blit(tractor.surf, tractor.rect)
|
||||
|
||||
# Plants grow with every 10th tick, then they are drawn
|
||||
for row in plants:
|
||||
for plant in row:
|
||||
plant.tick()
|
||||
plant.grow()
|
||||
screen.blit(plant.surf, plant.rect)
|
||||
|
||||
# Field are drying with every 100th tick
|
||||
if TICKER == 0:
|
||||
for row in range(D.GSIZE):
|
||||
for column in range(D.GSIZE):
|
||||
field[row][column].dehydrate()
|
||||
|
||||
# Increment ticker
|
||||
TICKER = (TICKER + 1)%100
|
||||
|
||||
# Update the screen
|
||||
pygame.display.flip()
|
||||
|
||||
# Ensure program maintains a stable framerate
|
||||
clock.tick(8)
|
259
cases.py
@ -1,259 +0,0 @@
|
||||
class Case:
|
||||
def __init__(self, values, attributes, Class):
|
||||
self.values = values
|
||||
self.attributes = attributes
|
||||
self.Class = Class
|
||||
|
||||
attributes = ["field.hydration", "field.fertility", "species", "ticks", "is_healthy", "field.tractor_there"]
|
||||
|
||||
cases = [Case([4, 0, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([2, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([4, 1, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([2, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([2, 0, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([1, 1, "strawberry", 1, 0, 1], attributes, -1),
|
||||
Case([1, 0, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([2, 0, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([1, 1, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 1, "potato", 1, 1, 0], attributes, 1),
|
||||
Case([2, 1, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([4, 0, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([4, 1, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([4, 0, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([1, 1, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([0, 0, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([2, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([0, 1, "sorrel", 0, 1, 1], attributes, 0),
|
||||
Case([0, 1, "strawberry", 1, 1, 0], attributes, -1),
|
||||
Case([2, 0, "sorrel", 0, 1, 1], attributes, 0),
|
||||
Case([4, 0, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([5, 0, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 0, 0], attributes, -1),
|
||||
Case([4, 0, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([3, 0, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([3, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([4, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([2, 0, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([4, 1, "strawberry", 0, 0, 1], attributes, 0),
|
||||
Case([1, 0, "potato", 1, 1, 0], attributes, 0),
|
||||
Case([4, 1, "sorrel", 1, 1, 1], attributes, 0),
|
||||
Case([0, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([4, 0, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([4, 0, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([5, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 1, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([3, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([4, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([5, 1, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([3, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([0, 0, "potato", 1, 1, 1], attributes, -1),
|
||||
Case([4, 0, "strawberry", 1, 1, 1], attributes, 0),
|
||||
Case([2, 1, "strawberry", 1, 0, 1], attributes, 0),
|
||||
Case([2, 1, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([2, 1, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([1, 0, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([4, 0, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([4, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 0, 1], attributes, -1),
|
||||
Case([0, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([1, 1, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([0, 0, "sorrel", 1, 1, 0], attributes, -1),
|
||||
Case([2, 0, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([5, 1, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([2, 0, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([2, 1, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([3, 0, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([5, 0, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([0, 1, "strawberry", 1, 0, 0], attributes, -1),
|
||||
Case([0, 0, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([5, 0, "potato", 1, 1, 0], attributes, 1),
|
||||
Case([2, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 1, "sorrel", 0, 1, 0], attributes, 0),
|
||||
Case([2, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([5, 0, "strawberry", 1, 1, 0], attributes, 1),
|
||||
Case([5, 0, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([5, 0, "wheat", 1, 1, 0], attributes, 1),
|
||||
Case([2, 0, "potato", 1, 0, 0], attributes, 0),
|
||||
Case([3, 1, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([3, 0, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 1, 1], attributes, -1),
|
||||
Case([0, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([2, 1, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 1, 0], attributes, -1),
|
||||
Case([3, 0, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([4, 0, "strawberry", 1, 0, 1], attributes, 0),
|
||||
Case([3, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([5, 1, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([5, 0, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([3, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([1, 0, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([5, 0, "sorrel", 0, 1, 1], attributes, 0),
|
||||
Case([4, 0, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([0, 0, "strawberry", 0, 0, 0], attributes, 0),
|
||||
Case([5, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([4, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([1, 1, "strawberry", 1, 1, 0], attributes, -1),
|
||||
Case([5, 0, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([5, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 1, 0], attributes, -1),
|
||||
Case([3, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([1, 0, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([3, 0, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([0, 0, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([1, 0, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([1, 1, "sorrel", 0, 1, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([2, 0, "strawberry", 1, 1, 1], attributes, 0),
|
||||
Case([4, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 1, 0], attributes, -1),
|
||||
Case([1, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([4, 0, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([4, 0, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([0, 0, "sorrel", 1, 0, 1], attributes, -1),
|
||||
Case([1, 0, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([2, 1, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([3, 1, "strawberry", 1, 1, 0], attributes, 1),
|
||||
Case([1, 0, "sorrel", 1, 1, 1], attributes, 0),
|
||||
Case([5, 1, "strawberry", 1, 1, 0], attributes, 1),
|
||||
Case([2, 0, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([5, 1, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([1, 1, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([1, 1, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([4, 0, "potato", 1, 1, 0], attributes, 1),
|
||||
Case([2, 1, "strawberry", 0, 0, 1], attributes, 0),
|
||||
Case([0, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([3, 0, "sorrel", 1, 0, 1], attributes, 0),
|
||||
Case([4, 0, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([5, 1, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([1, 0, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([5, 0, "sorrel", 1, 0, 1], attributes, 0),
|
||||
Case([2, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([1, 0, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([4, 0, "wheat", 1, 1, 0], attributes, 1),
|
||||
Case([0, 0, "sorrel", 0, 1, 0], attributes, 0),
|
||||
Case([2, 0, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([0, 1, "potato", 1, 0, 1], attributes, -1),
|
||||
Case([0, 1, "sorrel", 1, 0, 1], attributes, -1),
|
||||
Case([1, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([3, 0, "sorrel", 1, 1, 1], attributes, 0),
|
||||
Case([0, 0, "potato", 1, 0, 1], attributes, -1),
|
||||
Case([4, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 0, 0], attributes, -1),
|
||||
Case([0, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([5, 0, "potato", 0, 1, 1], attributes, 0),
|
||||
Case([2, 0, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "potato", 1, 0, 0], attributes, -1),
|
||||
Case([1, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([4, 0, "sorrel", 1, 0, 1], attributes, 0),
|
||||
Case([1, 0, "potato", 1, 0, 0], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([2, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([0, 1, "potato", 1, 1, 1], attributes, -1),
|
||||
Case([5, 1, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([3, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 0, 0, 1], attributes, 0),
|
||||
Case([0, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 1, 0, 0], attributes, -1),
|
||||
Case([1, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 1, 0, 1], attributes, -1),
|
||||
Case([1, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([0, 0, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([4, 1, "sorrel", 1, 1, 1], attributes, 0),
|
||||
Case([5, 1, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([5, 1, "strawberry", 0, 0, 0], attributes, 0),
|
||||
Case([4, 1, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([1, 1, "potato", 1, 1, 0], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 0, 0], attributes, -1),
|
||||
Case([5, 0, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([0, 0, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([4, 0, "strawberry", 0, 0, 1], attributes, 0),
|
||||
Case([2, 0, "potato", 1, 0, 0], attributes, 0),
|
||||
Case([4, 0, "strawberry", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([1, 1, "wheat", 1, 1, 0], attributes, 0),
|
||||
Case([3, 0, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([1, 1, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([1, 1, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([3, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([3, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([1, 0, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([5, 0, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([2, 1, "sorrel", 0, 1, 0], attributes, 0),
|
||||
Case([5, 0, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([1, 0, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([5, 1, "wheat", 1, 1, 0], attributes, 1),
|
||||
Case([3, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([5, 0, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([2, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([1, 0, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([0, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 1, 0], attributes, 1),
|
||||
Case([2, 0, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([3, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "potato", 1, 1, 0], attributes, 0),
|
||||
Case([1, 1, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([2, 1, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([2, 1, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([2, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([3, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([2, 0, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([5, 0, "wheat", 1, 1, 0], attributes, 1),
|
||||
Case([1, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([5, 1, "strawberry", 1, 1, 1], attributes, 0),
|
||||
Case([4, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([5, 1, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([5, 0, "strawberry", 1, 0, 1], attributes, 0),
|
||||
Case([5, 0, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([2, 0, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([3, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 1, 0, 0], attributes, -1),
|
||||
Case([0, 1, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([4, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([3, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([2, 1, "strawberry", 1, 1, 0], attributes, 0),
|
||||
Case([1, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([4, 1, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([2, 0, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([5, 0, "sorrel", 0, 1, 1], attributes, 0),
|
||||
Case([0, 1, "wheat", 1, 1, 0], attributes, -1),
|
||||
Case([5, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([2, 0, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([2, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([4, 1, "potato", 0, 1, 1], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 1, 0], attributes, -1),
|
||||
Case([1, 1, "strawberry", 1, 0, 1], attributes, -1),
|
||||
Case([3, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([5, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([4, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([2, 1, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([0, 1, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([5, 0, "potato", 1, 1, 0], attributes, 1),
|
||||
Case([3, 1, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([5, 1, "strawberry", 0, 0, 0], attributes, 0),
|
||||
Case([4, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([0, 0, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([1, 1, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([0, 1, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([4, 1, "strawberry", 1, 1, 1], attributes, 0),
|
||||
Case([0, 0, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "wheat", 1, 1, 0], attributes, 1)]
|
32
field.py
@ -1,6 +1,8 @@
|
||||
import pygame
|
||||
from colors import *
|
||||
from dimensions import *
|
||||
|
||||
from src.colors import *
|
||||
from src.dimensions import *
|
||||
|
||||
|
||||
class Field(pygame.sprite.Sprite):
|
||||
def __init__(self, row, column, field_type):
|
||||
@ -30,30 +32,16 @@ class Field(pygame.sprite.Sprite):
|
||||
def hydrate(self):
|
||||
if self.field_type == "soil" and self.hydration <= 5:
|
||||
self.hydration += 1
|
||||
if self.hydration == 0:
|
||||
self.surf.fill(BROWN0)
|
||||
if self.hydration == 1:
|
||||
self.surf.fill(BROWN1)
|
||||
if self.hydration == 2:
|
||||
self.surf.fill(BROWN2)
|
||||
if self.hydration == 3:
|
||||
self.surf.fill(BROWN3)
|
||||
if self.hydration == 4 or self.hydration == 5:
|
||||
self.surf.fill(BROWN4)
|
||||
|
||||
# color field to it's hydration value
|
||||
self.surf.fill(eval('BROWN' + str(self.hydration)))
|
||||
|
||||
def dehydrate(self):
|
||||
if self.field_type == "soil" and self.hydration > 0:
|
||||
self.hydration -= 1
|
||||
if self.hydration == 0:
|
||||
self.surf.fill(BROWN0)
|
||||
if self.hydration == 1:
|
||||
self.surf.fill(BROWN1)
|
||||
if self.hydration == 2:
|
||||
self.surf.fill(BROWN2)
|
||||
if self.hydration == 3:
|
||||
self.surf.fill(BROWN3)
|
||||
if self.hydration == 4 or self.hydration == 5:
|
||||
self.surf.fill(BROWN4)
|
||||
|
||||
# color field to it's hydration value
|
||||
self.surf.fill(eval('BROWN' + str(self.hydration)))
|
||||
|
||||
def free(self):
|
||||
self.planted = 0
|
||||
|
151
main.py
Normal file
@ -0,0 +1,151 @@
|
||||
# Import the pygame module
|
||||
import pygame
|
||||
# Import pygame.locals for easier access to key coordinates
|
||||
from pygame.locals import (
|
||||
K_UP,
|
||||
K_LEFT,
|
||||
K_RIGHT,
|
||||
K_ESCAPE,
|
||||
KEYDOWN,
|
||||
QUIT
|
||||
)
|
||||
|
||||
# Import other files from project
|
||||
import field as F
|
||||
import node as N
|
||||
import plant as P
|
||||
import src.colors as C
|
||||
import src.dimensions as D
|
||||
import tractor as T
|
||||
from src import mapschema as maps
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Initialize pygame
|
||||
pygame.init()
|
||||
|
||||
# Name the window
|
||||
pygame.display.set_caption("Inteligentny Traktor")
|
||||
|
||||
# Create the screen object
|
||||
# The size is determined by the constant SCREEN_WIDTH and SCREEN_HEIGHT
|
||||
screen = pygame.display.set_mode((D.SCREEN_WIDTH, D.SCREEN_HEIGHT))
|
||||
|
||||
# Define the map of the field
|
||||
mapschema = maps.createField()
|
||||
|
||||
# Create field array
|
||||
field = []
|
||||
|
||||
# Populate the field array
|
||||
for row in range(D.GSIZE):
|
||||
field.append([])
|
||||
for column in range(D.GSIZE):
|
||||
fieldbit = F.Field(row, column, mapschema[column][row])
|
||||
field[row].append(fieldbit)
|
||||
|
||||
# Create Tractor object
|
||||
tractor = T.Tractor(field, [0, 0])
|
||||
|
||||
# Define the map of plants
|
||||
mapschema = maps.createPlants()
|
||||
|
||||
# Createt plants array
|
||||
plants = []
|
||||
|
||||
# Populate the plants array
|
||||
for row in range(D.GSIZE):
|
||||
plants.append([])
|
||||
for column in range(D.GSIZE):
|
||||
if mapschema[column][row] != 0:
|
||||
plantbit = P.Plant(field[row][column], mapschema[column][row])
|
||||
plants[row].append(plantbit)
|
||||
|
||||
# Create list for tractor instructions
|
||||
path = []
|
||||
|
||||
# Variable to keep the main loop running
|
||||
RUNNING = True
|
||||
|
||||
# Variable conroling timed eventes
|
||||
TICKER = 0
|
||||
|
||||
# Initialize clock
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
# Main loop
|
||||
while RUNNING:
|
||||
|
||||
# Look at every event in the queue
|
||||
for event in pygame.event.get():
|
||||
# Did the user hit a key?
|
||||
if event.type == KEYDOWN:
|
||||
# Was it the Escape key? If so, stop the loop.
|
||||
if event.key == K_ESCAPE:
|
||||
RUNNING = False
|
||||
# Did the user click the window close button? If so, stop the loop.
|
||||
elif event.type == QUIT:
|
||||
RUNNING = False
|
||||
|
||||
# Create key Node that will be used to calculate tractor instructions
|
||||
processor = N.Node(field, tractor.position, tractor.direction)
|
||||
|
||||
# If path is empty or nonexistent, create new one
|
||||
if path is None or len(path) == 0:
|
||||
path = processor.findPathToPlant()
|
||||
|
||||
# control tractor by poping instructions from path list
|
||||
if path is not None:
|
||||
if path[0] == "move":
|
||||
tractor.move()
|
||||
elif path[0] == "left":
|
||||
tractor.rotate_left()
|
||||
elif path[0] == "right":
|
||||
tractor.rotate_right()
|
||||
elif path[0] == "hydrate":
|
||||
tractor.hydrate(field)
|
||||
|
||||
path.pop(0)
|
||||
|
||||
# Get all keys pressed at a time CURRENTLY UNUSED
|
||||
pressed_keys = pygame.key.get_pressed()
|
||||
|
||||
# control tractor with pressed keys CURRENTLY UNUSED
|
||||
if pressed_keys[K_UP]:
|
||||
tractor.move()
|
||||
elif pressed_keys[K_LEFT]:
|
||||
tractor.rotate_left()
|
||||
elif pressed_keys[K_RIGHT]:
|
||||
tractor.rotate_right()
|
||||
|
||||
# Set the screen background
|
||||
screen.fill(C.DBROWN)
|
||||
|
||||
# Draw the field
|
||||
for row in range(D.GSIZE):
|
||||
for column in range(D.GSIZE):
|
||||
screen.blit(field[row][column].surf, field[row][column].rect)
|
||||
|
||||
# Draw the tactor
|
||||
screen.blit(tractor.surf, tractor.rect)
|
||||
|
||||
# Plants grow with every 10th tick, then they are drawn
|
||||
for row in plants:
|
||||
for plant in row:
|
||||
plant.tick()
|
||||
plant.grow()
|
||||
screen.blit(plant.surf, plant.rect)
|
||||
|
||||
# Field are drying with every 100th tick
|
||||
if TICKER == 0:
|
||||
for row in range(D.GSIZE):
|
||||
for column in range(D.GSIZE):
|
||||
field[row][column].dehydrate()
|
||||
|
||||
# Increment ticker
|
||||
TICKER = (TICKER + 1) % 100
|
||||
|
||||
# Update the screen
|
||||
pygame.display.flip()
|
||||
|
||||
# Ensure program maintains a stable framerate
|
||||
clock.tick(8)
|
27
mapschema.py
@ -1,27 +0,0 @@
|
||||
def createField():
|
||||
field = [["soil", "soil", "soil", "soil", "soil", "soil", "rocks", "soil", "soil", "soil"],
|
||||
["soil", "soil", "soil", "soil", "soil", "soil", "rocks", "soil", "soil", "soil"],
|
||||
["soil", "soil", "soil", "soil", "soil", "road", "road", "road", "road", "road"],
|
||||
["rocks", "rocks", "rocks", "rocks", "soil", "road", "soil", "soil", "rocks", "soil"],
|
||||
["soil", "soil", "soil", "soil", "soil", "road", "rocks", "rocks", "soil", "soil"],
|
||||
["soil", "soil", "soil", "pond", "rocks", "road", "rocks", "soil", "soil", "rocks"],
|
||||
["rocks", "pond", "pond", "pond", "pond", "road", "rocks", "soil", "soil", "rocks"],
|
||||
["road", "road", "road", "road", "road", "road", "rocks", "soil", "soil", "soil"],
|
||||
["soil", "soil", "soil", "soil", "soil", "soil", "rocks", "soil", "rocks", "rocks"],
|
||||
["soil", "soil", "soil", "soil", "soil", "rocks", "soil", "rocks", "rocks", "soil"]
|
||||
]
|
||||
return field
|
||||
|
||||
def createPlants():
|
||||
field = [["wheat", "wheat", "wheat", "wheat", "wheat", "wheat", 0, "strawberry", "strawberry", "strawberry"],
|
||||
["wheat", "wheat", "wheat", "wheat", "wheat", "wheat", 0, "strawberry", "strawberry", "strawberry"],
|
||||
["wheat", "wheat", "wheat", "wheat", 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
["wheat", "wheat", "wheat", "wheat", 0, 0, 0, 0, 0, 0],
|
||||
["wheat", "wheat", "wheat", 0, 0, 0, 0, "potato", "potato", 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, "potato", "potato", 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, "potato", "potato", "potato"],
|
||||
["strawberry", "strawberry", "strawberry", "strawberry", "strawberry", 0, 0, "potato", 0, 0],
|
||||
["strawberry", "strawberry", "strawberry", "strawberry", "strawberry", 0, 0, 0, 0, 0]
|
||||
]
|
||||
return field
|
19
node.py
@ -1,10 +1,12 @@
|
||||
from dimensions import *
|
||||
import heapq
|
||||
|
||||
from src.dimensions import *
|
||||
|
||||
|
||||
def getTotalCost(x):
|
||||
return x.totalCost
|
||||
|
||||
|
||||
def showPath(node, goal):
|
||||
path = node.findPath(goal)
|
||||
for x in path:
|
||||
@ -16,8 +18,10 @@ def showPath(node, goal):
|
||||
|
||||
def succesor(node):
|
||||
succesors = []
|
||||
if node.position[0]+node.rotation[0] in range(0,GSIZE) and node.position[1]+node.rotation[1] in range(0,GSIZE):
|
||||
child = Node(node.field, [node.position[0]+node.rotation[0], node.position[1]+node.rotation[1]], node.rotation)
|
||||
if node.position[0] + node.rotation[0] in range(0, GSIZE) and node.position[1] + node.rotation[1] in range(0,
|
||||
GSIZE):
|
||||
child = Node(node.field, [node.position[0] + node.rotation[0], node.position[1] + node.rotation[1]],
|
||||
node.rotation)
|
||||
child.action = "move"
|
||||
succesors.append(child)
|
||||
if node.rotation == [1, 0]:
|
||||
@ -50,7 +54,8 @@ def succesor (node):
|
||||
succesors.append(child)
|
||||
return succesors
|
||||
|
||||
class Node():
|
||||
|
||||
class Node:
|
||||
def __init__(self, field, position, rotation):
|
||||
self.parent = 0
|
||||
self.startCost = 0
|
||||
@ -131,7 +136,8 @@ class Node():
|
||||
|
||||
closedList.append(currentNode)
|
||||
|
||||
if currentNode.field[currentNode.position[0]][currentNode.position[1]].planted and currentNode.field[currentNode.position[0]][currentNode.position[1]].hydration < 2:
|
||||
if currentNode.field[currentNode.position[0]][currentNode.position[1]].planted and \
|
||||
currentNode.field[currentNode.position[0]][currentNode.position[1]].hydration < 2:
|
||||
path = []
|
||||
for _ in range(currentNode.field[currentNode.position[0]][currentNode.position[1]].hydration, 4):
|
||||
path.append("hydrate")
|
||||
@ -154,7 +160,8 @@ class Node():
|
||||
continue
|
||||
child.parent = currentNode
|
||||
child.startCost = currentNode.startCost + child.field[child.position[0]][child.position[1]].moveCost
|
||||
child.heuristic = abs(startNode.position[0]-child.position[0]) + abs(startNode.position[1]-child.position[1])
|
||||
child.heuristic = abs(startNode.position[0] - child.position[0]) + abs(
|
||||
startNode.position[1] - child.position[1])
|
||||
child.totalCost = child.startCost + child.heuristic
|
||||
|
||||
for openNode in openList:
|
||||
|
93
plant.py
@ -1,7 +1,7 @@
|
||||
import pygame
|
||||
from colors import *
|
||||
from dimensions import *
|
||||
from sprites import *
|
||||
from AI.decision_tree import *
|
||||
from src.dimensions import *
|
||||
from src.sprites import *
|
||||
|
||||
|
||||
class Plant(pygame.sprite.Sprite):
|
||||
def __init__(self, field, species):
|
||||
@ -40,90 +40,7 @@ class Plant(pygame.sprite.Sprite):
|
||||
self.ticks = 0
|
||||
|
||||
def dtree(self):
|
||||
if self.field.hydration == 4:
|
||||
if self.is_healthy == 1:
|
||||
if self.field.tractor_there == 0:
|
||||
if self.ticks == 0:
|
||||
return 0
|
||||
elif self.ticks == 1:
|
||||
return 1
|
||||
elif self.field.tractor_there == 1:
|
||||
return 0
|
||||
elif self.is_healthy == 0:
|
||||
return 0
|
||||
elif self.field.hydration == 2:
|
||||
if self.species == "sorrel":
|
||||
if self.ticks == 1:
|
||||
if self.is_healthy == 1:
|
||||
return 1
|
||||
elif self.is_healthy == 0:
|
||||
return 0
|
||||
elif self.ticks == 0:
|
||||
return 0
|
||||
elif self.species == "potato":
|
||||
return 0
|
||||
elif self.species == "wheat":
|
||||
return 0
|
||||
elif self.species == "strawberry":
|
||||
return 0
|
||||
elif self.field.hydration == 1:
|
||||
if self.species == "potato":
|
||||
return 0
|
||||
elif self.species == "strawberry":
|
||||
if self.ticks == 1:
|
||||
return -1
|
||||
elif self.ticks == 0:
|
||||
return 0
|
||||
elif self.species == "wheat":
|
||||
return 0
|
||||
elif self.species == "sorrel":
|
||||
if self.is_healthy == 0:
|
||||
return 0
|
||||
elif self.is_healthy == 1:
|
||||
if self.field.tractor_there == 0:
|
||||
if self.ticks == 0:
|
||||
return 0
|
||||
elif self.ticks == 1:
|
||||
return 1
|
||||
elif self.field.tractor_there == 1:
|
||||
return 0
|
||||
elif self.field.hydration == 3:
|
||||
if self.ticks == 1:
|
||||
if self.field.tractor_there == 0:
|
||||
if self.is_healthy == 1:
|
||||
if self.species == "potato":
|
||||
if self.field.fertility == 1:
|
||||
return 1
|
||||
elif self.field.fertility == 0:
|
||||
return 0
|
||||
elif self.species == "strawberry":
|
||||
return 1
|
||||
elif self.species == "sorrel":
|
||||
return 1
|
||||
elif self.species == "wheat":
|
||||
return 1
|
||||
elif self.is_healthy == 0:
|
||||
return 0
|
||||
elif self.field.tractor_there == 1:
|
||||
return 0
|
||||
elif self.ticks == 0:
|
||||
return 0
|
||||
elif self.field.hydration == 5:
|
||||
if self.field.tractor_there == 1:
|
||||
return 0
|
||||
elif self.field.tractor_there == 0:
|
||||
if self.is_healthy == 0:
|
||||
return 0
|
||||
elif self.is_healthy == 1:
|
||||
if self.ticks == 1:
|
||||
return 1
|
||||
elif self.ticks == 0:
|
||||
return 0
|
||||
elif self.field.hydration == 0:
|
||||
if self.ticks == 0:
|
||||
return 0
|
||||
elif self.ticks == 1:
|
||||
return -1
|
||||
decision_tree(self)
|
||||
|
||||
def update(self):
|
||||
if self.growth == 0:
|
||||
|
260
src/cases.py
Normal file
@ -0,0 +1,260 @@
|
||||
class Case:
|
||||
def __init__(self, values, attributes, Class):
|
||||
self.values = values
|
||||
self.attributes = attributes
|
||||
self.Class = Class
|
||||
|
||||
|
||||
attributes = ["field.hydration", "field.fertility", "species", "ticks", "is_healthy", "field.tractor_there"]
|
||||
|
||||
cases = [Case([4, 0, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([2, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([4, 1, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([2, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([2, 0, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([1, 1, "strawberry", 1, 0, 1], attributes, -1),
|
||||
Case([1, 0, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([2, 0, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([1, 1, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 1, "potato", 1, 1, 0], attributes, 1),
|
||||
Case([2, 1, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([4, 0, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([4, 1, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([4, 0, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([1, 1, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([0, 0, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([2, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([0, 1, "sorrel", 0, 1, 1], attributes, 0),
|
||||
Case([0, 1, "strawberry", 1, 1, 0], attributes, -1),
|
||||
Case([2, 0, "sorrel", 0, 1, 1], attributes, 0),
|
||||
Case([4, 0, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([5, 0, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 0, 0], attributes, -1),
|
||||
Case([4, 0, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([3, 0, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([3, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([4, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([2, 0, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([4, 1, "strawberry", 0, 0, 1], attributes, 0),
|
||||
Case([1, 0, "potato", 1, 1, 0], attributes, 0),
|
||||
Case([4, 1, "sorrel", 1, 1, 1], attributes, 0),
|
||||
Case([0, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([4, 0, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([4, 0, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([5, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 1, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([3, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([4, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([5, 1, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([3, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([0, 0, "potato", 1, 1, 1], attributes, -1),
|
||||
Case([4, 0, "strawberry", 1, 1, 1], attributes, 0),
|
||||
Case([2, 1, "strawberry", 1, 0, 1], attributes, 0),
|
||||
Case([2, 1, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([2, 1, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([1, 0, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([4, 0, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([4, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 0, 1], attributes, -1),
|
||||
Case([0, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([1, 1, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([0, 0, "sorrel", 1, 1, 0], attributes, -1),
|
||||
Case([2, 0, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([5, 1, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([2, 0, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([2, 1, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([3, 0, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([5, 0, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([0, 1, "strawberry", 1, 0, 0], attributes, -1),
|
||||
Case([0, 0, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([5, 0, "potato", 1, 1, 0], attributes, 1),
|
||||
Case([2, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 1, "sorrel", 0, 1, 0], attributes, 0),
|
||||
Case([2, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([5, 0, "strawberry", 1, 1, 0], attributes, 1),
|
||||
Case([5, 0, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([5, 0, "wheat", 1, 1, 0], attributes, 1),
|
||||
Case([2, 0, "potato", 1, 0, 0], attributes, 0),
|
||||
Case([3, 1, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([3, 0, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 1, 1], attributes, -1),
|
||||
Case([0, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([2, 1, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 1, 0], attributes, -1),
|
||||
Case([3, 0, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([4, 0, "strawberry", 1, 0, 1], attributes, 0),
|
||||
Case([3, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([5, 1, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([5, 0, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([3, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([1, 0, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([5, 0, "sorrel", 0, 1, 1], attributes, 0),
|
||||
Case([4, 0, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([0, 0, "strawberry", 0, 0, 0], attributes, 0),
|
||||
Case([5, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([4, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([1, 1, "strawberry", 1, 1, 0], attributes, -1),
|
||||
Case([5, 0, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([5, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 1, 0], attributes, -1),
|
||||
Case([3, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([1, 0, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([3, 0, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([0, 0, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([1, 0, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([1, 1, "sorrel", 0, 1, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([2, 0, "strawberry", 1, 1, 1], attributes, 0),
|
||||
Case([4, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 1, 0], attributes, -1),
|
||||
Case([1, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([4, 0, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([4, 0, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([0, 0, "sorrel", 1, 0, 1], attributes, -1),
|
||||
Case([1, 0, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([2, 1, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([3, 1, "strawberry", 1, 1, 0], attributes, 1),
|
||||
Case([1, 0, "sorrel", 1, 1, 1], attributes, 0),
|
||||
Case([5, 1, "strawberry", 1, 1, 0], attributes, 1),
|
||||
Case([2, 0, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([5, 1, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([1, 1, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([1, 1, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([4, 0, "potato", 1, 1, 0], attributes, 1),
|
||||
Case([2, 1, "strawberry", 0, 0, 1], attributes, 0),
|
||||
Case([0, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([3, 0, "sorrel", 1, 0, 1], attributes, 0),
|
||||
Case([4, 0, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([5, 1, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([1, 0, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([5, 0, "sorrel", 1, 0, 1], attributes, 0),
|
||||
Case([2, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([1, 0, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([4, 0, "wheat", 1, 1, 0], attributes, 1),
|
||||
Case([0, 0, "sorrel", 0, 1, 0], attributes, 0),
|
||||
Case([2, 0, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([0, 1, "potato", 1, 0, 1], attributes, -1),
|
||||
Case([0, 1, "sorrel", 1, 0, 1], attributes, -1),
|
||||
Case([1, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([3, 0, "sorrel", 1, 1, 1], attributes, 0),
|
||||
Case([0, 0, "potato", 1, 0, 1], attributes, -1),
|
||||
Case([4, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 0, 0], attributes, -1),
|
||||
Case([0, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([5, 0, "potato", 0, 1, 1], attributes, 0),
|
||||
Case([2, 0, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "potato", 1, 0, 0], attributes, -1),
|
||||
Case([1, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([4, 0, "sorrel", 1, 0, 1], attributes, 0),
|
||||
Case([1, 0, "potato", 1, 0, 0], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([2, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([0, 1, "potato", 1, 1, 1], attributes, -1),
|
||||
Case([5, 1, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([3, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "strawberry", 1, 0, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 0, 0, 1], attributes, 0),
|
||||
Case([0, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 1, 0, 0], attributes, -1),
|
||||
Case([1, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 1, 0, 1], attributes, -1),
|
||||
Case([1, 1, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([0, 0, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([4, 1, "sorrel", 1, 1, 1], attributes, 0),
|
||||
Case([5, 1, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([5, 1, "strawberry", 0, 0, 0], attributes, 0),
|
||||
Case([4, 1, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([1, 1, "potato", 1, 1, 0], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 0, 0], attributes, -1),
|
||||
Case([5, 0, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([0, 0, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([0, 0, "strawberry", 1, 1, 1], attributes, -1),
|
||||
Case([4, 0, "strawberry", 0, 0, 1], attributes, 0),
|
||||
Case([2, 0, "potato", 1, 0, 0], attributes, 0),
|
||||
Case([4, 0, "strawberry", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([1, 1, "wheat", 1, 1, 0], attributes, 0),
|
||||
Case([3, 0, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([1, 1, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([1, 1, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([3, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([3, 1, "wheat", 0, 0, 0], attributes, 0),
|
||||
Case([1, 0, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([5, 0, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([2, 1, "sorrel", 0, 1, 0], attributes, 0),
|
||||
Case([5, 0, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([1, 0, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([5, 1, "wheat", 1, 1, 0], attributes, 1),
|
||||
Case([3, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([5, 0, "wheat", 0, 0, 1], attributes, 0),
|
||||
Case([2, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([1, 0, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([0, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 1, 0], attributes, 1),
|
||||
Case([2, 0, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([3, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "potato", 1, 1, 0], attributes, 0),
|
||||
Case([1, 1, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([2, 1, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([2, 1, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([2, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([3, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([2, 0, "wheat", 1, 1, 1], attributes, 0),
|
||||
Case([5, 0, "wheat", 1, 1, 0], attributes, 1),
|
||||
Case([1, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([0, 1, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([5, 1, "strawberry", 1, 1, 1], attributes, 0),
|
||||
Case([4, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([5, 1, "sorrel", 0, 0, 1], attributes, 0),
|
||||
Case([1, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([5, 0, "strawberry", 1, 0, 1], attributes, 0),
|
||||
Case([5, 0, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([2, 0, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([3, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([0, 1, "strawberry", 1, 0, 0], attributes, -1),
|
||||
Case([0, 1, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([4, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([3, 0, "potato", 0, 0, 1], attributes, 0),
|
||||
Case([2, 1, "strawberry", 1, 1, 0], attributes, 0),
|
||||
Case([1, 1, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([4, 1, "wheat", 1, 0, 1], attributes, 0),
|
||||
Case([2, 0, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([5, 0, "sorrel", 0, 1, 1], attributes, 0),
|
||||
Case([0, 1, "wheat", 1, 1, 0], attributes, -1),
|
||||
Case([5, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([2, 0, "potato", 0, 0, 0], attributes, 0),
|
||||
Case([2, 0, "strawberry", 0, 1, 1], attributes, 0),
|
||||
Case([4, 1, "potato", 0, 1, 1], attributes, 0),
|
||||
Case([0, 1, "sorrel", 1, 1, 0], attributes, -1),
|
||||
Case([1, 1, "strawberry", 1, 0, 1], attributes, -1),
|
||||
Case([3, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([5, 1, "wheat", 1, 0, 0], attributes, 0),
|
||||
Case([4, 0, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([2, 1, "sorrel", 1, 0, 0], attributes, 0),
|
||||
Case([0, 1, "wheat", 0, 1, 0], attributes, 0),
|
||||
Case([5, 0, "potato", 1, 1, 0], attributes, 1),
|
||||
Case([3, 1, "strawberry", 0, 1, 0], attributes, 0),
|
||||
Case([5, 1, "strawberry", 0, 0, 0], attributes, 0),
|
||||
Case([4, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 0, 1], attributes, 0),
|
||||
Case([5, 1, "potato", 1, 1, 1], attributes, 0),
|
||||
Case([0, 0, "sorrel", 0, 0, 0], attributes, 0),
|
||||
Case([1, 1, "sorrel", 1, 1, 0], attributes, 1),
|
||||
Case([0, 1, "potato", 0, 1, 0], attributes, 0),
|
||||
Case([4, 1, "strawberry", 1, 1, 1], attributes, 0),
|
||||
Case([0, 0, "wheat", 0, 1, 1], attributes, 0),
|
||||
Case([3, 0, "wheat", 1, 1, 0], attributes, 1)]
|
@ -6,6 +6,7 @@ BROWN1 = (160, 130, 70)
|
||||
BROWN2 = (140, 110, 55)
|
||||
BROWN3 = (110, 85, 40)
|
||||
BROWN4 = (80, 60, 20)
|
||||
BROWN5 = (80, 60, 20)
|
||||
DBROWN = (65, 50, 20)
|
||||
LBROWN = (108, 97, 62)
|
||||
BLUE = (18, 93, 156)
|
28
src/mapschema.py
Normal file
@ -0,0 +1,28 @@
|
||||
def createField():
|
||||
field = [["soil", "soil", "soil", "soil", "soil", "soil", "rocks", "soil", "soil", "soil"],
|
||||
["soil", "soil", "soil", "soil", "soil", "soil", "rocks", "soil", "soil", "soil"],
|
||||
["soil", "soil", "soil", "soil", "soil", "road", "road", "road", "road", "road"],
|
||||
["rocks", "rocks", "rocks", "rocks", "soil", "road", "soil", "soil", "rocks", "soil"],
|
||||
["soil", "soil", "soil", "soil", "soil", "road", "rocks", "rocks", "soil", "soil"],
|
||||
["soil", "soil", "soil", "pond", "rocks", "road", "rocks", "soil", "soil", "rocks"],
|
||||
["rocks", "pond", "pond", "pond", "pond", "road", "rocks", "soil", "soil", "rocks"],
|
||||
["road", "road", "road", "road", "road", "road", "rocks", "soil", "soil", "soil"],
|
||||
["soil", "soil", "soil", "soil", "soil", "soil", "rocks", "soil", "rocks", "rocks"],
|
||||
["soil", "soil", "soil", "soil", "soil", "rocks", "soil", "rocks", "rocks", "soil"]
|
||||
]
|
||||
return field
|
||||
|
||||
|
||||
def createPlants():
|
||||
field = [["wheat", "wheat", "wheat", "wheat", "wheat", "wheat", 0, "strawberry", "strawberry", "strawberry"],
|
||||
["wheat", "wheat", "wheat", "wheat", "wheat", "wheat", 0, "strawberry", "strawberry", "strawberry"],
|
||||
["wheat", "wheat", "wheat", "wheat", 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
["wheat", "wheat", "wheat", "wheat", 0, 0, 0, 0, 0, 0],
|
||||
["wheat", "wheat", "wheat", 0, 0, 0, 0, "potato", "potato", 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, "potato", "potato", 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, "potato", "potato", "potato"],
|
||||
["strawberry", "strawberry", "strawberry", "strawberry", "strawberry", 0, 0, "potato", 0, 0],
|
||||
["strawberry", "strawberry", "strawberry", "strawberry", "strawberry", 0, 0, 0, 0, 0]
|
||||
]
|
||||
return field
|
@ -1,4 +1,5 @@
|
||||
import os
|
||||
|
||||
import pygame
|
||||
|
||||
# set up asset folders
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.0 KiB |
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.0 KiB |
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.0 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
19
tractor.py
@ -1,20 +1,8 @@
|
||||
import pygame
|
||||
from pygame.locals import (K_c)
|
||||
|
||||
from pygame.locals import (
|
||||
K_UP,
|
||||
K_DOWN,
|
||||
K_LEFT,
|
||||
K_RIGHT,
|
||||
K_ESCAPE,
|
||||
K_SPACE,
|
||||
K_c,
|
||||
KEYDOWN,
|
||||
QUIT
|
||||
)
|
||||
from src.dimensions import *
|
||||
from src.sprites import *
|
||||
|
||||
from dimensions import *
|
||||
from colors import *
|
||||
from sprites import *
|
||||
|
||||
class Tractor(pygame.sprite.Sprite):
|
||||
def __init__(self, field, position):
|
||||
@ -53,7 +41,6 @@ class Tractor(pygame.sprite.Sprite):
|
||||
|
||||
self.field[self.position[0]][self.position[1]].tractor_there = True
|
||||
|
||||
|
||||
def rotate_right(self):
|
||||
if self.direction == [1, 0]:
|
||||
self.direction = [0, 1]
|
||||
|