From acaeda970f33479524dce123a469baec749bcfa3 Mon Sep 17 00:00:00 2001 From: Richard Feistenauer Date: Sun, 17 Feb 2019 11:11:27 +0100 Subject: [PATCH] changed project structure --- .gitignore | 3 ++- LICENSE.txt | 0 MANIFEST.in | 1 + README.md | 0 __init__.py | 1 + cellular_automaton/__init__.py | 6 ++++++ .../ca_cell.py => cellular_automaton/_cell.py | 2 +- .../_state.py | 2 +- .../automaton.py | 0 .../cell_state.py | 0 .../display.py | 3 +-- .../factory.py | 4 +++- .../neighborhood.py | 0 .../ca_rule.py => cellular_automaton/rule.py | 4 ++-- scripts/main_ui.py => examples/basic_2d_ca.py | 4 +--- images/map.png | Bin 2190054 -> 0 bytes scripts/performance_test | Bin 2895 -> 0 bytes setup.py | 14 ++++++++++++++ src/cellular_automaton/__init__.py | 8 -------- test/test_cell.py | 2 +- test/test_cell_state.py | 2 +- test/test_factory.py | 2 +- test/test_neighborhood.py | 2 +- 23 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 LICENSE.txt create mode 100644 MANIFEST.in create mode 100644 README.md create mode 100644 __init__.py create mode 100644 cellular_automaton/__init__.py rename src/cellular_automaton/ca_cell.py => cellular_automaton/_cell.py (94%) rename src/cellular_automaton/ca_state.py => cellular_automaton/_state.py (83%) rename src/cellular_automaton/cellular_automaton.py => cellular_automaton/automaton.py (100%) rename src/cellular_automaton/ca_cell_state.py => cellular_automaton/cell_state.py (100%) rename src/cellular_automaton/ca_display.py => cellular_automaton/display.py (96%) rename src/cellular_automaton/ca_factory.py => cellular_automaton/factory.py (90%) rename src/cellular_automaton/ca_neighborhood.py => cellular_automaton/neighborhood.py (100%) rename src/cellular_automaton/ca_rule.py => cellular_automaton/rule.py (87%) rename scripts/main_ui.py => examples/basic_2d_ca.py (90%) delete mode 100644 images/map.png delete mode 100644 scripts/performance_test create mode 100644 setup.py delete mode 100644 src/cellular_automaton/__init__.py diff --git a/.gitignore b/.gitignore index bce6882..9784317 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ __pycache__ .coverage htmlcov/ -*.orig \ No newline at end of file +*.orig +performance.txt \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..e69de29 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..bd133bb --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include cellular_automaton/examples * \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..79356a6 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from .cellular_automaton import * \ No newline at end of file diff --git a/cellular_automaton/__init__.py b/cellular_automaton/__init__.py new file mode 100644 index 0000000..aa0e537 --- /dev/null +++ b/cellular_automaton/__init__.py @@ -0,0 +1,6 @@ +from .cell_state import * +from .neighborhood import * +from .rule import * +from .factory import * +from .automaton import * +from .display import * diff --git a/src/cellular_automaton/ca_cell.py b/cellular_automaton/_cell.py similarity index 94% rename from src/cellular_automaton/ca_cell.py rename to cellular_automaton/_cell.py index e42e886..ff487b5 100644 --- a/src/cellular_automaton/ca_cell.py +++ b/cellular_automaton/_cell.py @@ -1,4 +1,4 @@ -from cellular_automaton.ca_cell_state import CellState +from .cell_state import CellState from typing import Type diff --git a/src/cellular_automaton/ca_state.py b/cellular_automaton/_state.py similarity index 83% rename from src/cellular_automaton/ca_state.py rename to cellular_automaton/_state.py index ac5f789..e5792e7 100644 --- a/src/cellular_automaton/ca_state.py +++ b/cellular_automaton/_state.py @@ -1,4 +1,4 @@ -from cellular_automaton.ca_rule import Rule +from cellular_automaton.cellular_automaton import Rule from typing import Type diff --git a/src/cellular_automaton/cellular_automaton.py b/cellular_automaton/automaton.py similarity index 100% rename from src/cellular_automaton/cellular_automaton.py rename to cellular_automaton/automaton.py diff --git a/src/cellular_automaton/ca_cell_state.py b/cellular_automaton/cell_state.py similarity index 100% rename from src/cellular_automaton/ca_cell_state.py rename to cellular_automaton/cell_state.py diff --git a/src/cellular_automaton/ca_display.py b/cellular_automaton/display.py similarity index 96% rename from src/cellular_automaton/ca_display.py rename to cellular_automaton/display.py index 1982786..505c24e 100644 --- a/src/cellular_automaton/ca_display.py +++ b/cellular_automaton/display.py @@ -7,8 +7,7 @@ import pstats from pympler import asizeof -from cellular_automaton.ca_state import CellularAutomatonState -from cellular_automaton.cellular_automaton import CellularAutomatonProcessor +from . import CellularAutomatonState, CellularAutomatonProcessor class _DisplayInfo: diff --git a/src/cellular_automaton/ca_factory.py b/cellular_automaton/factory.py similarity index 90% rename from src/cellular_automaton/ca_factory.py rename to cellular_automaton/factory.py index ce2f9fa..fdb5679 100644 --- a/src/cellular_automaton/ca_factory.py +++ b/cellular_automaton/factory.py @@ -1,4 +1,6 @@ -from cellular_automaton import * +from . import Neighborhood, CellState, Rule +from ._cell import Cell +from ._state import CellularAutomatonState from typing import Type import itertools diff --git a/src/cellular_automaton/ca_neighborhood.py b/cellular_automaton/neighborhood.py similarity index 100% rename from src/cellular_automaton/ca_neighborhood.py rename to cellular_automaton/neighborhood.py diff --git a/src/cellular_automaton/ca_rule.py b/cellular_automaton/rule.py similarity index 87% rename from src/cellular_automaton/ca_rule.py rename to cellular_automaton/rule.py index aa744ab..799b21b 100644 --- a/src/cellular_automaton/ca_rule.py +++ b/cellular_automaton/rule.py @@ -11,7 +11,7 @@ class Rule: """ Calculates and sets new state of 'cell'. :param last_cell_state: The cells current state to calculate new state for. :param neighbors_last_states: The cells neighbors current states. - :return: True if state changed, False if not. + :return: New state. A cells evolution will only be called if it or at least one of its neighbors has changed last evolution_step cycle. """ - return False + return last_cell_state diff --git a/scripts/main_ui.py b/examples/basic_2d_ca.py similarity index 90% rename from scripts/main_ui.py rename to examples/basic_2d_ca.py index ad3e26e..5344735 100644 --- a/scripts/main_ui.py +++ b/examples/basic_2d_ca.py @@ -1,8 +1,7 @@ #!/usr/bin/env python3 import random -from cellular_automaton.ca_rule import Rule -from cellular_automaton.ca_cell_state import CellState, SynchronousCellState +from cellular_automaton import * class TestRule(Rule): @@ -29,7 +28,6 @@ class MyState(CellState): if __name__ == "__main__": - from cellular_automaton import * # best single is 400/400 with 0,2 ca speed and 0,09 redraw / multi is 300/300 with 0.083 neighborhood = MooreNeighborhood(EdgeRule.FIRST_AND_LAST_CELL_OF_DIMENSION_ARE_NEIGHBORS) ca = CAFactory.make_cellular_automaton(dimension=[100, 100], diff --git a/images/map.png b/images/map.png deleted file mode 100644 index b18b2171b3859c54e3e19742ac1a6927f44b05ac..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2190054 zcmeIuF%5t~5Cp&lOwiJy00HzEK^=M!KyU&7FHtNtX-bpC36i1&3S@DX&u1C>;*Tf! z-w03KMf}ZyDSrO!h(#mf(ulY;B3U#dx2F-&nGnHHrouChHw`TY?9_t zvy$sLCh=lRAiqCmm4Sh*0JbHEf=LxsE3$3~TC6ebNk}jKbac_P2MC?M?&N{81KlLf z@&WI0or7^)vq1o5gArdK@86K;vkaYkcIVz3g@*~+t`?g&YA_1ZDU@}aKeEq=Fml$ye{0XYPH24pl@SZHgBkYy zU{I(MaGIQep6^GYENLXJPGg{1v%z77nuZKlO*f=Q2-)`pTpcvD@8@$5_dN3)p+~;c z5*^pp6Sz87fif&mHVh1$Q$Kh&{4@;jrx4ygBdv~8c>OlPF9!zrWHi*A_3Q4xKI$a2 zyf%7Mdgla|q#b++2FFVe!TnuO!f5D>o>hyDnQ$#yu3p+P{-^gz?ydN9PQ7nWHzRb( zOI_WAx;7F>$5N*T>5b$#Q5Mq#g?e74lIKp1zFIr2wPO{b{ym%+Ilh6o*#&WXsVBP} zRgdg~#L&>!T35F9Zh4!~|$ zWjz;=iLsow`k~V_@ro>ZsQ)q`xamy0LFm?^vfiGmHH3||qh#7-8#}kMc7aLgvhCZF z7e8B*$!;cwDa9!6+2v%H@xu-K zv4!Vb=hlM(Mne0F2a!8`tw3jvy##BuiVa)QYi44!mipqnY_ zp2%N(eyK)EJx{2!h_i{eMsq&77$+JV2T(R1@!8p&*xpgUchOct*OlpgH!ki6g>ro6 zU>u*x2xd^i3A`e}?16TtE1CiRJKFPomZ8_bS@-I=AD~e<3%od%TG%bw2;`I9T{}8E zYYy#%6LS_096K_@mIUz3CC}?^Yp+=yCDd6saBMNG)P`rOeR_N0lz(D7U|OXY>^>Wk zDH+zh#eC%WazdR2CX3_K8diy6=^5J08FCEICz*%e%E8b{$F#?X6kiQfacXc*i=M!{ z1VcnO7(5}u76yLCG|^Nfm?_pDci8C$Ek^J6fB{uAt@VxJn@|0>7F0dFd&QcnzrV6- z5J@Jn4JHQJBt63BY;i+iJ7f=8A?$&SQ<-k~`ss%2hj$X%Ibi6BfSpW62Q~%q`TgP1 z|5S91+OPoP3$jwqe`Vi=;`Xy)`tGP1TQ}PNQ+aEXfb*p$S4T}*F)C!$ACutaCHk%3 zvZ@EAW=Zghm*WW|S71L+mHV|ie>tbMY{yL7?f; z()r|KJTX}a@!2FlshanFNy#Wezbv2L`hfw3=h=`dyR)2%q~e3_v)B$;WmVRFqM`61GR9;QUCw| diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6977244 --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +from distutils.core import setup + +setup( + name="cellular_automaton", + version="0.1.0", + author="Richard Feistenauer", + author_email="r.feistenauer@web.de", + packages=["cellular_automaton"], + url="https://gitlab.com/DamKoVosh/cellular_automaton", + license="LICENSE.txt", + description="N dimensional cellular automaton implementation with multi processing capability.", + long_description="README.md", + requires=["pygame"] +) diff --git a/src/cellular_automaton/__init__.py b/src/cellular_automaton/__init__.py deleted file mode 100644 index c5cd890..0000000 --- a/src/cellular_automaton/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from .ca_cell import * -from .ca_cell_state import * -from .ca_display import * -from .ca_neighborhood import * -from .ca_rule import * -from .ca_state import * -from .cellular_automaton import * -from .ca_factory import * diff --git a/test/test_cell.py b/test/test_cell.py index 1ff3996..9b6d439 100644 --- a/test/test_cell.py +++ b/test/test_cell.py @@ -1,7 +1,7 @@ import sys sys.path.append('../src') -from cellular_automaton import * +from cellular_automaton.cellular_automaton import * import unittest diff --git a/test/test_cell_state.py b/test/test_cell_state.py index 42b802a..30f3396 100644 --- a/test/test_cell_state.py +++ b/test/test_cell_state.py @@ -1,7 +1,7 @@ import sys sys.path.append('../src') -import cellular_automaton.ca_cell_state as cs +from cellular_automaton import cellular_automaton as cs import unittest diff --git a/test/test_factory.py b/test/test_factory.py index 7558110..116e8ac 100644 --- a/test/test_factory.py +++ b/test/test_factory.py @@ -1,7 +1,7 @@ import sys sys.path.append('../src') -from cellular_automaton import * +from cellular_automaton.cellular_automaton import * import unittest import mock diff --git a/test/test_neighborhood.py b/test/test_neighborhood.py index fde97a5..6241672 100644 --- a/test/test_neighborhood.py +++ b/test/test_neighborhood.py @@ -1,7 +1,7 @@ import sys sys.path.append('../src') -import cellular_automaton.ca_neighborhood as csn +from cellular_automaton import cellular_automaton as csn import unittest