Add decision trees and some refactor

This commit is contained in:
mkielar 2021-06-10 21:23:58 +02:00
parent 1d717acefa
commit bb970960d0
53 changed files with 1205 additions and 505 deletions

340
.gitignore vendored Normal file
View File

@ -0,0 +1,340 @@
# Created by https://www.toptal.com/developers/gitignore/api/python,venv,intellij,pycharm
# Edit at https://www.toptal.com/developers/gitignore?templates=python,venv,intellij,pycharm
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/
# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml
# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/
# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$
# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml
### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
# Generated files
# Sensitive or high-churn files
# Gradle
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
# Mongo Explorer plugin
# File-based project format
# IntelliJ
# mpeltonen/sbt-idea plugin
# JIRA plugin
# Cursive Clojure plugin
# Crashlytics plugin (for Android Studio and IntelliJ)
# Editor-based Rest Client
# Android studio 3.1+ serialized cache file
### PyCharm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
pytestdebug.log
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
doc/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
#poetry.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
# .env
.env/
.venv/
env/
venv/
ENV/
env.bak/
venv.bak/
pythonenv*
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# operating system-related files
# file properties cache/storage on macOS
*.DS_Store
# thumbnail cache on Windows
Thumbs.db
# profiling data
.prof
### venv ###
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
.venv
pip-selfcheck.json
# End of https://www.toptal.com/developers/gitignore/api/python,venv,intellij,pycharm
.idea/**

View File

@ -6,3 +6,10 @@ of the square(piece object) location
each square(piece object) contains own x and y identifiers and isSbThere atribute which stores info if detective is standing on
piece location
a_star algorithm:
-goal: nearest mushroom without posion, x,y finded by bfs
-get_cost: return summary cost of parent node and cost of current node (predictable heuristic cost and cost of field)
-heuristic function: summary of differences between node location and goal location

View File

@ -1,87 +0,0 @@
from container import board
from container.node import Node
from container.mushroom import Mushroom
from container.tree import Tree
from operator import attrgetter
def a_star(board, fringe, explored, istate, successor, get_cost, goaltest):
agent_x = istate[0]
agent_y = istate[1]
agent_angle = istate[2]
fringe: List[Node] = [Node(agent_x, agent_y, agent_angle)]
while fringe:
if not fringe:
return False, False
node = min(fringe, key=lambda x: x.cost)
fringe.remove(node)
if (node.x, node.y) == goaltest:
actions = []
while node.parent != None:
actions.append(node.action)
node = node.parent
actions.reverse()
return actions
explored.append(node)
for action, x, y, angle in successor(board, node.x, node.y, node.angle):
next_node = Node(x, y, angle)
next_node.parent = node
next_node.action = action
next_node.cost = get_cost(next_node, goaltest,board) + heuristic_function(node, goaltest)
if next_node not in fringe and next_node not in explored:
fringe.append(next_node)
else:
for checked_node in fringe:
if(checked_node == next_node and (next_node.cost) < (checked_node.cost)):
fringe[fringe.index(checked_node)] = next_node
def successor(board,x,y,angle):
result = []
result.append(("rotate_left", x, y, (angle + 1) % 4))
result.append(("rotate_right", x, y, (angle - 1) % 4))
if angle == 1:
if x > 0:
result.append(("move", x-1, y, angle))
elif angle == 0:
if y > 0:
result.append(("move", x, y-1, angle))
elif angle == 3:
if x < board.col - 1:
result.append(("move", x+1, y, angle))
elif angle == 2:
if y < board.row - 1:
result.append(("move", x, y+1, angle))
return result
def get_cost(node, goal: Mushroom, board):
if (node.parent.x, node.parent.y) == (node.x, node.y):
sum = 1
elif(isinstance((board.board[node.x][node.y]),Tree)):
sum = 1000
elif(isinstance((board.board[node.x][node.y]),Mushroom) and (board.board[node.x][node.y].poison) == True):
sum = 1000
else:
sum = 2
return sum + node.parent.cost
def heuristic_function(node, goal):
return abs(node.x - goal[0]) + abs(node.y - goal[1])

View File

@ -1,25 +0,0 @@
from container.piece import Piece
import pygame
class Mushroom(Piece):
def __init__(self,x_y, img = 0, poison = False, grow = 100):
self.name = "Mushroom"
self.col = x_y[0]
self.row = x_y[1]
self.poison = poison
self.grow = grow
self.img = pygame.image.load(r'container\mushrooms\m'+str(img)+'.png')
if poison: self.img = pygame.image.load(r'container\mushrooms\pm'+str(img)+'.png')
self.points = img+1
if poison: self.points *= -1
def draw(self, win, square_size):
x = (self.col+0.5*(100-self.grow)/100)*square_size[0]
y = (self.row+0.5*(100-self.grow)/100)*square_size[1]
win.blit(pygame.transform.scale(self.img, (int(square_size[0]/100*self.grow), int(square_size[1]/100*self.grow))), ((x, y)))

View File

@ -1,13 +0,0 @@
from container.piece import Piece
import pygame
class Tree(Piece):
def __init__(self,x_y, img = 0):
self.name = "Tree"
self.col = x_y[0]
self.row = x_y[1]
self.img = pygame.image.load(r'container\trees\tree'+str(img)+'.png')

122
core/a_star.py Normal file
View File

@ -0,0 +1,122 @@
from typing import List
from core.mushroom import Mushroom
from core.node import Node
from core.tree import Tree
def a_star(board, fringe, explored, istate, successor, get_cost, goaltest):
agent_x = istate[0]
agent_y = istate[1]
agent_angle = istate[2]
fringe: List[Node] = [Node(agent_x, agent_y, agent_angle)]
while fringe:
if not fringe:
return False, False
node = min(fringe, key=lambda x: x.cost)
fringe.remove(node)
if (node.x, node.y) == goaltest:
actions = []
while node.parent is not None:
actions.append(node.action)
node = node.parent
actions.reverse()
return actions
explored.append(node)
for action, x, y, angle in successor(board, node.x, node.y, node.angle):
next_node = Node(x, y, angle)
next_node.parent = node
next_node.action = action
next_node.cost = get_cost(next_node, goaltest, board) + heuristic_function(next_node, goaltest, board)
if next_node not in fringe and next_node not in explored:
fringe.append(next_node)
else:
for checked_node in fringe:
if checked_node == next_node and next_node.cost < checked_node.cost:
fringe[fringe.index(checked_node)] = next_node
def successor(board, x, y, angle):
result = []
result.append(("rotate_left", x, y, (angle + 1) % 4))
result.append(("rotate_right", x, y, (angle - 1) % 4))
if angle == 1:
if x > 0:
result.append(("move", x - 1, y, angle))
elif angle == 0:
if y > 0:
result.append(("move", x, y - 1, angle))
elif angle == 3:
if x < board.col - 1:
result.append(("move", x + 1, y, angle))
elif angle == 2:
if y < board.row - 1:
result.append(("move", x, y + 1, angle))
return result
def get_cost(node, goal: Mushroom, board):
if (node.parent.x, node.parent.y) == (node.x, node.y):
weight = 1
elif isinstance((board.board[node.x][node.y]), Tree):
weight = 1000
elif isinstance((board.board[node.x][node.y]), Mushroom) and board.dt.predict(board.board[node.x][node.y]):
weight = 1000
else:
weight = 2
return weight + node.parent.cost
def heuristic_function(node, goal, board):
try:
return abs(node.x - goal[0]) + abs(node.y - goal[1])
except:
print("No more edible mushrooms on the board. Score: " + str(board.agent.points))
exit(0)
def bfs(istate, successor, board):
fringe = []
explored = []
fringe_states = set()
explored_states = set()
agent_x = istate[0]
agent_y = istate[1]
agent_angle = istate[2]
fringe.append(Node(agent_x, agent_y, agent_angle))
fringe_states.add((agent_x, agent_y, agent_angle))
while fringe:
if not fringe:
return False, False
node = fringe.pop(0)
fringe_states.remove((node.x, node.y, node.angle))
if isinstance((board.board[node.x][node.y]), Mushroom):
if not board.dt.predict(board.board[node.x][node.y]):
return node.x, node.y
explored.append(node)
explored_states.add((node.x, node.y, node.angle))
for action, x, y, angle in successor(board, node.x, node.y, node.angle):
if ((x, y, angle) not in explored_states and (x, y, angle) not in fringe_states):
next_node = Node(x, y, angle)
next_node.parent = node
next_node.action = action
fringe.append(next_node)
fringe_states.add((x, y, angle))

View File

@ -1,5 +1,7 @@
import os
import pygame
from container.piece import Piece
from core.piece import Piece
class Agent(Piece):
@ -8,17 +10,22 @@ class Agent(Piece):
self.col = x_y[0]
self.row = x_y[1]
self.angle = 0
self.current_angle = 0
self.moving = 0
self.rotating = 0
self.move_to = (self.row, self.col)
self.points = 0
self.img = pygame.image.load(r'container\new_detective.png')
self.img = pygame.image.load(r'core' + os.path.sep + 'resources' + os.path.sep +
'agent' + os.path.sep + 'new_detective.png')
self.square_size = square_size
self.img = pygame.transform.scale(self.img, (int(self.square_size[0]), int(self.square_size[1])))
def draw(self, win):
x = (self.col + 0.5 + (self.move_to[0] - self.col)/10*self.moving)*self.square_size[0]
y = (self.row + 0.5 + (self.move_to[1] - self.row)/10*self.moving)*self.square_size[1]
@ -29,6 +36,7 @@ class Agent(Piece):
def rotate(self, angle):
if self.moving == self.rotating == 0:
self.rotating += angle
#print(self.rotating)
def move(self):
if self.moving == self.rotating == 0:

View File

@ -1,14 +1,15 @@
import pygame
import random
from container.constans import *
from container.tree import Tree
from container.mushroom import Mushroom
from container.agent import Agent
from container.a_star import a_star,successor, get_cost
from core.constans import *
from core.decision_tree import DecisionTree
from core.tree import Tree
from core.mushroom import Mushroom
from core.agent import Agent
from core.a_star import a_star, bfs, successor, get_cost
class Board:
def __init__(self, x = 0, y = 0, width = WIDTH, height = HEIGHT, row = ROWS, col = COLUMNS):
def __init__(self, x=0, y=0, width=WIDTH, height=HEIGHT, row=ROWS, col=COLUMNS):
self.x = x
self.y = y
self.width = width
@ -19,6 +20,8 @@ class Board:
self.board = [[False for j in range(self.row)] for i in range(self.col)]
self.free_spaces = []
self.update_free_spaces()
self.dt = DecisionTree(0.05)
self.dt.learn()
self.agent = Agent(self.free_spaces.pop(), self.square_size)
@ -30,15 +33,13 @@ class Board:
x_y = self.free_spaces.pop()
self.board[x_y[0]][x_y[1]] = Tree(x_y, random.randint(0, 8))
for i in range(MUSHROOMS_START):
x_y = self.free_spaces.pop()
self.board[x_y[0]][x_y[1]] = Mushroom(x_y, random.randint(0, 2))
for i in range(POISON_MUSHROOMS_START):
x_y = self.free_spaces.pop()
self.board[x_y[0]][x_y[1]] = Mushroom(x_y, random.randint(0, 2), True)
self.board[x_y[0]][x_y[1]] = Mushroom(x_y, random.randint(0, 2))
self.grow_next = 0
@ -50,90 +51,94 @@ class Board:
for x in range(self.col):
for y in range(self.row):
if self.board[x][y] == False: self.free_spaces.append((x,y))
if self.board[x][y] == False: self.free_spaces.append((x, y))
random.shuffle(self.free_spaces)
def draw_squares(self,win):
def draw_squares(self, win):
self.surface.fill(GREEN_2)
for x in range(self.col):
for y in range(self.row):
if (x+y) % 2 == 0:
pygame.draw.rect(self.surface,GREEN,(x*self.square_size[0], y*self.square_size[1], self.square_size[0], self.square_size[1]))
if (x + y) % 2 == 0:
pygame.draw.rect(self.surface, GREEN, (
x * self.square_size[0], y * self.square_size[1], self.square_size[0], self.square_size[1]))
win.blit(self.surface, (self.x, self.y))
def draw_agent(self,win):
def draw_agent(self, win):
self.agent.draw(self.surface)
win.blit(self.surface, (self.x, self.y))
def draw_pieces(self,win):
def draw_pieces(self, win):
for x in range(self.col):
for y in range(self.row):
if self.board[x][y] != False:
self.board[x][y].draw(self.surface, self.square_size)
win.blit(self.surface, (self.x, self.y))
def draw_info(self,win):
def draw_info(self, win):
myfont = pygame.font.SysFont('Comic Sans MS', 30)
textsurface = myfont.render(str(self.agent.points), False, (0, 0, 0))
win.blit(textsurface,(self.x+self.width-textsurface.get_width()-5,self.y-40))
win.blit(textsurface, (self.x + self.width - textsurface.get_width() - 5, self.y - 40))
# kolumna agneta
textsurface = myfont.render("c: "+str(self.agent.col), False, (0, 0, 0))
win.blit(textsurface,(self.x+1,self.y-40))
textsurface = myfont.render("c: " + str(self.agent.col), False, (0, 0, 0))
win.blit(textsurface, (self.x + 1, self.y - 40))
# wiersz agneta
textsurface = myfont.render("r: "+str(self.agent.row), False, (0, 0, 0))
win.blit(textsurface,(self.x+100,self.y-40))
textsurface = myfont.render("r: " + str(self.agent.row), False, (0, 0, 0))
win.blit(textsurface, (self.x + 100, self.y - 40))
# kierunek agenta
textsurface = myfont.render("a: "+str(self.agent.angle), False, (0, 0, 0))
win.blit(textsurface,(self.x+200,self.y-40))
textsurface = myfont.render("a: " + str(self.agent.angle), False, (0, 0, 0))
win.blit(textsurface, (self.x + 200, self.y - 40))
def update_agent(self):
self.agent.update_animation()
if self.actions and self.agent.moving == self.agent.rotating == 0:
action = self.actions.pop(0)
if action == "move": self.agent.move()
elif action == "rotate_left": self.agent.rotate(1)
else: self.agent.rotate(-1)
if action == "move":
self.agent.move()
elif action == "rotate_left":
self.agent.rotate(1)
else:
self.agent.rotate(-1)
#zebranie grzyba
if self.board[self.agent.col][self.agent.row] != False and self.board[self.agent.col][self.agent.row].name == "Mushroom" and self.board[self.agent.col][self.agent.row].grow == 100:
# zebranie grzyba
if self.board[self.agent.col][self.agent.row] != False and self.board[self.agent.col][
self.agent.row].name == "Mushroom" and self.board[self.agent.col][self.agent.row].grow == 100:
self.agent.points += self.board[self.agent.col][self.agent.row].points
self.board[self.agent.col][self.agent.row] = False
self.free_spaces.append((self.agent.col, self.agent.row))
def grow_mushrooms(self):
numer = 0
numer_poison = 0
# numer_poison = 0
for x in range(self.col):
for y in range(self.row):
if self.board[x][y] != False and self.board[x][y].name == "Mushroom":
if self.board[x][y].grow < 100: self.board[x][y].grow += 1
if self.board[x][y].poison: numer_poison += 1
else: numer += 1
# if self.board[x][y].poison:
# numer_poison += 1
# else:
numer += 1
if self.grow_next < 100: self.grow_next += 1
if self.grow_next < 100:
self.grow_next += 1
elif random.random() > 0.5 and numer < MUSHROOMS_MAX:
self.grow_next = 0
self.update_free_spaces()
x_y = self.free_spaces.pop()
self.board[x_y[0]][x_y[1]] = Mushroom(x_y, random.randint(0, 2), False, 0)
elif numer_poison < POISON_MUSHROOMS_MAX:
self.grow_next = 0
self.update_free_spaces()
x_y = self.free_spaces.pop()
self.board[x_y[0]][x_y[1]] = Mushroom(x_y, random.randint(0, 2), True, 0)
self.board[x_y[0]][x_y[1]] = Mushroom(x_y, random.randint(0, 2), 0)
# elif numer_poison < POISON_MUSHROOMS_MAX:
# self.grow_next = 0
# self.update_free_spaces()
# x_y = self.free_spaces.pop()
# self.board[x_y[0]][x_y[1]] = Mushroom(x_y, random.randint(0, 2), 0)
def a_starxd(self):
print(self.agent.angle)
@ -142,15 +147,12 @@ class Board:
self.actions = a_star(self,
fringe,
explored,
(self.agent.col,self.agent.row, self.agent.angle),
(self.agent.col, self.agent.row, self.agent.angle),
successor,
get_cost,
(bfs((self.agent.col,self.agent.row,self.agent.angle),successor,self))
(bfs((self.agent.col, self.agent.row, self.agent.angle), successor, self))
)
print(self.actions)
return self.actions

View File

@ -6,7 +6,7 @@ HEIGHT = 700
COLUMNS = 20
ROWS = 14
#number of mushrooms
#amount of mushrooms on the board
MUSHROOMS_START = 5
MUSHROOMS_MAX = 10
@ -15,7 +15,7 @@ POISON_MUSHROOMS_MAX = 40
TREES = 80
#colors in game in rgb
#colors of board in game in rgb
GREEN = (0,230,0)
GREEN_2 = (0,200,0)
WHITE = (255,255,255)
#WHITE = (255,255,255)

32
core/decision_tree.py Normal file
View File

@ -0,0 +1,32 @@
import os
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
class DecisionTree:
def __init__(self, precision):
self.model = DecisionTreeClassifier(criterion='gini')
self.learningDataSize = precision
def learn(self):
dataset = pd.read_csv(r'core' + os.path.sep + 'resources' + os.path.sep + 'data' +
os.path.sep + 'data_tree.csv')
input_x = dataset.iloc[:, 0:8]
input_y = dataset.iloc[:, 8]
x_train, x_test, y_train, y_test = train_test_split(input_x, input_y, test_size=(1-self.learningDataSize))
self.model.fit(x_train, y_train)
def predict(self, mushroom):
return bool(self.model.predict([[
mushroom.isRed,
mushroom.hasRing,
mushroom.hasEmptyCore,
mushroom.hasDots,
mushroom.hasLamella,
mushroom.isShiftingColor,
mushroom.hasUnpleasantSmell,
mushroom.hasSlime,
]])[0])

42
core/mushroom.py Normal file
View File

@ -0,0 +1,42 @@
import os
import random
from core.piece import Piece
import pygame
class Mushroom(Piece):
def __init__(self, x_y, img=0, grow=100):
self.name = "Mushroom"
self.col = x_y[0]
self.row = x_y[1]
self.grow = grow
self.isRed = bool(random.getrandbits(1))
self.hasRing = bool(random.getrandbits(1))
self.hasEmptyCore = bool(random.getrandbits(1))
self.hasDots = bool(random.getrandbits(1))
self.hasLamella = bool(random.getrandbits(1))
self.isShiftingColor = bool(random.getrandbits(1))
self.hasUnpleasantSmell = bool(random.getrandbits(1))
self.hasSlime = bool(random.getrandbits(1))
self.img = pygame.image.load(r'core' + os.path.sep + 'resources' + os.path.sep + 'mushrooms' +
os.path.sep + 'm' + str(img) + '.png')
poison = (int(self.isRed) + int(self.hasRing) + int(self.hasEmptyCore) + int(self.hasDots) + int(
self.hasLamella) + int(self.isShiftingColor) + int(self.hasUnpleasantSmell) + int(self.hasSlime)) > 4
if poison:
self.img = pygame.image.load(r'core' + os.path.sep + 'resources' + os.path.sep + 'mushrooms' +
os.path.sep + 'pm' + str(img) + '.png')
self.points = img + 1
if poison:
self.points *= -1
def draw(self, win, square_size):
x = (self.col + 0.5 * (100 - self.grow) / 100) * square_size[0]
y = (self.row + 0.5 * (100 - self.grow) / 100) * square_size[1]
win.blit(pygame.transform.scale(self.img,
(int(square_size[0] / 100 * self.grow), int(square_size[1] / 100 * self.grow))),
(x, y))

View File

@ -2,11 +2,14 @@ import pygame
class Piece:
def __init__(self,x_y):
def __init__(self,x_y,weight = 0 ,mushroom = 0):
self.name = ""
self.col = x_y[0]
self.row = x_y[1]
self.img = ''
self.weight = weight
self.mushroom = mushroom
def draw(self, win, square_size):
win.blit(pygame.transform.scale(self.img, (int(square_size[0]), int(square_size[1]))), (self.col*square_size[0], self.row*square_size[1]))

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,257 @@
Czy jest czerwony,Czy ma pierścień,Czy ma pusty trzpień,Cz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
224 0 1 1 1 1 0 1 1 1
225 1 1 1 1 1 0 1 1 1
226 0 0 0 0 0 1 1 1 0
227 1 0 0 0 0 1 1 1 0
228 0 1 0 0 0 1 1 1 0
229 1 1 0 0 0 1 1 1 1
230 0 0 1 0 0 1 1 1 0
231 1 0 1 0 0 1 1 1 1
232 0 1 1 0 0 1 1 1 1
233 1 1 1 0 0 1 1 1 1
234 0 0 0 1 0 1 1 1 0
235 1 0 0 1 0 1 1 1 1
236 0 1 0 1 0 1 1 1 1
237 1 1 0 1 0 1 1 1 1
238 0 0 1 1 0 1 1 1 1
239 1 0 1 1 0 1 1 1 1
240 0 1 1 1 0 1 1 1 1
241 1 1 1 1 0 1 1 1 1
242 0 0 0 0 1 1 1 1 0
243 1 0 0 0 1 1 1 1 1
244 0 1 0 0 1 1 1 1 1
245 1 1 0 0 1 1 1 1 1
246 0 0 1 0 1 1 1 1 1
247 1 0 1 0 1 1 1 1 1
248 0 1 1 0 1 1 1 1 1
249 1 1 1 0 1 1 1 1 1
250 0 0 0 1 1 1 1 1 1
251 1 0 0 1 1 1 1 1 1
252 0 1 0 1 1 1 1 1 1
253 1 1 0 1 1 1 1 1 1
254 0 0 1 1 1 1 1 1 1
255 1 0 1 1 1 1 1 1 1
256 0 1 1 1 1 1 1 1 1
257 1 1 1 1 1 1 1 1 1

View File

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

15
core/tree.py Normal file
View File

@ -0,0 +1,15 @@
import os
import pygame
from core.piece import Piece
class Tree(Piece):
def __init__(self, x_y, img=0):
super().__init__(x_y)
self.name = "Tree"
self.col = x_y[0]
self.row = x_y[1]
self.img = pygame.image.load(r'core' + os.path.sep + 'resources' + os.path.sep + 'trees' +
os.path.sep + 'tree' + str(img) + '.png')

45
main.py
View File

@ -1,26 +1,26 @@
import pygame
from container.constans import WIDTH, HEIGHT, ROWS, COLUMNS, GREEN
from container.board import Board
from core.board import Board
from core.constans import WIDTH, HEIGHT, GREEN
FPS = 18
from core.decision_tree import DecisionTree
from core.mushroom import Mushroom
FPS = 40
#creating game window
WIN = pygame.display.set_mode((WIDTH,HEIGHT))
#setting name
# creating game window
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
# setting name
pygame.display.set_caption('Forest')
pygame.font.init()
#detective = pygame.image.load(r'container\detective.png')
# detective = pygame.image.load(r'core\detective.png')
def main():
run = True
clock = pygame.time.Clock() #for fps
board = Board(0,40,WIDTH,HEIGHT-40)
clock = pygame.time.Clock() # for fps
board = Board(0, 40, WIDTH, HEIGHT - 40)
while run:
clock.tick(FPS)
@ -29,19 +29,15 @@ def main():
if event.type == pygame.QUIT:
run = False
#managing arrow click
# managing arrow click
key_input = pygame.key.get_pressed()
if key_input[pygame.K_LEFT]: board.agent.rotate(1)
if key_input[pygame.K_UP]: board.agent.move()
if key_input[pygame.K_RIGHT]: board.agent.rotate(-1)
#drawing map and detective
# drawing map and detective
WIN.fill(GREEN)
board.update_agent() #update moves and collecting mushrooms
board.update_agent() # update moves and collecting mushrooms
board.grow_mushrooms()
board.draw_squares(WIN)
@ -51,21 +47,12 @@ def main():
pygame.display.update()
if key_input[pygame.K_SPACE]:
board.a_starxd()
if(board.agent.rotating==0 and board.agent.moving==0):
if board.agent.rotating == 0 and board.agent.moving == 0:
board.a_starxd()
pygame.quit()
main()

10
requirements.txt Normal file
View File

@ -0,0 +1,10 @@
joblib==1.0.1
numpy==1.20.3
pandas==1.2.4
pygame==2.0.1
python-dateutil==2.8.1
pytz==2021.1
scikit-learn==0.24.2
scipy==1.6.3
six==1.16.0
threadpoolctl==2.1.0