Compare commits

..

No commits in common. "e5bf300f1458428976ef45e7f81dd24c43a696b3" and "1c1af5828d76dabf6a7028d15fb065744f5509c8" have entirely different histories.

6 changed files with 48 additions and 234 deletions

156
.gitignore vendored
View file

@ -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

View file

@ -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.
![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)
@ -63,7 +65,11 @@ The folder structure follows a non standard layout for personal reasons.
├── makefile
├── metro_holografix
│   ├── cardtypes.py
│   └── scrapes/
│   └── scrapes
│   ├── alg.py
│   ├── cardtypes.py
│   ├── test.py
│   └── vecchio.py
├── ono_sendai
│   ├── animation/
│   ├── start

View file

@ -3,7 +3,6 @@ from colorama import Style, Fore
from time import sleep
from os import system
import sys
frames = []
@ -19,23 +18,6 @@ def animate(n):
sleep(0.2)
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__':
from sys import argv
animate(int(argv[1]))

View file

@ -6,8 +6,6 @@ from time import sleep
import os
import json
import logging
import random
import sys
from widgets import *
from state import Table, Hand
@ -268,7 +266,7 @@ def make_auto_move(original, game, difficulty):
game.next_turn()
def main(difficulty, game, dbg=False):
def main(difficulty, dbg=False):
from animation.octopus import intro
global exit, action
@ -277,6 +275,7 @@ def main(difficulty, game, dbg=False):
intro()
sleep(1)
game = state.State(ID, ["PVR", ID])
game.next_turn()
@ -361,56 +360,24 @@ def main(difficulty, game, dbg=False):
s = input(f'{Fore.MAGENTA}Do you want to save the game? (y/n)\n')
while s.lower() not in ['y', 'yes', 'n', 'no']:
s = input(f"{Fore.MAGENTA}Please write 'y' or 'n'\n")
print(f'{Style.RESET_ALL}')
if s.lower() == 'y' or s.lower() == 'yes':
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)
print(f'{Style.RESET_ALL}')
if s.lower() == 'y' or s.lower() == 'yes':
game.dump()
if __name__ == '__main__':
from sys import argv
args = parse_args(argv[1:])
if args['about'] is not None:
from animation.octopus import intro_text
# print(f'{Fore.MAGENTA}' + intro_text)
print(intro_text)
print("Press 'd' for drawing a card, m to 'move' a card, 's' to confirm the move.\n")
# print(f'{Style.RESET_ALL}')
sys.exit(0)
diff = args['difficulty'][0]
d = {'medium':14, 'hard':21, 'easy':7}
try:
diff = int(diff) if diff.isdigit() else d[diff]
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)
diff = argv[1]
dbg = 'DEBUG' in argv
if diff == 'easy':
main(7, dbg)
elif diff == 'medium':
main(14, dbg)
elif diff == 'hard':
main(21, dbg)
else:
try:
diff = int(diff)
except:
print('Wrong argument for difficulty')
main(int(diff), dbg)

View file

@ -75,7 +75,7 @@ class Hand:
return yi
def make_deck():
from random import shuffle
from random import shuffle # TODO: mersenne
def make_set(seed):
for i in range(1, 14):
yield Card(seed, i)
@ -153,23 +153,21 @@ class State:
self.turn.append((table, hand))
return table, hand
def dump(self, fname):
def dump(self):
j = dict()
j['table'] = [tc.cards for tc in self.table.cards]
for pl, hand in self.players.items():
j[pl] = hand.cards
j['nrounds'] = self.nrounds
j['deck'] = self.deck
j['players'] = list(self.players.keys())
with open(fname, 'w') as f:
with open('save.machiavelli', 'w') as f:
f.write(json.dumps(j))
return j
def load(self, fname):
with open(fname, 'r') as f:
def load(self):
with open('save.machiavelli', 'r') as f:
j = json.loads(f.read())
self.nrounds = j['nrounds']
self.deck = [Card(seed, value) for seed, value in j['deck']]
tcards = []
for tc in j['table']:
tcards.append(TaggedCards([Card(seed, value) for seed, value in tc]))
@ -194,6 +192,23 @@ def toJson(table, hand):
j['table'].append(tc.cards)
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):
assert type(src) is int
to_move = hand.cards[src]

BIN
shot.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 MiB