Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • sunarch/exploratory
1 result
Show changes
Commits on Source (4)
Showing
with 76 additions and 653 deletions
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""Blades in the Dark - dice probabilities"""
from itertools import product
D6_LARGEST: int = 6
def d6_faces() -> list[int]:
return list(map(lambda x: x+1, list(range(D6_LARGEST))))
def result_line(title, value, total) -> str:
percent: float = round(value / total * 100, 2)
print('- {:<16}: {:>4} / {:>4} ( {:>5} % )'.format(title, value, total, percent))
def statistics(d6_count: int) -> None:
combinations: list[tuple[int]] = list(product(d6_faces(), repeat=d6_count))
combination_count: int = len(combinations)
critical: int = 0
complete_success: int = 0
partial_success: int = 0
failure: int = 0
for element in combinations:
element: list = list(sorted(element))
if len(element) > 1 and element[-1] == D6_LARGEST and element[-2] == D6_LARGEST:
critical += 1
continue
match max(element):
case 6:
complete_success += 1
case 5 | 4:
partial_success += 1
case 3 | 2 | 1:
failure += 1
all_full_success: int = critical + complete_success
all_success: int = all_full_success + partial_success
print()
print(f'{d6_count}d6')
result_line('critical', critical, combination_count)
result_line('complete success', complete_success, combination_count)
result_line('partial success', partial_success, combination_count)
result_line('failure', failure, combination_count)
print()
if d6_count > 1:
result_line('all full success', all_full_success, combination_count)
result_line('all success', all_success, combination_count)
def main() -> None:
for d6_count in range(1, 5):
statistics(d6_count)
if __name__ == '__main__':
main()
# Moonscribe
- an RPG engine
## Parts
- [Probable Adventure](probable-adventure.md)
- a novel generator
## License
[Mozilla Public License 2.0](https://www.mozilla.org/en-US/MPL/2.0/)
```
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
```
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# imports: library
from argparse import ArgumentParser
# imports: dependencies
from libmonty_logging.config.file_and_stream.v1 import config as logging_config
import libmonty_logging.helper as logging_helper
import libmonty_logging.message as logging_message
# imports: project
from moonscribe import version
def main() -> None:
logging_helper.apply_config(version.PROGRAM_NAME,
version.__version__,
logging_config)
logging_message.program_header(version.PROGRAM_NAME)
parser = ArgumentParser(prog=version.PROGRAM_NAME)
parser.add_argument('--version',
help='Display version',
action='store_true',
dest='version')
args = parser.parse_args()
if args.version:
print(f'{version.PROGRAM_NAME} {version.__version__}')
return
if __name__ == '__main__':
main()
# -------------------------------------------------------------------- #
[loggers]
keys=root
[handlers]
keys=hand01,hand02
[formatters]
keys=form01,form02
[logger_root]
level=NOTSET
handlers=hand01,hand02
[handler_hand01]
class=StreamHandler
level=INFO
formatter=form01
args=(sys.stdout,)
[formatter_form01]
format=[%(asctime)s] [%(levelname)-8s] %(message)s
datefmt=%H:%M:%S
class=logging.Formatter
[handler_hand02]
class=FileHandler
level=INFO
formatter=form02
args=('moonscribe.log', 'w', 'UTF-8')
[formatter_form02]
format=[%(asctime)s] [%(levelname)-8s] %(message)s
datefmt=
class=logging.Formatter
## Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fot
*.cb
*.cb2
# Core aux files // mylatexformat
*.fmt
## Intermediate documents:
*.dvi
*-converted-to.*
# these rules might exclude image files for figures etc.
# *.ps
# *.eps
# *.pdf
## Generated if empty string is given at "Please type another file name for output:"
.pdf
## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml
# Bibliography auxiliary files // hyperref
*.brf
## Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync
## Auxiliary and intermediate files from other packages:
# algorithms
*.alg
*.loa
# achemso
acs-*.bib
# amsthm
*.thm
# beamer
*.nav
*.snm
*.vrb
# cprotect
*.cpt
# fixme
*.lox
#(r)(e)ledmac/(r)(e)ledpar
*.end
*.?end
*.[1-9]
*.[1-9][0-9]
*.[1-9][0-9][0-9]
*.[1-9]R
*.[1-9][0-9]R
*.[1-9][0-9][0-9]R
*.eledsec[1-9]
*.eledsec[1-9]R
*.eledsec[1-9][0-9]
*.eledsec[1-9][0-9]R
*.eledsec[1-9][0-9][0-9]
*.eledsec[1-9][0-9][0-9]R
# glossaries
*.acn
*.acr
*.glg
*.glo
*.gls
*.glsdefs
# gnuplottex
*-gnuplottex-*
# gregoriotex
*.gaux
*.gtex
# knitr
*-concordance.tex
# Comment the next line if you want to keep your tikz graphics files
*.tikz
*-tikzDictionary
# listings
*.lol
# makeidx
*.idx
*.ilg
*.ind
*.ist
# minitoc
*.maf
*.mlf
*.mlt
*.mtc
*.mtc[0-9]
*.mtc[1-9][0-9]
# minted
_minted*
*.pyg
# morewrites
*.mw
# nomencl
*.nlo
# sagetex
*.sagetex.sage
*.sagetex.py
*.sagetex.scmd
# scrwfile
*.wrt
# sympy
*.sout
*.sympy
sympy-plots-for-*.tex/
# pdfcomment
*.upa
*.upb
# pythontex
*.pytxcode
pythontex-files-*/
# thmtools
*.loe
# TikZ & PGF
*.dpth
*.md5
*.auxlock
# todonotes
*.tdo
# easy - to do
*.lod
# xindy
*.xdy
# xypic precompiled matrices
*.xyc
# endfloat
*.ttt
*.fff
# Latexian
TSWLatexianTemp*
## Editors:
# WinEdt
*.bak
*.sav
# Texpad
.texpadtmp
# Kile
*.backup
# KBibTeX
*~[0-9]*
# auto folder when using emacs and auctex
/auto/*
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# !/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# imports: library
from typing import Generator
# imports: subproject
from moonscribe.probable_adventure import common
def chapter(title: str) -> Generator:
for line in common.license_notice():
yield line
yield '\\chapter{' + title + '}'
yield 'Text'
yield ''
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# imports: library
from typing import Generator
def license_notice() -> Generator:
yield '% This file is part of "Probable Adventure".'
yield '%'
yield '% This Source Code Form is subject to the terms of the Mozilla Public'
yield '% License, v. 2.0. If a copy of the MPL was not distributed with this'
yield '% file, You can obtain one at http://mozilla.org/MPL/2.0/.'
yield ''
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# imports: library
from typing import Generator
# imports: subproject
from moonscribe.probable_adventure import common
def document() -> Generator:
chapters: int = 0
for line in common.license_notice():
yield line
yield '\\documentclass[12pt,a4paper]{book}'
yield ''
yield '\\usepackage[utf8]{inputenc}'
yield '\\usepackage[T1]{fontenc}'
yield ''
yield '\\usepackage{import}'
yield '\\usepackage{graphicx}'
yield '\\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.50cm]{geometry}'
yield '\\usepackage[english]{babel}'
yield ''
yield '\\author{András Németh}'
yield '\\title{Probable Adventure}'
yield ''
yield '\\begin{document}'
yield ''
yield '\\frontmatter'
yield '\\maketitle'
yield ''
yield '\\tableofcontents'
yield ''
yield '\\mainmatter'
yield ''
yield '\\subimport{./}{chapter-sample.tex}'
for i in range(chapters):
yield '\\subimport{./generated/}{chapter-' + f'{i:0>2}' + '.tex}'
yield ''
yield '\\end{document}'
yield ''
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# imports: library
import argparse
def main():
parser = argparse.ArgumentParser(prog='probable-adventure')
parser.add_argument('-m', '--mode',
help='check mode')
args = parser.parse_args()
if args.mode == "a":
print("a.")
if __name__ == '__main__':
main()
libmonty-logging == 0.1.1
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
PROGRAM_NAME = 'moonscribe'
__version__ = '0.0.3'
[< home](README.md)
# Probable Adventure
Novel generation program for the NaNoGenMo
......@@ -8,6 +6,10 @@ Novel generation program for the NaNoGenMo
_Fun fact:_ The name of the repository (probable-adventure)
was the first random one GitHub offered when I created the project.
### alternative
The project was also considered to be named `moonscribe` at onw point.
### [NaNoGenMo 2016](https://github.com/NaNoGenMo/2016)
This was the first year I planned to create an entry.
......
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""Config
"""
# imports: library
from dataclasses import dataclass, InitVar, field
import json
import os
@dataclass
class SoundboardItem:
"""Soundboard item"""
filename: str
text: str
@dataclass
class Config:
"""Config"""
main_file_path: InitVar[str]
_main_dir: str = None
_data_dir: str = None
board_name: str = None
title: str = 'Soundboard'
sound_items: list[SoundboardItem] = field(default_factory=list)
def __post_init__(self, main_file_path: str):
self._main_dir = os.path.split(os.path.abspath(main_file_path))[0]
self._data_dir = os.path.join(self._main_dir, 'data')
def data_path(self, *elements) -> str:
"""Data path"""
return os.path.join(self._data_dir, *elements)
def data_path_board(self, *elements) -> str:
"""Data path board"""
return os.path.join(self._data_dir, self.board_name, *elements)
def load(self, name):
"""Load"""
self.board_name = name
path: str = self.data_path(self.board_name, 'config.json')
with open(path, 'rb') as fh_config:
config_json = json.load(fh_config)
self.title = config_json['title']
self.sound_items = []
for item in config_json['sounds']:
self.sound_items.append(SoundboardItem(item['filename'], item['text']))
libmonty-logging == 0.1.1
pygame == 2.4.0
xdg-base-dirs == 6.0.0
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""Sound
"""
# imports: library
import logging
# imports: requirements
import pygame
class MixerInitError(Exception):
"""Mixer init error"""
if not pygame.mixer:
logging.warning('sound disabled')
def _load_mixer():
"""Load mixer"""
if not pygame.mixer.get_init():
pygame.mixer.init()
if (mixer_init := pygame.mixer.get_init()) is not None:
logging.info('Mixer initalized.')
mixer_frequency, mixer_format, mixer_channels = mixer_init
logging.info('frequency: %s', mixer_frequency)
logging.info('format: %s', mixer_format)
logging.info('channels: %s', mixer_channels)
else:
raise MixerInitError('Mixer NOT initalized!')
def load_sound(path):
"""Load sound"""
class NoneSound:
"""None sound"""
def play(self):
"""Dummy play method"""
if not pygame.mixer:
return NoneSound()
try:
_load_mixer()
except MixerInitError as exc:
logging.warning(exc)
return NoneSound()
sound = pygame.mixer.Sound(path)
return sound
def deinit() -> None:
"""De-init"""
pygame.mixer.quit()
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""Soundboard
"""
# imports: library
from argparse import ArgumentParser
import logging
import tkinter # no underscore, lowercase 't' for V3.0 and later
from tkinter import ttk
# imports: dependencies
from libmonty_logging.config.file_and_stream.v1 import config as logging_config
import libmonty_logging.helper as logging_helper
import libmonty_logging.message as logging_message
# imports: project
from libmonty_tools.soundboard.config import Config
from libmonty_tools.soundboard import sound
from libmonty_tools import version
def main() -> None:
"""Main"""
logging_helper.apply_config(version.PROGRAM_NAME,
version.__version__,
logging_config)
logging_message.program_header('libmonty Soundboard')
parser = ArgumentParser(prog=version.PROGRAM_NAME)
parser.add_argument('--version',
help='Display version',
action='store_true',
dest='version')
parser.add_argument('--board',
help='Name of the board config',
action='store', default=None,
dest='board_name')
args = parser.parse_args()
if args.version:
print(f'libmonty Soundboard {version.__version__}')
return
config = Config(__file__)
if args.board_name is None:
logging.warning('No board specified. See the --board option.')
logging.warning('Exiting.')
return
config.load(args.board_name)
root = tkinter.Tk()
frm = ttk.Frame(root, padding=10)
frm.grid()
ttk.Label(frm, text=config.title).grid(column=0, row=0)
ttk.Button(frm, text='Quit', command=root.destroy).grid(column=1, row=0)
for index, sound_item in enumerate(config.sound_items):
sound_item_path = config.data_path_board(sound_item.filename)
ttk.Button(frm,
text=sound_item.text,
command=sound.load_sound(sound_item_path).play
).grid(column=0,
row=index + 1)
root.mainloop()
sound.deinit()
if __name__ == '__main__':
main()
......@@ -4,18 +4,18 @@
(let ([socket (udp-open-socket)])
(udp-bind!
socket
"0.0.0.0"
6454
)
(udp-bind!
socket
"0.0.0.0"
6454
)
(udp-send-to
socket
"255.255.255.255"
6454
(bytes 65 112 112 108 101)
)
(udp-send-to
socket
"255.255.255.255"
6454
(bytes 65 112 112 108 101)
)
(udp-close socket)
(udp-close socket)
)