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.
|
||||
|
||||
![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)
|
||||
|
||||
|
||||
|
@ -65,11 +63,7 @@ The folder structure follows a non standard layout for personal reasons.
|
|||
├── makefile
|
||||
├── metro_holografix
|
||||
│ ├── cardtypes.py
|
||||
│ └── scrapes
|
||||
│ ├── alg.py
|
||||
│ ├── cardtypes.py
|
||||
│ ├── test.py
|
||||
│ └── vecchio.py
|
||||
│ └── scrapes/
|
||||
├── ono_sendai
|
||||
│ ├── animation/
|
||||
│ ├── start
|
||||
|
|
|
@ -3,6 +3,7 @@ from colorama import Style, Fore
|
|||
|
||||
from time import sleep
|
||||
from os import system
|
||||
import sys
|
||||
|
||||
|
||||
frames = []
|
||||
|
@ -18,6 +19,23 @@ 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]))
|
||||
|
|
|
@ -6,6 +6,8 @@ from time import sleep
|
|||
import os
|
||||
import json
|
||||
import logging
|
||||
import random
|
||||
import sys
|
||||
|
||||
from widgets import *
|
||||
from state import Table, Hand
|
||||
|
@ -266,7 +268,7 @@ def make_auto_move(original, game, difficulty):
|
|||
game.next_turn()
|
||||
|
||||
|
||||
def main(difficulty, dbg=False):
|
||||
def main(difficulty, game, dbg=False):
|
||||
from animation.octopus import intro
|
||||
|
||||
global exit, action
|
||||
|
@ -275,7 +277,6 @@ def main(difficulty, dbg=False):
|
|||
|
||||
intro()
|
||||
sleep(1)
|
||||
game = state.State(ID, ["PVR", ID])
|
||||
|
||||
game.next_turn()
|
||||
|
||||
|
@ -362,22 +363,54 @@ def main(difficulty, dbg=False):
|
|||
s = input(f"{Fore.MAGENTA}Please write 'y' or 'n'\n")
|
||||
print(f'{Style.RESET_ALL}')
|
||||
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__':
|
||||
from sys import argv
|
||||
|
||||
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:
|
||||
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)
|
||||
diff = int(diff) if diff.isdigit() else d[diff]
|
||||
except:
|
||||
print('Wrong argument for difficulty')
|
||||
main(int(diff), dbg)
|
||||
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
|
||||
|
||||
def make_deck():
|
||||
from random import shuffle # TODO: mersenne
|
||||
from random import shuffle
|
||||
def make_set(seed):
|
||||
for i in range(1, 14):
|
||||
yield Card(seed, i)
|
||||
|
@ -153,21 +153,23 @@ class State:
|
|||
self.turn.append((table, hand))
|
||||
return table, hand
|
||||
|
||||
def dump(self):
|
||||
def dump(self, fname):
|
||||
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('save.machiavelli', 'w') as f:
|
||||
with open(fname, 'w') as f:
|
||||
f.write(json.dumps(j))
|
||||
return j
|
||||
|
||||
def load(self):
|
||||
with open('save.machiavelli', 'r') as f:
|
||||
def load(self, fname):
|
||||
with open(fname, '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]))
|
||||
|
@ -192,23 +194,6 @@ 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
BIN
shot.gif
Binary file not shown.
Before Width: | Height: | Size: 5.1 MiB |
Loading…
Reference in a new issue