From bb970960d068afdbdf35aa11278e6d17083a599e Mon Sep 17 00:00:00 2001 From: mkielar Date: Thu, 10 Jun 2021 21:23:58 +0200 Subject: [PATCH] Add decision trees and some refactor --- .gitignore | 340 ++++++++++++++++++ README.txt | 23 +- container/__pycache__/__init__.cpython-37.pyc | Bin 142 -> 0 bytes container/__pycache__/__init__.cpython-39.pyc | Bin 142 -> 0 bytes container/__pycache__/a_star.cpython-37.pyc | Bin 2678 -> 0 bytes container/__pycache__/agent.cpython-37.pyc | Bin 3285 -> 0 bytes container/__pycache__/agent.cpython-39.pyc | Bin 3297 -> 0 bytes container/__pycache__/board.cpython-37.pyc | Bin 5136 -> 0 bytes container/__pycache__/board.cpython-39.pyc | Bin 4447 -> 0 bytes container/__pycache__/constans.cpython-37.pyc | Bin 467 -> 0 bytes container/__pycache__/constans.cpython-39.pyc | Bin 461 -> 0 bytes container/__pycache__/graph.cpython-39.pyc | Bin 1714 -> 0 bytes container/__pycache__/mushroom.cpython-37.pyc | Bin 1144 -> 0 bytes container/__pycache__/mushroom.cpython-39.pyc | Bin 1146 -> 0 bytes container/__pycache__/node.cpython-37.pyc | Bin 728 -> 0 bytes container/__pycache__/piece.cpython-37.pyc | Bin 741 -> 0 bytes container/__pycache__/piece.cpython-39.pyc | Bin 747 -> 0 bytes container/__pycache__/state.cpython-39.pyc | Bin 490 -> 0 bytes container/__pycache__/tree.cpython-37.pyc | Bin 632 -> 0 bytes container/__pycache__/tree.cpython-39.pyc | Bin 634 -> 0 bytes container/a_star.py | 87 ----- container/mushroom.py | 25 -- container/tree.py | 13 - {container => core}/__init__.py | 0 core/a_star.py | 122 +++++++ {container => core}/agent.py | 198 +++++----- {container => core}/board.py | 314 ++++++++-------- {container => core}/constans.py | 42 +-- core/decision_tree.py | 32 ++ core/mushroom.py | 42 +++ {container => core}/node.py | 28 +- {container => core}/piece.py | 33 +- .../resources/agent}/detective.png | Bin .../resources/agent}/new_detective.png | Bin core/resources/data/data_tree.csv | 257 +++++++++++++ .../resources}/mushrooms/m0.png | Bin .../resources}/mushrooms/m1.png | Bin .../resources}/mushrooms/m2.png | Bin .../resources}/mushrooms/pm0.png | Bin .../resources}/mushrooms/pm1.png | Bin .../resources}/mushrooms/pm2.png | Bin {container => core/resources}/trees/tree0.png | Bin {container => core/resources}/trees/tree1.png | Bin {container => core/resources}/trees/tree2.png | Bin {container => core/resources}/trees/tree3.png | Bin {container => core/resources}/trees/tree4.png | Bin {container => core/resources}/trees/tree5.png | Bin {container => core/resources}/trees/tree6.png | Bin {container => core/resources}/trees/tree7.png | Bin {container => core/resources}/trees/tree8.png | Bin core/tree.py | 15 + main.py | 129 +++---- requirements.txt | 10 + 53 files changed, 1205 insertions(+), 505 deletions(-) create mode 100644 .gitignore delete mode 100644 container/__pycache__/__init__.cpython-37.pyc delete mode 100644 container/__pycache__/__init__.cpython-39.pyc delete mode 100644 container/__pycache__/a_star.cpython-37.pyc delete mode 100644 container/__pycache__/agent.cpython-37.pyc delete mode 100644 container/__pycache__/agent.cpython-39.pyc delete mode 100644 container/__pycache__/board.cpython-37.pyc delete mode 100644 container/__pycache__/board.cpython-39.pyc delete mode 100644 container/__pycache__/constans.cpython-37.pyc delete mode 100644 container/__pycache__/constans.cpython-39.pyc delete mode 100644 container/__pycache__/graph.cpython-39.pyc delete mode 100644 container/__pycache__/mushroom.cpython-37.pyc delete mode 100644 container/__pycache__/mushroom.cpython-39.pyc delete mode 100644 container/__pycache__/node.cpython-37.pyc delete mode 100644 container/__pycache__/piece.cpython-37.pyc delete mode 100644 container/__pycache__/piece.cpython-39.pyc delete mode 100644 container/__pycache__/state.cpython-39.pyc delete mode 100644 container/__pycache__/tree.cpython-37.pyc delete mode 100644 container/__pycache__/tree.cpython-39.pyc delete mode 100644 container/a_star.py delete mode 100644 container/mushroom.py delete mode 100644 container/tree.py rename {container => core}/__init__.py (100%) create mode 100644 core/a_star.py rename {container => core}/agent.py (88%) rename {container => core}/board.py (54%) rename {container => core}/constans.py (67%) create mode 100644 core/decision_tree.py create mode 100644 core/mushroom.py rename {container => core}/node.py (91%) rename {container => core}/piece.py (70%) rename {container => core/resources/agent}/detective.png (100%) rename {container => core/resources/agent}/new_detective.png (100%) create mode 100644 core/resources/data/data_tree.csv rename {container => core/resources}/mushrooms/m0.png (100%) rename {container => core/resources}/mushrooms/m1.png (100%) rename {container => core/resources}/mushrooms/m2.png (100%) rename {container => core/resources}/mushrooms/pm0.png (100%) rename {container => core/resources}/mushrooms/pm1.png (100%) rename {container => core/resources}/mushrooms/pm2.png (100%) rename {container => core/resources}/trees/tree0.png (100%) rename {container => core/resources}/trees/tree1.png (100%) rename {container => core/resources}/trees/tree2.png (100%) rename {container => core/resources}/trees/tree3.png (100%) rename {container => core/resources}/trees/tree4.png (100%) rename {container => core/resources}/trees/tree5.png (100%) rename {container => core/resources}/trees/tree6.png (100%) rename {container => core/resources}/trees/tree7.png (100%) rename {container => core/resources}/trees/tree8.png (100%) create mode 100644 core/tree.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..46ef7dc --- /dev/null +++ b/.gitignore @@ -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/** \ No newline at end of file diff --git a/README.txt b/README.txt index 3d50cf2..d9d409f 100644 --- a/README.txt +++ b/README.txt @@ -1,8 +1,15 @@ -required pygame library installed -change img directory in main.py line 13 - -board is represented as 2D lists of square objects, where first index of the list points to the row and second to the column -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 +required pygame library installed +change img directory in main.py line 13 + +board is represented as 2D lists of square objects, where first index of the list points to the row and second to the column +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 + + diff --git a/container/__pycache__/__init__.cpython-37.pyc b/container/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 8073cc2e2d4eb49fec649257ccdc7f1dee14ca7e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 142 zcmZ?b<>g`k0_}3Y1Q7igM8E(ekl_Ht#VkM~g&~+hlhJP_LlHS4Xj7iSVD@n}EOD&3tkI&4@EQycTE2zB1VUwGm PQks)$2Qu(85HkP(Tn{2m diff --git a/container/__pycache__/__init__.cpython-39.pyc b/container/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 1db512bb92bcbb7f380d46485e85316cd1fa4b61..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 142 zcmYe~<>g`kg6Wqc6F~H15P=LBfgA@QE@lA|DGb33nv8xc8Hzx{2;!HqvsFxJacWU< zOhIBvQGSd|YH@Z+enCueW=ybWKumIeUP)qRUTRTHe0*kJW=VX!UP0w84x8Nkl+v73 LJCI?YftUdRLP!ti%vH~)v?8OG7(V}JCRl7T1-Q%iW zXB<^uvX;dKDF-AjC|X~TB5_1f{+2$1gfO`vam$I{tDgPHiXPRgSMR-gRrNmS&)sgy z@cnoB&yPOqGWHEEPCg0bCWg%c6jOZ87JS4x;bJZpawI)2=fNTzg&q&)(IOtj9uMcq zqBUv(k5v4KjZ&4U7Us4NRr)zsZPj@cj5?~TdZ2dICDq5=QyaJ0aPuk7WJ6wu_lmJm zK!WW;Y0SxA4()*{iUrZ`7)`WvT$W~Em!&pYOdIiSVi5i|hP}fXb5ikNuqwtZFejKL z=2ppE>=M^HlKZ^k|KO|NIY6`Rxc#FFZnKg*u0j<(Vk-VbRH@^~!lh4O2bWGIMzAMb zG!y32eO9$sS3n6Bn@RK7wT~mL;bunScSF|!j9uvZE^_QhmMQ4bkx1DV1E&o-pT&5~ zCNQ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I5o^YC{l0e( zH^w6TM(j&meClafhK#8fvaFlH)Nsd!e**oEU`&0DY3zW{qERT&HP=|8BTQ?Jadgc> zA9yHo9&rK$wkb~4qE)t*!MEa6F4|?gY;B80r{r?yD7Qt4`;T*_Lp|o2_BsxjHED*v zLp^2DVgo1DmMEm)sur82T!!Ulxp9hD13S09_gtJ(s{3dU$aqx8#)zLkY%XMhI9#ey zp2|O~ue=AYnsl|rdj+))Ui`AE{T^3mWxbEKzX1@ri?3h9F%cnaIEn}UEP0$2{T6pCvWA;cp|1kRx!-myOvFz< z7Xr6PLXIuEZ9heGPcYq*@5oo>O?gvqqrQduj_&CB=GDO1BNIdsy+Wg?YDCdAGmj=T zZbcEEkrTIKcj%Zm39vQZp%MLCuypFBJmdgjaWobv)AJTUD8r2~485=!zQ!+Pyl*(O kH`Wiz-i-c4SjqwShQ6rjYo=AW>*Tvl>B3KoP`32H0lnma>i_@% diff --git a/container/__pycache__/board.cpython-37.pyc b/container/__pycache__/board.cpython-37.pyc deleted file mode 100644 index 97003780794c1e0721b7f2548f7bf29872b5c157..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5136 zcma)ATW=f36`t7}msioUV#}Abtm>qu;kc=h-dw|V9LKSXNJ=dk3KlXpG-oN3;!U%w znkH6HGTOB0LkjevXxf4T`qDqq=b}Ghp9=Iz?*$6vrTxxXilQkS?Gkh5dd|$8`|wV& zm=pN^-T%{PzdS3%KdE!{nP}Wb2^#=PDA^WXT1!u&Z?uhd>YHt|V|kXOw$-*fj^}XO zZf82K=W^R=XFEAB*U5YNPQfd5ie6EQkA%u7_k~dIzTuUWTocvoA@&k0Rhh^u0M@z= z0@UvEZunI9dL6Xw_qT#>RJ9VP=7&*DC)sefUJt^srxSN8i2Qmlj1u!nBdimxqt8L( zHcI#eAP{r|&rnjyzznRw4xEOg3}wEMUPf8Uejz+pIVyuXt6Y^uol`lLN1ay%RYYA- zB{he-sLJXT>XMpQr%}(T1>EF~#JbwM-;!}*11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b78afab0b9e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 461 zcmZXR&q~8U5XLu6(xiW)2t|AZd-0$*DPn0u6EI21rc{PN4Nj0?+k|X9^x{+a625~E z;4|bZi187;=x$UhILrR#n~&LHU?an56CMxm_g7~UAupo%8x3BZ^UDStNKjf5AlLv2 zWoV!RGOD0p6I9fo$+Lz!=-7f5wxNw3=wKJRC{fZkDn5a@$(u|_^2Fy>JziHk0;+&m zq&gIsa`fe#??b9rj#~X1&s(GV6k5Ei(KpIwwz-K`ajDMjabT5A%d{s}P--LZV&=HC zRD5qvVb_^a%lABoE@&|H12DFRGrWZTsb^EqU2NU&w%$KqbgO}HnzU3WJh`CNX>knd z+_D4nk>q<~KY@>v(P=nian8alD)KZO$LzL9vyderwWr~Ax-Oz*9p^%^B3iSfY*Xrk YRf>1ZSbPs*2OPSrNcB;EvZU1N3wi!+5dZ)H diff --git a/container/__pycache__/graph.cpython-39.pyc b/container/__pycache__/graph.cpython-39.pyc deleted file mode 100644 index 5e56db1b7024d5becb6b528b2aacd09630049599..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1714 zcmZ`(%Wf1$6s<>hPkU?+2pnEPz#>Algb)kF0-*>AD=3>0(f|u%B^&%*{+t8U$Tb)9?9smivu+YIIYvo9b23K{#GI_pKE z^9t2IfO*3dQ~WFHiP)o_P!c_f9#=t+CE)<8&J}^)D^$A!qZ!t*J)yV~U)i2i5_06?93Sf>bb-~Q-wg$70x~T!G0Yh=l$?K`zJAevZ?&=g zNmiP1e^=Xsay;qVyx;rvZGSK>$}BIm=?_gd*?%(m;^H*Ti@Z!z3c+r{Fdi+x*_Arr zCyP~GBmrBB>`S9>5;nl7y`%#+9twmVAfnCL%FYwkCB3>YKbID=d9zwEVDT96EulJ zh=@avs(@3mPi&X{c5e=?d;+!uVIp{<66A3xyT_(cv+8BDisl~E*r_Z7#3isJRQx8Z zMEuz8OGauhsUCg_AcMzvyD0mWd0~fJ{{(}98nTDe_pKaEN{LJN;ep+F=wT=nsgg|168pV6ekl4&EGPlW` zmxycUHf=8XeN0>Ar=3bFb|6i0VV8u8b}!wvJAGc^EV?Uy$lJ{w`40t}SZU`6fbx%$f1}pr;v%E% z(WrDmp+A@Ad&I;;U8Z=u_9@Sn(#Lp!k92bl`iUD4d^LA!v7wv9W}A-gkhwy}KSDRj zyF-TPHk9o(GCVE*(vnKau{0F(IEXh%2`=tcEcz7XrWNLf!#Ikr9<-#AIIz z>6}mq;L6?!842k@Am4g#4$Ph|icC{*e>InYu>*jDGmaN9%vS(O8xoR+O14cvqoDCt zV-1HjZv>#IoT+=-lcMq(c1*X3bhgMDp6oYVe>k_gORP-tEsX1fU)>NvroQYwAPjaS zfpop0#@n^2&N1J5BQEkPN^+&g+4)7xIIG2=%qR8cGGm#||AGW7R^(BpERT!Sa$Ou+ zw=5D<z)zyr zVfynpemH(_ls4m3$)p&+RA#>_%5e#0FA%3{zq)6V@&D-#%9-`TFv*iD43P=52|%bz zefV7J@*OJ34)X!)>kBFeixV+c3k8q%VYEbk1EnETAX74!=`FGj&32nW>4AW4SbYI9 zr);TRw06YCGlS;3m+OKq!o83ZZ)-iFEsZ@T0KTA7{Mxyjx1Z;v!fPZb<7_Vy(JnCO*cLHIrUNpg=#J8;(y5pU@)?X6LdXKss Np5T*cBd$`9{R5A*2qpjk diff --git a/container/__pycache__/mushroom.cpython-39.pyc b/container/__pycache__/mushroom.cpython-39.pyc deleted file mode 100644 index 8ad4c811580bf94fc6a6207879e6bb95ceebc34a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1146 zcmZuwJ8#rL5Z;%4J}2Rs2LUNi;^rDE5CWti5Cx}55zWcM7_W2j;TOA(k~4-TDfkf- zNy%T@3W@6e0u9XAx#%Qrto?R&XLdY0-)y+H<`R$}U#1@pIU&Dsu_yu-FJS100Fp?W zl8lZhMV+N=#9kB0r8px}#PpPpxMcgpvu5B;JZh}HB#z=?gv&*NUv*)3K#9qSN-|=y zFNL(uC_`GBJ41yxY}1`#&hNaVHO)66{+E> zI5u`!B)Z6r7ANG*|>GiEA3fE=r}zv{3MvF8<-ptuT}tl z615J~pGUh-{C7H5+AqUO75>Xuf2xYo*NMOXX3zgW$w4_aP7ow{QUw9lU*7^C)TSVx8OI*+T;HBu2rA>*SQSd*Hpecfc;NJp|6!;MmB+ahK$;=L(-f%c#P9 zy}ojA0}H4yc_TiiNu^d%?N=(y^+BOBW9cYNMjKSB@c1@p+6Ex>0etn^RXNc*^mz9!+6;kcpaeT62#gy9Ss{;7)K`N5 zewKC?wF$x0eFUU_0r0PF^Wt?ifUD*g$r3cFy)m+$kOV98@&C z3XkBHikgm!ndI(-5EISMU!2(EZ~SbtSp&w`@yomK4B!X7+=M`JiW%-9UV#S94w#>L z4Vu4(Qgk?f8xqwiX1I?qP%{lR*DEcwJg{2mOy>uvrDnLYNV0O;R6p@o=vG7w8ad{3 z%y3>mZ@bt#n`Gxg zELTYeGrafY%+rB=M#u?N-4}>&;Hf9SA9p9s+hBZX2BUk|yf9%O-PnxYIY-=?eS8r5 zrgJv7y*0kEXlgrNrb4OS_E9M+6pj(V^4sTXL*}%qN?H^6B z;}hHQ{h|eGajhk4Nt!xK_cC`xRBv9ESz7m@w;{H+Gaj!O{&8M%e+Oq%=Hf@=XWI*o zXf{{MoGV2-P>X)S1&41L&M(?w`QoV` o{w{&~{1>Rwd`#Lg(ESu_UCc98$rc0uS(1t;OQol@?iVKf0Z+r1SpWb4 diff --git a/container/__pycache__/piece.cpython-37.pyc b/container/__pycache__/piece.cpython-37.pyc deleted file mode 100644 index bc840f0af22605ce26b0fc82e2cca199bcfe7296..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 741 zcmYjPy>8S%5T5<9<6Lskgd&K7g2qiAAVMetB&beEh~{KzG2Xps9iMG>9UXUacXF@BZi4ngRT!&A|kcD|G)HL4#%uEa3xa zuEiZ_vFA&s*=NY*1IA%d5gv>qxkC3Z5Def+SaQuYzk{XFLQ7nwPB1$S$tPT zt>o{}{VN2`Mo=(f@;M-5$V6mV5cfg@HL(cbZ~}NB$Yqdixi&#mT@!@sHbL0+bF00Gpi#N^}jnTF%-Wz{2bbZmguImVEb2Gg3wy3&xC~a$8(Nn`0 z{WfGu+13t9C0NO42*6S{!)Ny-PIYlOP?4Hsv>v0!@jfCM**y%b=J#TRS`NvGW1YjE zMTR5q*^2+-7)z(f8H!LJA;;JmP>kW%K?%en3g9Fb&9flCHFgMTzr7|Qjt5t^e$}~k zNPJZ`#!Ejj_Q(Bo~Fromc}fjN5FLLcO}AaRltU3mF1b{k5ki%U1YA~?DlV%?CdA&#OEw91s%2NXZ6*Fj zIr5i$<$ot}Wgf|Fv(s!rS8J<8@KBO<&r^xT2$0FS5TGrYvPPXIHdzpyK+r)^YP8tb}}la?OC4C zY-sRGg^5zDR^QdcPnE)w^%!weOn1)+sL%n>4UX#4s6463c$UVUoV%y{=s`v-5F5+h NjJLg|_m9nG{69^boWKA8 diff --git a/container/__pycache__/state.cpython-39.pyc b/container/__pycache__/state.cpython-39.pyc deleted file mode 100644 index f4429c693bb656bc93f17c5a30c8a612a138e5a7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 490 zcmY*V!AiqG5S`s55{s=Meu1}Mif0iiR1hykD7}P*b;+(JnkIF33#|k%_GkPQe_^kF zf;UgjBoyj|_hx7F=1nH5-|qp&`(X3O}rM#`ht#L2DUI|x-+5Lma>&mO5GFG&fqt!N~QWjO=r6gC^{zP`vJ^XFZ?l;;? zrnoZdE44IIhMttmTCYnwpGf(-R%Q3bl1uwN2Xst#42j@qSjyUZI_&a+mR7OU5Yp>z K#0_=*Am9%V+-9o) diff --git a/container/__pycache__/tree.cpython-37.pyc b/container/__pycache__/tree.cpython-37.pyc deleted file mode 100644 index 8d28d36ce8d9169346ea018fd87b42ed849c4ffe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 632 zcmZ8e!EV$r5S_7|C0gyOAR#JlNL^uc7%cuvUQlZTfC2DhMLi$**JVn|GmObqf=-6Td0ldZVKLomr9{NU3M z46yvtv)Cwq&p9@aE7uKW-C17@lsJsIQH#D?WocAh+1e;8*F@>v_c-a-E8a=!wp`h$ z8dsVq!{DQ=+f^o`3by$g<%M4R8Oh&*KcMN?tLk;}IanWx#+up{A8a@qTwnCwImdWv z&xU8AF8-}%(XV5wb=}p2*4%-R5&%wcN@FwURxS4NWrpLsGR1eeaINE1>(-g`hWSkE zZ|7yRi}*(*G#2+4JmfuY5dVG<1SyW|OyviEN?Y{&x1PhE>)ExG-}#?ZOyBI1zvWg3 J7M)=#egpigkyZcz diff --git a/container/__pycache__/tree.cpython-39.pyc b/container/__pycache__/tree.cpython-39.pyc deleted file mode 100644 index b4f5ce55dfb70fbb892ac4d8b033a481025055cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 634 zcmZ8eO>5jR5S@|atyy+S3niiFUh2yRdJ3h4KmwtcC6JVYF{s8;7B~Ki1`JkEV~WUJ zR3a6pV5CtGV3fssnMxzhA&H)7HzXLMv(grJUU0Z=l7b_0ze`{tMFXiYkr75dAc-gv z83lFWtaa2D6nx;tm`CKt4@|TNKY8~n z16*S6SZpZq#C2A0i?-?Wvav4fskk3-rDk2TNaCQHytY9WZ55>wIB@ zs@mKH>3bJsSuYY9l(*Gokav3NCM5q0+z$Po_m4kiU%hoc>+;^U*@^X6ecNTe%+9}@ zW&idt>y{zbx@^i`YreOS2>?eprf)UnA 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]) - diff --git a/container/mushroom.py b/container/mushroom.py deleted file mode 100644 index 70aa786..0000000 --- a/container/mushroom.py +++ /dev/null @@ -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))) - - - diff --git a/container/tree.py b/container/tree.py deleted file mode 100644 index 5476b73..0000000 --- a/container/tree.py +++ /dev/null @@ -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') - - - - diff --git a/container/__init__.py b/core/__init__.py similarity index 100% rename from container/__init__.py rename to core/__init__.py diff --git a/core/a_star.py b/core/a_star.py new file mode 100644 index 0000000..f3af1eb --- /dev/null +++ b/core/a_star.py @@ -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)) diff --git a/container/agent.py b/core/agent.py similarity index 88% rename from container/agent.py rename to core/agent.py index c640c22..517b777 100644 --- a/container/agent.py +++ b/core/agent.py @@ -1,96 +1,104 @@ -import pygame -from container.piece import Piece - - -class Agent(Piece): - def __init__(self,x_y, square_size): - self.name = "Agent" - self.col = x_y[0] - self.row = x_y[1] - self.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.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] - - #win.blit(self.img, (x, y)) - - self.blitRotate(win, self.img, (x, y), (self.square_size[0]/2, self.square_size[1]/2), self.angle*90 + self.rotating*90/10) - - def rotate(self, angle): - if self.moving == self.rotating == 0: - self.rotating += angle - - def move(self): - if self.moving == self.rotating == 0: - move_to = (0,-1) - if self.angle == 1: move_to = (-1,0) - if self.angle == 2: move_to = (0,1) - if self.angle == 3: move_to = (1,0) - - self.move_to = (self.col + move_to[0], self.row + move_to[1]) - - self.moving += 1 - - def update_animation(self): - if self.moving > 0: - self.moving += 1 - if self.moving >= 10: - self.moving = 0 - self.col, self.row = self.move_to - - if self.rotating > 0: - self.rotating += 1 - if self.rotating >= 10: - self.rotating = 0 - self.angle = (self.angle + 1) % 4 - if self.rotating < 0: - self.rotating -= 1 - if self.rotating <= -10: - self.rotating = 0 - self.angle = (self.angle - 1) % 4 - - - def blitRotate(self, surf, image, pos, originPos, angle): - - # calcaulate the axis aligned bounding box of the rotated image - w, h = image.get_size() - box = [pygame.math.Vector2(p) for p in [(0, 0), (w, 0), (w, -h), (0, -h)]] - box_rotate = [p.rotate(angle) for p in box] - min_box = (min(box_rotate, key=lambda p: p[0])[0], min(box_rotate, key=lambda p: p[1])[1]) - max_box = (max(box_rotate, key=lambda p: p[0])[0], max(box_rotate, key=lambda p: p[1])[1]) - - # calculate the translation of the pivot - pivot = pygame.math.Vector2(originPos[0], -originPos[1]) - pivot_rotate = pivot.rotate(angle) - pivot_move = pivot_rotate - pivot - - # calculate the upper left origin of the rotated image - origin = (pos[0] - originPos[0] + min_box[0] - pivot_move[0], pos[1] - originPos[1] - max_box[1] + pivot_move[1]) - - # get a rotated image - rotated_image = pygame.transform.rotate(image, angle) - - # rotate and blit the image - surf.blit(rotated_image, origin) - - # draw rectangle around the image - #pygame.draw.rect(surf, (255, 0, 0), (*origin, *rotated_image.get_size()),2) - - - - - - - - +import os + +import pygame +from core.piece import Piece + + +class Agent(Piece): + def __init__(self,x_y, square_size): + self.name = "Agent" + 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'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] + + #win.blit(self.img, (x, y)) + + self.blitRotate(win, self.img, (x, y), (self.square_size[0]/2, self.square_size[1]/2), self.angle*90 + self.rotating*90/10) + + 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: + move_to = (0,-1) + if self.angle == 1: move_to = (-1,0) + if self.angle == 2: move_to = (0,1) + if self.angle == 3: move_to = (1,0) + + self.move_to = (self.col + move_to[0], self.row + move_to[1]) + + self.moving += 1 + + def update_animation(self): + if self.moving > 0: + self.moving += 1 + if self.moving >= 10: + self.moving = 0 + self.col, self.row = self.move_to + + if self.rotating > 0: + self.rotating += 1 + if self.rotating >= 10: + self.rotating = 0 + self.angle = (self.angle + 1) % 4 + if self.rotating < 0: + self.rotating -= 1 + if self.rotating <= -10: + self.rotating = 0 + self.angle = (self.angle - 1) % 4 + + + def blitRotate(self, surf, image, pos, originPos, angle): + + # calcaulate the axis aligned bounding box of the rotated image + w, h = image.get_size() + box = [pygame.math.Vector2(p) for p in [(0, 0), (w, 0), (w, -h), (0, -h)]] + box_rotate = [p.rotate(angle) for p in box] + min_box = (min(box_rotate, key=lambda p: p[0])[0], min(box_rotate, key=lambda p: p[1])[1]) + max_box = (max(box_rotate, key=lambda p: p[0])[0], max(box_rotate, key=lambda p: p[1])[1]) + + # calculate the translation of the pivot + pivot = pygame.math.Vector2(originPos[0], -originPos[1]) + pivot_rotate = pivot.rotate(angle) + pivot_move = pivot_rotate - pivot + + # calculate the upper left origin of the rotated image + origin = (pos[0] - originPos[0] + min_box[0] - pivot_move[0], pos[1] - originPos[1] - max_box[1] + pivot_move[1]) + + # get a rotated image + rotated_image = pygame.transform.rotate(image, angle) + + # rotate and blit the image + surf.blit(rotated_image, origin) + + # draw rectangle around the image + #pygame.draw.rect(surf, (255, 0, 0), (*origin, *rotated_image.get_size()),2) + + + + + + + + \ No newline at end of file diff --git a/container/board.py b/core/board.py similarity index 54% rename from container/board.py rename to core/board.py index a6bb551..abc7627 100644 --- a/container/board.py +++ b/core/board.py @@ -1,156 +1,158 @@ -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 - -class Board: - def __init__(self, x = 0, y = 0, width = WIDTH, height = HEIGHT, row = ROWS, col = COLUMNS): - self.x = x - self.y = y - self.width = width - self.height = height - self.row = row - self.col = col - self.square_size = (self.width / self.col, self.height / self.row) - self.board = [[False for j in range(self.row)] for i in range(self.col)] - self.free_spaces = [] - self.update_free_spaces() - - self.agent = Agent(self.free_spaces.pop(), self.square_size) - - print(f"Board {col}x{row} with agent on ({self.agent.col},{self.agent.row}) {self.agent.angle}") - - self.surface = pygame.Surface((self.width, self.height)) - - for i in range(TREES): - 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.grow_next = 0 - - self.path = [] - self.actions = [] - - def update_free_spaces(self): - self.free_spaces = [] - - for x in range(self.col): - for y in range(self.row): - if self.board[x][y] == False: self.free_spaces.append((x,y)) - - random.shuffle(self.free_spaces) - - 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])) - - win.blit(self.surface, (self.x, self.y)) - - def draw_agent(self,win): - self.agent.draw(self.surface) - win.blit(self.surface, (self.x, self.y)) - - 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): - 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)) - - # kolumna agneta - 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)) - - # kierunek agenta - 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) - - - #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 - - 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.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) - - 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)) - ) - - print(self.actions) - - return self.actions - - - +import random + +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): + self.x = x + self.y = y + self.width = width + self.height = height + self.row = row + self.col = col + self.square_size = (self.width / self.col, self.height / self.row) + 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) + + print(f"Board {col}x{row} with agent on ({self.agent.col},{self.agent.row}) {self.agent.angle}") + + self.surface = pygame.Surface((self.width, self.height)) + + for i in range(TREES): + 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)) + + self.grow_next = 0 + + self.path = [] + self.actions = [] + + def update_free_spaces(self): + self.free_spaces = [] + + for x in range(self.col): + for y in range(self.row): + if self.board[x][y] == False: self.free_spaces.append((x, y)) + + random.shuffle(self.free_spaces) + + 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])) + + win.blit(self.surface, (self.x, self.y)) + + def draw_agent(self, win): + self.agent.draw(self.surface) + win.blit(self.surface, (self.x, self.y)) + + 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): + 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)) + + # kolumna agneta + 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)) + + # kierunek agenta + 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) + + # 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 + + 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.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), 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)) + ) + + print(self.actions) + + return self.actions diff --git a/container/constans.py b/core/constans.py similarity index 67% rename from container/constans.py rename to core/constans.py index 25012d0..e0dddfe 100644 --- a/container/constans.py +++ b/core/constans.py @@ -1,21 +1,21 @@ -import pygame - -#board size variables -WIDTH = 1000 -HEIGHT = 700 -COLUMNS = 20 -ROWS = 14 - -#number of mushrooms - -MUSHROOMS_START = 5 -MUSHROOMS_MAX = 10 -POISON_MUSHROOMS_START = 5 -POISON_MUSHROOMS_MAX = 40 -TREES = 80 - - -#colors in game in rgb -GREEN = (0,230,0) -GREEN_2 = (0,200,0) -WHITE = (255,255,255) +import pygame + +#board size variables +WIDTH = 1000 +HEIGHT = 700 +COLUMNS = 20 +ROWS = 14 + +#amount of mushrooms on the board + +MUSHROOMS_START = 5 +MUSHROOMS_MAX = 10 +POISON_MUSHROOMS_START = 5 +POISON_MUSHROOMS_MAX = 40 +TREES = 80 + + +#colors of board in game in rgb +GREEN = (0,230,0) +GREEN_2 = (0,200,0) +#WHITE = (255,255,255) diff --git a/core/decision_tree.py b/core/decision_tree.py new file mode 100644 index 0000000..8023586 --- /dev/null +++ b/core/decision_tree.py @@ -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]) diff --git a/core/mushroom.py b/core/mushroom.py new file mode 100644 index 0000000..aea72da --- /dev/null +++ b/core/mushroom.py @@ -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)) diff --git a/container/node.py b/core/node.py similarity index 91% rename from container/node.py rename to core/node.py index a2ed0a8..1b29633 100644 --- a/container/node.py +++ b/core/node.py @@ -1,15 +1,15 @@ - -class Node: - def __init__(self, x, y, angle = None, parent = None, action = 0, cost=0): - self.x = x - self.y = y - self.angle = angle - self.parent = parent - self.action = action - self.cost = cost - - def __eq__(self, other): - if isinstance(other, Node) and (self.x == other.x and self.y == other.y and self.angle == other.angle): - return True - else: + +class Node: + def __init__(self, x, y, angle = None, parent = None, action = 0, cost=0): + self.x = x + self.y = y + self.angle = angle + self.parent = parent + self.action = action + self.cost = cost + + def __eq__(self, other): + if isinstance(other, Node) and (self.x == other.x and self.y == other.y and self.angle == other.angle): + return True + else: return False \ No newline at end of file diff --git a/container/piece.py b/core/piece.py similarity index 70% rename from container/piece.py rename to core/piece.py index 282ea6e..a0ee483 100644 --- a/container/piece.py +++ b/core/piece.py @@ -1,15 +1,18 @@ -import pygame - -class Piece: - - def __init__(self,x_y): - self.name = "" - self.col = x_y[0] - self.row = x_y[1] - self.img = '' - - 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])) - - - +import pygame + +class Piece: + + 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])) + + + diff --git a/container/detective.png b/core/resources/agent/detective.png similarity index 100% rename from container/detective.png rename to core/resources/agent/detective.png diff --git a/container/new_detective.png b/core/resources/agent/new_detective.png similarity index 100% rename from container/new_detective.png rename to core/resources/agent/new_detective.png diff --git a/core/resources/data/data_tree.csv b/core/resources/data/data_tree.csv new file mode 100644 index 0000000..1bc9685 --- /dev/null +++ b/core/resources/data/data_tree.csv @@ -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,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1,1,1,1,0,1,1,1 +1,1,1,1,1,0,1,1,1 +0,0,0,0,0,1,1,1,0 +1,0,0,0,0,1,1,1,0 +0,1,0,0,0,1,1,1,0 +1,1,0,0,0,1,1,1,1 +0,0,1,0,0,1,1,1,0 +1,0,1,0,0,1,1,1,1 +0,1,1,0,0,1,1,1,1 +1,1,1,0,0,1,1,1,1 +0,0,0,1,0,1,1,1,0 +1,0,0,1,0,1,1,1,1 +0,1,0,1,0,1,1,1,1 +1,1,0,1,0,1,1,1,1 +0,0,1,1,0,1,1,1,1 +1,0,1,1,0,1,1,1,1 +0,1,1,1,0,1,1,1,1 +1,1,1,1,0,1,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 \ No newline at end of file diff --git a/container/mushrooms/m0.png b/core/resources/mushrooms/m0.png similarity index 100% rename from container/mushrooms/m0.png rename to core/resources/mushrooms/m0.png diff --git a/container/mushrooms/m1.png b/core/resources/mushrooms/m1.png similarity index 100% rename from container/mushrooms/m1.png rename to core/resources/mushrooms/m1.png diff --git a/container/mushrooms/m2.png b/core/resources/mushrooms/m2.png similarity index 100% rename from container/mushrooms/m2.png rename to core/resources/mushrooms/m2.png diff --git a/container/mushrooms/pm0.png b/core/resources/mushrooms/pm0.png similarity index 100% rename from container/mushrooms/pm0.png rename to core/resources/mushrooms/pm0.png diff --git a/container/mushrooms/pm1.png b/core/resources/mushrooms/pm1.png similarity index 100% rename from container/mushrooms/pm1.png rename to core/resources/mushrooms/pm1.png diff --git a/container/mushrooms/pm2.png b/core/resources/mushrooms/pm2.png similarity index 100% rename from container/mushrooms/pm2.png rename to core/resources/mushrooms/pm2.png diff --git a/container/trees/tree0.png b/core/resources/trees/tree0.png similarity index 100% rename from container/trees/tree0.png rename to core/resources/trees/tree0.png diff --git a/container/trees/tree1.png b/core/resources/trees/tree1.png similarity index 100% rename from container/trees/tree1.png rename to core/resources/trees/tree1.png diff --git a/container/trees/tree2.png b/core/resources/trees/tree2.png similarity index 100% rename from container/trees/tree2.png rename to core/resources/trees/tree2.png diff --git a/container/trees/tree3.png b/core/resources/trees/tree3.png similarity index 100% rename from container/trees/tree3.png rename to core/resources/trees/tree3.png diff --git a/container/trees/tree4.png b/core/resources/trees/tree4.png similarity index 100% rename from container/trees/tree4.png rename to core/resources/trees/tree4.png diff --git a/container/trees/tree5.png b/core/resources/trees/tree5.png similarity index 100% rename from container/trees/tree5.png rename to core/resources/trees/tree5.png diff --git a/container/trees/tree6.png b/core/resources/trees/tree6.png similarity index 100% rename from container/trees/tree6.png rename to core/resources/trees/tree6.png diff --git a/container/trees/tree7.png b/core/resources/trees/tree7.png similarity index 100% rename from container/trees/tree7.png rename to core/resources/trees/tree7.png diff --git a/container/trees/tree8.png b/core/resources/trees/tree8.png similarity index 100% rename from container/trees/tree8.png rename to core/resources/trees/tree8.png diff --git a/core/tree.py b/core/tree.py new file mode 100644 index 0000000..6b3ebb3 --- /dev/null +++ b/core/tree.py @@ -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') diff --git a/main.py b/main.py index 882e5a0..ca47f18 100644 --- a/main.py +++ b/main.py @@ -1,71 +1,58 @@ -import pygame -from container.constans import WIDTH, HEIGHT, ROWS, COLUMNS, GREEN -from container.board import Board - - -FPS = 18 - - -#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') - - -def main(): - - run = True - clock = pygame.time.Clock() #for fps - board = Board(0,40,WIDTH,HEIGHT-40) - - - while run: - clock.tick(FPS) - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - run = False - - - #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 - WIN.fill(GREEN) - board.update_agent() #update moves and collecting mushrooms - board.grow_mushrooms() - - board.draw_squares(WIN) - board.draw_pieces(WIN) - board.draw_agent(WIN) - board.draw_info(WIN) - - pygame.display.update() - - - if key_input[pygame.K_SPACE]: - board.a_starxd() - - if(board.agent.rotating==0 and board.agent.moving==0): - board.a_starxd() - - - - - pygame.quit() - -main() - - - - - +import pygame + +from core.board import Board +from core.constans import WIDTH, HEIGHT, GREEN + +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 +pygame.display.set_caption('Forest') +pygame.font.init() + +# 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) + + while run: + clock.tick(FPS) + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + run = False + + # 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 + WIN.fill(GREEN) + board.update_agent() # update moves and collecting mushrooms + board.grow_mushrooms() + + board.draw_squares(WIN) + board.draw_pieces(WIN) + board.draw_agent(WIN) + board.draw_info(WIN) + + pygame.display.update() + + if key_input[pygame.K_SPACE]: + board.a_starxd() + + if board.agent.rotating == 0 and board.agent.moving == 0: + board.a_starxd() + pygame.quit() + + +main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6de3877 --- /dev/null +++ b/requirements.txt @@ -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