Compare commits
10 commits
1c1af5828d
...
e5bf300f14
Author | SHA1 | Date | |
---|---|---|---|
|
e5bf300f14 | ||
|
19069a8f3f | ||
|
2263de8a99 | ||
|
1dac4d2bfb | ||
|
42931f2925 | ||
|
9cba685957 | ||
|
bd3026a854 | ||
|
2f988a8128 | ||
|
71beb1d407 | ||
|
0dee7fd856 |
6 changed files with 234 additions and 48 deletions
156
.gitignore
vendored
Normal file
156
.gitignore
vendored
Normal file
|
@ -0,0 +1,156 @@
|
||||||
|
*~
|
||||||
|
|
||||||
|
# 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,8 +41,6 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,11 +63,7 @@ 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,6 +3,7 @@ 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 = []
|
||||||
|
@ -18,6 +19,23 @@ 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,6 +6,8 @@ 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
|
||||||
|
@ -266,7 +268,7 @@ def make_auto_move(original, game, difficulty):
|
||||||
game.next_turn()
|
game.next_turn()
|
||||||
|
|
||||||
|
|
||||||
def main(difficulty, dbg=False):
|
def main(difficulty, game, dbg=False):
|
||||||
from animation.octopus import intro
|
from animation.octopus import intro
|
||||||
|
|
||||||
global exit, action
|
global exit, action
|
||||||
|
@ -275,7 +277,6 @@ def main(difficulty, dbg=False):
|
||||||
|
|
||||||
intro()
|
intro()
|
||||||
sleep(1)
|
sleep(1)
|
||||||
game = state.State(ID, ["PVR", ID])
|
|
||||||
|
|
||||||
game.next_turn()
|
game.next_turn()
|
||||||
|
|
||||||
|
@ -360,24 +361,56 @@ def main(difficulty, dbg=False):
|
||||||
s = input(f'{Fore.MAGENTA}Do you want to save the game? (y/n)\n')
|
s = input(f'{Fore.MAGENTA}Do you want to save the game? (y/n)\n')
|
||||||
while s.lower() not in ['y', 'yes', 'n', 'no']:
|
while s.lower() not in ['y', 'yes', 'n', 'no']:
|
||||||
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':
|
||||||
game.dump()
|
fname = ''
|
||||||
|
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
|
||||||
|
|
||||||
diff = argv[1]
|
args = parse_args(argv[1:])
|
||||||
dbg = 'DEBUG' in argv
|
if args['about'] is not None:
|
||||||
if diff == 'easy':
|
from animation.octopus import intro_text
|
||||||
main(7, dbg)
|
# print(f'{Fore.MAGENTA}' + intro_text)
|
||||||
elif diff == 'medium':
|
print(intro_text)
|
||||||
main(14, dbg)
|
print("Press 'd' for drawing a card, m to 'move' a card, 's' to confirm the move.\n")
|
||||||
elif diff == 'hard':
|
# print(f'{Style.RESET_ALL}')
|
||||||
main(21, dbg)
|
sys.exit(0)
|
||||||
else:
|
|
||||||
try:
|
diff = args['difficulty'][0]
|
||||||
diff = int(diff)
|
d = {'medium':14, 'hard':21, 'easy':7}
|
||||||
except:
|
try:
|
||||||
print('Wrong argument for difficulty')
|
diff = int(diff) if diff.isdigit() else d[diff]
|
||||||
main(int(diff), dbg)
|
except:
|
||||||
|
print('Can\'t parse difficulty')
|
||||||
|
|
||||||
|
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 # TODO: mersenne
|
from random import shuffle
|
||||||
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,21 +153,23 @@ class State:
|
||||||
self.turn.append((table, hand))
|
self.turn.append((table, hand))
|
||||||
return table, hand
|
return table, hand
|
||||||
|
|
||||||
def dump(self):
|
def dump(self, fname):
|
||||||
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('save.machiavelli', 'w') as f:
|
with open(fname, 'w') as f:
|
||||||
f.write(json.dumps(j))
|
f.write(json.dumps(j))
|
||||||
return j
|
return j
|
||||||
|
|
||||||
def load(self):
|
def load(self, fname):
|
||||||
with open('save.machiavelli', 'r') as f:
|
with open(fname, '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]))
|
||||||
|
@ -192,23 +194,6 @@ 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
BIN
shot.gif
Binary file not shown.
Before Width: | Height: | Size: 5.1 MiB |
Loading…
Reference in a new issue