Add decision trees and some refactor
340
.gitignore
vendored
Normal 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/**
|
@ -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
|
||||
|
||||
|
||||
|
@ -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])
|
||||
|
@ -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)))
|
||||
|
||||
|
||||
|
@ -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
@ -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))
|
@ -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:
|
@ -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,107 +51,108 @@ 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)
|
||||
fringe = []
|
||||
explored = []
|
||||
self.actions = a_star(self,
|
||||
fringe,
|
||||
explored,
|
||||
(self.agent.col,self.agent.row, self.agent.angle),
|
||||
successor,
|
||||
get_cost,
|
||||
(bfs((self.agent.col,self.agent.row,self.agent.angle),successor,self))
|
||||
)
|
||||
fringe,
|
||||
explored,
|
||||
(self.agent.col, self.agent.row, self.agent.angle),
|
||||
successor,
|
||||
get_cost,
|
||||
(bfs((self.agent.col, self.agent.row, self.agent.angle), successor, self))
|
||||
)
|
||||
|
||||
print(self.actions)
|
||||
|
||||
return self.actions
|
||||
|
||||
|
||||
|
@ -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
@ -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
@ -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))
|
@ -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]))
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
257
core/resources/data/data_tree.csv
Normal file
@ -0,0 +1,257 @@
|
||||
Czy jest czerwony,Czy ma pierścień,Czy ma pusty trzpień,Czy ma kropki,Czy ma blaszki,Czy zmienia kolor po przełamaniu,Czy ma nieprzyjemny zapach,Czy ma śluz,Czy jest trujący
|
||||
0,0,0,0,0,0,0,0,0
|
||||
1,0,0,0,0,0,0,0,0
|
||||
0,1,0,0,0,0,0,0,0
|
||||
1,1,0,0,0,0,0,0,0
|
||||
0,0,1,0,0,0,0,0,0
|
||||
1,0,1,0,0,0,0,0,0
|
||||
0,1,1,0,0,0,0,0,0
|
||||
1,1,1,0,0,0,0,0,0
|
||||
0,0,0,1,0,0,0,0,0
|
||||
1,0,0,1,0,0,0,0,0
|
||||
0,1,0,1,0,0,0,0,0
|
||||
1,1,0,1,0,0,0,0,0
|
||||
0,0,1,1,0,0,0,0,0
|
||||
1,0,1,1,0,0,0,0,0
|
||||
0,1,1,1,0,0,0,0,0
|
||||
1,1,1,1,0,0,0,0,0
|
||||
0,0,0,0,1,0,0,0,0
|
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,1,1,1
|
||||
0,0,0,0,1,1,1,1,0
|
||||
1,0,0,0,1,1,1,1,1
|
||||
0,1,0,0,1,1,1,1,1
|
||||
1,1,0,0,1,1,1,1,1
|
||||
0,0,1,0,1,1,1,1,1
|
||||
1,0,1,0,1,1,1,1,1
|
||||
0,1,1,0,1,1,1,1,1
|
||||
1,1,1,0,1,1,1,1,1
|
||||
0,0,0,1,1,1,1,1,1
|
||||
1,0,0,1,1,1,1,1,1
|
||||
0,1,0,1,1,1,1,1,1
|
||||
1,1,0,1,1,1,1,1,1
|
||||
0,0,1,1,1,1,1,1,1
|
||||
1,0,1,1,1,1,1,1,1
|
||||
0,1,1,1,1,1,1,1,1
|
||||
1,1,1,1,1,1,1,1,1
|
|
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 9.1 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
15
core/tree.py
Normal 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
@ -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
@ -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
|