Compare commits
No commits in common. "e5bf300f1458428976ef45e7f81dd24c43a696b3" and "1c1af5828d76dabf6a7028d15fb065744f5509c8" have entirely different histories.
e5bf300f14
...
1c1af5828d
6 changed files with 48 additions and 234 deletions
156
.gitignore
vendored
156
.gitignore
vendored
|
@ -1,156 +0,0 @@
|
||||||
*~
|
|
||||||
|
|
||||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
|
||||||
.fuse_hidden*
|
|
||||||
|
|
||||||
# KDE directory preferences
|
|
||||||
.directory
|
|
||||||
|
|
||||||
# Linux trash folder which might appear on any partition or disk
|
|
||||||
.Trash-*
|
|
||||||
|
|
||||||
# .nfs files are created when an open file is removed but is still being accessed
|
|
||||||
.nfs*
|
|
||||||
|
|
||||||
### OCaml ###
|
|
||||||
*.annot
|
|
||||||
*.cmo
|
|
||||||
*.cma
|
|
||||||
*.cmi
|
|
||||||
*.a
|
|
||||||
*.o
|
|
||||||
*.cmx
|
|
||||||
*.cmxs
|
|
||||||
*.cmxa
|
|
||||||
|
|
||||||
# ocamlbuild working directory
|
|
||||||
_build/
|
|
||||||
|
|
||||||
# ocamlbuild targets
|
|
||||||
*.byte
|
|
||||||
*.native
|
|
||||||
|
|
||||||
# oasis generated files
|
|
||||||
setup.data
|
|
||||||
setup.log
|
|
||||||
|
|
||||||
# Merlin configuring file for Vim and Emacs
|
|
||||||
.merlin
|
|
||||||
|
|
||||||
# Dune generated files
|
|
||||||
*.install
|
|
||||||
|
|
||||||
# Local OPAM switch
|
|
||||||
_opam/
|
|
||||||
|
|
||||||
# Esy-related generated files
|
|
||||||
_esy/
|
|
||||||
_build.prev/
|
|
||||||
node_modules/
|
|
||||||
|
|
||||||
### Python ###
|
|
||||||
# Byte-compiled / optimized / DLL files
|
|
||||||
__pycache__/
|
|
||||||
*.py[cod]
|
|
||||||
*$py.class
|
|
||||||
|
|
||||||
# C extensions
|
|
||||||
*.so
|
|
||||||
|
|
||||||
# Distribution / packaging
|
|
||||||
.Python
|
|
||||||
build/
|
|
||||||
develop-eggs/
|
|
||||||
dist/
|
|
||||||
downloads/
|
|
||||||
eggs/
|
|
||||||
.eggs/
|
|
||||||
lib/
|
|
||||||
lib64/
|
|
||||||
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
|
|
||||||
.hypothesis/
|
|
||||||
.pytest_cache/
|
|
||||||
|
|
||||||
# Translations
|
|
||||||
*.mo
|
|
||||||
*.pot
|
|
||||||
|
|
||||||
# Scrapy stuff:
|
|
||||||
.scrapy
|
|
||||||
|
|
||||||
# Sphinx documentation
|
|
||||||
docs/_build/
|
|
||||||
|
|
||||||
# PyBuilder
|
|
||||||
target/
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# celery beat schedule file
|
|
||||||
celerybeat-schedule
|
|
||||||
|
|
||||||
# SageMath parsed files
|
|
||||||
*.sage.py
|
|
||||||
|
|
||||||
# Spyder project settings
|
|
||||||
.spyderproject
|
|
||||||
.spyproject
|
|
||||||
|
|
||||||
# Rope project settings
|
|
||||||
.ropeproject
|
|
||||||
|
|
||||||
# Mr Developer
|
|
||||||
.mr.developer.cfg
|
|
||||||
.project
|
|
||||||
.pydevproject
|
|
||||||
|
|
||||||
# mkdocs documentation
|
|
||||||
/site
|
|
||||||
|
|
||||||
# mypy
|
|
||||||
.mypy_cache/
|
|
||||||
.dmypy.json
|
|
||||||
dmypy.json
|
|
||||||
|
|
||||||
# Pyre type checker
|
|
||||||
.pyre/
|
|
||||||
|
|
||||||
# End of https://www.gitignore.io/api/ocaml,linux,python
|
|
|
@ -41,6 +41,8 @@ Then run the executable
|
||||||
|
|
||||||
[Click](https://raw.githubusercontent.com/FraMecca/Octopus_Carnival/master/ono_sendai/animation/rec.webm) to play the video.
|
[Click](https://raw.githubusercontent.com/FraMecca/Octopus_Carnival/master/ono_sendai/animation/rec.webm) to play the video.
|
||||||
|
|
||||||
|
![Example](ono_sendai/animation/intro.gif)
|
||||||
|
|
||||||
[![Example](ono_sendai/animation/shot.gif)](https://raw.githubusercontent.com/FraMecca/Octopus_Carnival/master/ono_sendai/animation/rec.webm)
|
[![Example](ono_sendai/animation/shot.gif)](https://raw.githubusercontent.com/FraMecca/Octopus_Carnival/master/ono_sendai/animation/rec.webm)
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,7 +65,11 @@ The folder structure follows a non standard layout for personal reasons.
|
||||||
├── makefile
|
├── makefile
|
||||||
├── metro_holografix
|
├── metro_holografix
|
||||||
│ ├── cardtypes.py
|
│ ├── cardtypes.py
|
||||||
│ └── scrapes/
|
│ └── scrapes
|
||||||
|
│ ├── alg.py
|
||||||
|
│ ├── cardtypes.py
|
||||||
|
│ ├── test.py
|
||||||
|
│ └── vecchio.py
|
||||||
├── ono_sendai
|
├── ono_sendai
|
||||||
│ ├── animation/
|
│ ├── animation/
|
||||||
│ ├── start
|
│ ├── start
|
||||||
|
|
|
@ -3,7 +3,6 @@ from colorama import Style, Fore
|
||||||
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from os import system
|
from os import system
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
frames = []
|
frames = []
|
||||||
|
@ -19,23 +18,6 @@ def animate(n):
|
||||||
sleep(0.2)
|
sleep(0.2)
|
||||||
system('clear')
|
system('clear')
|
||||||
|
|
||||||
with open('animation/intro2.txt', 'r') as f:
|
|
||||||
intro_text = f.read()
|
|
||||||
|
|
||||||
def intro():
|
|
||||||
system('clear')
|
|
||||||
print(f'{Fore.MAGENTA}', end='')
|
|
||||||
for ch in intro_text:
|
|
||||||
print(ch, end='')
|
|
||||||
sys.stdout.flush()
|
|
||||||
sleep(0.01)
|
|
||||||
# for i in range(5):
|
|
||||||
# system('clear')
|
|
||||||
# print(anim)
|
|
||||||
# sleep(0.4)
|
|
||||||
print(f'{Style.RESET_ALL}')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from sys import argv
|
from sys import argv
|
||||||
animate(int(argv[1]))
|
animate(int(argv[1]))
|
||||||
|
|
|
@ -6,8 +6,6 @@ from time import sleep
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import random
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from widgets import *
|
from widgets import *
|
||||||
from state import Table, Hand
|
from state import Table, Hand
|
||||||
|
@ -268,7 +266,7 @@ def make_auto_move(original, game, difficulty):
|
||||||
game.next_turn()
|
game.next_turn()
|
||||||
|
|
||||||
|
|
||||||
def main(difficulty, game, dbg=False):
|
def main(difficulty, dbg=False):
|
||||||
from animation.octopus import intro
|
from animation.octopus import intro
|
||||||
|
|
||||||
global exit, action
|
global exit, action
|
||||||
|
@ -277,6 +275,7 @@ def main(difficulty, game, dbg=False):
|
||||||
|
|
||||||
intro()
|
intro()
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
game = state.State(ID, ["PVR", ID])
|
||||||
|
|
||||||
game.next_turn()
|
game.next_turn()
|
||||||
|
|
||||||
|
@ -363,54 +362,22 @@ def main(difficulty, game, dbg=False):
|
||||||
s = input(f"{Fore.MAGENTA}Please write 'y' or 'n'\n")
|
s = input(f"{Fore.MAGENTA}Please write 'y' or 'n'\n")
|
||||||
print(f'{Style.RESET_ALL}')
|
print(f'{Style.RESET_ALL}')
|
||||||
if s.lower() == 'y' or s.lower() == 'yes':
|
if s.lower() == 'y' or s.lower() == 'yes':
|
||||||
fname = ''
|
game.dump()
|
||||||
while fname == '':
|
|
||||||
fname = input('Choose a filename: ')
|
|
||||||
game.dump(fname)
|
|
||||||
print(f'{Style.RESET_ALL}')
|
|
||||||
|
|
||||||
def parse_args(argv):
|
|
||||||
import argparse
|
|
||||||
parser = argparse.ArgumentParser(description="")
|
|
||||||
parser.add_argument('--difficulty', type=str, nargs=1, default='medium',
|
|
||||||
help='[easy|medium|hard|n]')
|
|
||||||
parser.add_argument('--seed', type=int, nargs=1, default=None,
|
|
||||||
help='Seed for randomness')
|
|
||||||
parser.add_argument('--debug', action='store_const', const=True,
|
|
||||||
help='provide access to the REPL')
|
|
||||||
parser.add_argument('--load', type=str, nargs=1, default='',
|
|
||||||
help='load a savefile')
|
|
||||||
parser.add_argument('--about', action='store_const', const=True,
|
|
||||||
help='information about this game')
|
|
||||||
|
|
||||||
args = parser.parse_args(argv)
|
|
||||||
return vars(args)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from sys import argv
|
from sys import argv
|
||||||
|
|
||||||
args = parse_args(argv[1:])
|
diff = argv[1]
|
||||||
if args['about'] is not None:
|
dbg = 'DEBUG' in argv
|
||||||
from animation.octopus import intro_text
|
if diff == 'easy':
|
||||||
# print(f'{Fore.MAGENTA}' + intro_text)
|
main(7, dbg)
|
||||||
print(intro_text)
|
elif diff == 'medium':
|
||||||
print("Press 'd' for drawing a card, m to 'move' a card, 's' to confirm the move.\n")
|
main(14, dbg)
|
||||||
# print(f'{Style.RESET_ALL}')
|
elif diff == 'hard':
|
||||||
sys.exit(0)
|
main(21, dbg)
|
||||||
|
else:
|
||||||
diff = args['difficulty'][0]
|
|
||||||
d = {'medium':14, 'hard':21, 'easy':7}
|
|
||||||
try:
|
try:
|
||||||
diff = int(diff) if diff.isdigit() else d[diff]
|
diff = int(diff)
|
||||||
except:
|
except:
|
||||||
print('Can\'t parse difficulty')
|
print('Wrong argument for difficulty')
|
||||||
|
main(int(diff), dbg)
|
||||||
random.seed = args['seed'][0] if args['seed'] is not None else os.urandom(1)
|
|
||||||
dbg = args['debug'] is not None
|
|
||||||
|
|
||||||
game = state.State(ID, ["PVR", ID])
|
|
||||||
if args['load']:
|
|
||||||
game.load(args['load'][0])
|
|
||||||
|
|
||||||
# start the game
|
|
||||||
main(diff, game, dbg)
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Hand:
|
||||||
return yi
|
return yi
|
||||||
|
|
||||||
def make_deck():
|
def make_deck():
|
||||||
from random import shuffle
|
from random import shuffle # TODO: mersenne
|
||||||
def make_set(seed):
|
def make_set(seed):
|
||||||
for i in range(1, 14):
|
for i in range(1, 14):
|
||||||
yield Card(seed, i)
|
yield Card(seed, i)
|
||||||
|
@ -153,23 +153,21 @@ class State:
|
||||||
self.turn.append((table, hand))
|
self.turn.append((table, hand))
|
||||||
return table, hand
|
return table, hand
|
||||||
|
|
||||||
def dump(self, fname):
|
def dump(self):
|
||||||
j = dict()
|
j = dict()
|
||||||
j['table'] = [tc.cards for tc in self.table.cards]
|
j['table'] = [tc.cards for tc in self.table.cards]
|
||||||
for pl, hand in self.players.items():
|
for pl, hand in self.players.items():
|
||||||
j[pl] = hand.cards
|
j[pl] = hand.cards
|
||||||
j['nrounds'] = self.nrounds
|
j['nrounds'] = self.nrounds
|
||||||
j['deck'] = self.deck
|
|
||||||
j['players'] = list(self.players.keys())
|
j['players'] = list(self.players.keys())
|
||||||
with open(fname, 'w') as f:
|
with open('save.machiavelli', 'w') as f:
|
||||||
f.write(json.dumps(j))
|
f.write(json.dumps(j))
|
||||||
return j
|
return j
|
||||||
|
|
||||||
def load(self, fname):
|
def load(self):
|
||||||
with open(fname, 'r') as f:
|
with open('save.machiavelli', 'r') as f:
|
||||||
j = json.loads(f.read())
|
j = json.loads(f.read())
|
||||||
self.nrounds = j['nrounds']
|
self.nrounds = j['nrounds']
|
||||||
self.deck = [Card(seed, value) for seed, value in j['deck']]
|
|
||||||
tcards = []
|
tcards = []
|
||||||
for tc in j['table']:
|
for tc in j['table']:
|
||||||
tcards.append(TaggedCards([Card(seed, value) for seed, value in tc]))
|
tcards.append(TaggedCards([Card(seed, value) for seed, value in tc]))
|
||||||
|
@ -194,6 +192,23 @@ def toJson(table, hand):
|
||||||
j['table'].append(tc.cards)
|
j['table'].append(tc.cards)
|
||||||
return json.dumps(j)
|
return json.dumps(j)
|
||||||
|
|
||||||
|
# def gioca(tavolo, hand, src, dst):
|
||||||
|
# giocata = [] if dst == 'Empty' else tavolo.cards[dst]
|
||||||
|
# da_muovere = hand.cards[src[1]] if src[0] == 'Hand' else tavolo.cards[src[0]].cards[src[1]]
|
||||||
|
# hcards = hand.cards[:src[1]] + hand.cards[src[1]+1:] if src[0] == 'Hand' else hand.cards
|
||||||
|
# assert src[0] != 'Hand' or len(hcards) == len(hand.cards) - 1
|
||||||
|
|
||||||
|
# assert type(dst) is int or dst == 'Empty'
|
||||||
|
# assert type(src[0]) is int or src[0] == 'Hand'
|
||||||
|
# assert type(da_muovere) is Card
|
||||||
|
# assert type(giocata) is TaggedCards or giocata == []
|
||||||
|
|
||||||
|
# idx = -1 if dst == 'Empty' else tavolo.cards.index(giocata)
|
||||||
|
# if type(giocata) is list: # we want a new empty cell
|
||||||
|
# news = [TaggedCards([da_muovere])]
|
||||||
|
# else:
|
||||||
|
# news = []
|
||||||
|
|
||||||
def fromHandToEmpty(table, hand, src):
|
def fromHandToEmpty(table, hand, src):
|
||||||
assert type(src) is int
|
assert type(src) is int
|
||||||
to_move = hand.cards[src]
|
to_move = hand.cards[src]
|
||||||
|
|
BIN
shot.gif
Normal file
BIN
shot.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 MiB |
Loading…
Reference in a new issue