commit 14a43f82141216bdff211fb47e1da443d98551b4 Author: Suwako Moriya Date: Fri May 29 21:28:00 2020 +0200 Initial Commit diff --git a/CdC.md b/CdC.md new file mode 100644 index 0000000..952d3cd --- /dev/null +++ b/CdC.md @@ -0,0 +1,20 @@ +Cahier des charges +== + +Le jeu +-- +C'est un jeu multijoueur basé sur le jeu de la vie. Il doit supporter pleins de règles donc je vais utiliser lifelib. +L'objectif d'un joueur est d'avoir le contrôle sur le plus grand nombre de cellules *(coucou le go)* +Les objectifs +-- +- Support pour autant de joueur qu'on puisse imaginer *(on fait un mmo ?)* +- Permettre de copier des RLE dans le jeu +- Des performances potables, du dezoom a la golly +- Une interface graphique sympa (HUD, Boutons, Menus) +- Une structure correcte (séparation en sous-modules) +- ~~Moddable ?? (on part sur non quand même)~~ + +Les idées +-- +- Envisager une structure p2p et une structure centralisée +- Des zones de "spawn" pour les joueurs qu'ils peuvent éditer lors de certains ticks diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..7c2dccb --- /dev/null +++ b/Pipfile @@ -0,0 +1,13 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] +spyder = "*" + +[packages] +pygame = "*" + +[requires] +python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..2aea493 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,53 @@ +{ + "_meta": { + "hash": { + "sha256": "e172a3e30534a9a0b74742497b40f2ab196a0890d1cb082eb481fb89e384456e" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "pygame": { + "hashes": [ + "sha256:0480fe82cd41a43e3eea497fa2c059c72ac54cb5d003d5aa2ed06a04541c384e", + "sha256:136a3b5711d9ec369a0407e4e08ffced3ba61aa41059e9280ffffa79c8614f65", + "sha256:2622b9dd95f445c887a36a57eade42c672598589f69a8052ccdb8eeeffa4dbb1", + "sha256:301c6428c0880ecd4a9e3951b80e539c33863b6ff356a443db1758de4f297957", + "sha256:396320aa29a925feed0b64639f77ce1418722ea7f536b4e4936083dd8d4c4535", + "sha256:398c42b605ecc514e62f68f1944a2d21e247938309f598de6cb0ad3c207324a8", + "sha256:4aaff572a273a32e70ec3593d213e59ab11c183a9916616562247930f17a5447", + "sha256:4e1065577f1b29111113be5deb2ea88553551a5e1cf33e0c08fa32768f285809", + "sha256:5f052dc2975a399aa1830c1f04c5f72856aa416bf3cd4b31375a058015a5c620", + "sha256:68ea43e51150316b9fb08e251209d4e2b4e76a340b5b6fc8cdf1a898c78f7e5b", + "sha256:698433a9fcefca0527244dc44dff9503eb26157494730b1cc80e6e4dbb246e92", + "sha256:6f714986f7987f10cb94f1be0753318e341a7ea6b12d66f37a4d5d6dd4695023", + "sha256:73cd9df328c7e72638dbcc1d18e7155225faed880a53db6bad90d1d7c0a71dfd", + "sha256:7876d1f29f66d3d7cac46479503891ee1ef409b0fbce54b0d74f3a6b33a46dba", + "sha256:854e87b8b2b76e3ed11d64985fcfdd7af919659503de99fc2b0a717b314c3cf0", + "sha256:8da13704ad45b7d5de8a8cca135a7f44c7fc6aa9f691abe7b0392468a34a8013", + "sha256:9ce22fb72298ea33dbb3a1c6c60a4a4e19d9698df6f3f5782eba4dada7b7736d", + "sha256:a37b6c59e7b8feadc51db5197052b86ceb6443f9fb2a6f7d6527620e707c558c", + "sha256:a6e8d2f99dbe1dfe72d0c019693c14d93c410f702d0b04ec9a81b36dacd55a23", + "sha256:a9ac862dd7159861f2c6443b0029089e1c0c4ec762a8074022914ec52fe4dfac", + "sha256:ae1bc3e78ed28f20878e7ca2c98663a6634e9c00d7746d39413fc18e907dc162", + "sha256:be7e70f91bd4eb35ae081062f16bf434619b3292358d9b061f8159ddc570c7f0", + "sha256:c895cf9c1b6d1cbba8cb8cc3f5427febcf8aa41a9333697741abeea1c537a350", + "sha256:e3e7e4a09dfd8b03663222d6bcadec9fef021404f4d9eecf56825342e039dfc1", + "sha256:f1f5714d2c23f6a64ef2ac4fcd36a2dd2689da85978d951a99a6ae5dfdf9bdbc", + "sha256:fa788f775680fc5d268ab00a2da29c9a22830032cfab732730298a2952cd87f3" + ], + "index": "pypi", + "version": "==1.9.6" + } + }, + "develop": {} +} diff --git a/install.py b/install.py new file mode 100755 index 0000000..2a318e6 --- /dev/null +++ b/install.py @@ -0,0 +1,176 @@ +#!/usr/bin/python + +def make_lifelib(autorun=True): + ''' + This script should be run from within the Python environment in which + you would like to install or upgrade lifelib. It will do the following + in turn: + + - ensure its own existence; + - invoke the pip package manager to install/upgrade python-lifelib; + - ensure the lifelib environment is correctly configured; + - perform a rudimentary sanity check; + - perform comprehensive tests. + + It can be invoked as a Python script or module, or run from within an + interpreter (python, IPython, or Jupyter), or executed as a Golly script. + ''' + + import sys + import os + from time import sleep + + print('Determining whether Golly exists...') + try: + import golly as g + def pprint(x): + print(x) + g.show(x) + g.update() + sleep(0.5) + golly_exists=True + except ImportError: + def pprint(x): + print(x) + golly_exists=False + + preposition = ('within' if golly_exists else 'outside') + pprint('We are running %s Golly.' % preposition) + + pprint('Determining Python executable...') + this_python = os.path.abspath(sys.executable) + + pprint('Determining script location...') + try: + this_script = os.path.abspath(__file__) + if not os.path.exists(this_script): + raise NameError("Script does not exist.") + except NameError: + # We may be running from stdin or the clipboard. Ensure the script + # exists in a real location: + pprint('Writing script to file...') + this_script = 'lifelib_install.py' + + try: + import inspect + source = '#!/usr/bin/python\n\n' + source += inspect.getsource(make_lifelib) + source += '# run program\nmake_lifelib(False)\n' + with open(this_script, 'w') as f: + f.write(source) + except: + try: + from urllib import urlretrieve + except ImportError: + from urllib.request import urlretrieve + pprint("Downloading installation script over HTTPS...") + script_path = 'https://gitlab.com/apgoucher/python-lifelib' + script_path += '/raw/master/install/install.py' + urlretrieve(script_path, this_script) + + def install_package(): + + pprint("Finding pip package manager...") + + try: + import pip + except ImportError: + import ensurepip + ensurepip.bootstrap() + + try: + # Python 3.x: + from pip._internal import main + except ImportError: + # Python 2.x: + from pip import main + + pprint("Installing/upgrading lifelib...") + rc = main(['install', '--user', '--upgrade', 'python-lifelib']) + + if rc and os.environ.get('VIRTUAL_ENV', None): + pprint("Probably running in virtualenv so dropping --user...") + rc = main(['install', '--upgrade', 'python-lifelib']) + + if rc: + pprint("Failed to install or upgrade lifelib.") + + def post_install(): + + pprint("Checking lifelib is installed...") + + try: + # This usually works, but not if this is the first time that + # a --user package has been installed: + import lifelib + except ImportError: + pprint("Updating sys.path...") + + # Find the updated sys.path which contains the newly-minted + # python-lifelib installation: + from subprocess import check_output + sa = [this_python, '-c', 'import sys; print(sys.path)'] + new_path = check_output(sa) + + # Python 3 returns a 'bytes' object which is incompatible + # with the ast.literal_eval() function, so cast to str: + if not isinstance(new_path, str): + new_path = new_path.decode() + + # Safely decode the returned string: + import ast + new_path = ast.literal_eval(new_path) + + # In-place list concatenation: + for n in new_path: + sys.path.append(n) + + # Now that sys.path has been modified, we can import lifelib: + import lifelib + + pprint("Lifelib version: %s" % lifelib.__version__) + + if (os.name == 'nt'): + pprint("Installing Cygwin if necessary...") + lifelib.install_cygwin() + + pprint("Creating session...") + sess = lifelib.load_rules('b3s23', force_indirect=True) + lt = sess.lifetree() + lidka = lt.pattern("bo$obo$bo8$8bo$6bobo$5b2obo2$4b3o!", 'b3s23') + + lp = lidka.population + l30kp = lidka[30000].population + + pprint("Initial population of Lidka: %d" % lp) + pprint("Final population of Lidka: %d" % l30kp) + + if (lp != 13) or (l30kp != 1623): + raise ValueError("Serious problem: populations do not match.") + + pprint("Checking numpy is installed...") + import numpy as np + pprint("Numpy version: %s" % np.__version__) + + pprint("Running comprehensive tests...") + lifelib.run_tests() + + pprint("Everything completed successfully.") + + def install_sandboxed(): + + from subprocess import check_call + pprint("Upgrading lifelib in separate process...") + check_call([this_python, this_script, '*']) + pprint("Lifelib upgraded; running post-install tasks...") + sleep(1.0) + post_install() + + if autorun or golly_exists: + install_sandboxed() + elif (__name__ == '__main__'): + [install_sandboxed, install_package, post_install][len(sys.argv)-1]() + + pass +# run program +make_lifelib(False) diff --git a/main.py b/main.py new file mode 100755 index 0000000..ae698ac --- /dev/null +++ b/main.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu May 28 19:45:33 2020 + +@author: suwako +""" + + +import lifelib +import pygame +