1
0
Fork 0
mirror of https://github.com/Oreolek/gamebookformat.git synced 2024-05-14 06:58:20 +03:00

Optional seed to get predictable shuffling of sections (for tests).

This commit is contained in:
Pelle Nilsson 2013-06-13 23:07:36 +02:00
parent 9aa32a1071
commit 9831aae42a
3 changed files with 33 additions and 12 deletions

View file

@ -67,7 +67,8 @@ def format_gamebook(inputfilenames,
outputfilename,
import_default_map_file,
templatedirs,
verify):
verify,
seed):
output_format = make_output(outputfilename, templatedirs)
book = sections.Book()
for inputfilename in inputfilenames:
@ -76,7 +77,7 @@ def format_gamebook(inputfilenames,
import_default_nr_map(outputfilename, book)
if verify:
verifygamebook.verify(book)
write_book(book, output_format, outputfilename)
write_book(book, seed, output_format, outputfilename)
def parse_file_to_book(inputfile, book):
before_first_section = True
@ -145,8 +146,8 @@ def make_output(outputfilename, templatedirs):
raise Exception("Unsupported or unknown output format for %s."
% outputfilename)
def write_book(book, output_format, outputfilename):
shuffled_sections = book.shuffle()
def write_book(book, seed, output_format, outputfilename):
shuffled_sections = book.shuffle(seed)
output = open(outputfilename, 'w')
output_format.write_begin(book, output)
output_format.write_intro_sections(book, shuffled_sections, output)
@ -187,6 +188,8 @@ if __name__ == '__main__':
action='append', help='add custom template dir')
ap.add_argument('-y', '--verify', action='store_true',
help='verify gamebook structure')
ap.add_argument('-s', '--seed', action='store', default=None,
help='random seed for shuffling sections')
args = ap.parse_args()
templatedirs = ['templates',
os.path.join(os.path.dirname(sys.argv[0]), 'templates')]
@ -197,4 +200,5 @@ if __name__ == '__main__':
args.outputfile,
args.import_default_map_file,
templatedirs,
args.verify)
args.verify,
args.seed)

View file

@ -97,7 +97,7 @@ class Book:
if nr > self.config['max']:
self.config['max'] = nr
def shuffle(self):
def shuffle(self, seed=None):
as_list = [None]
from_nr = {}
shuffled = self.sections[:]
@ -109,11 +109,13 @@ class Book:
for p in self.nr_sections.values():
if p in self.from_name:
shuffled.remove(self.from_name[p])
random.shuffle(shuffled)
rnd = random.Random(seed)
rnd.shuffle(shuffled)
for nr in range(1, self.config['max'] + 1):
if (self.nr_sections.has_key(nr)
and self.nr_sections[nr] in self.from_name):
section = ShuffledSection(nr, self.from_name[self.nr_sections[nr]])
section = ShuffledSection(nr, self.from_name[
self.nr_sections[nr]])
elif len(shuffled):
section = ShuffledSection(nr, shuffled.pop())
else:

View file

@ -1,4 +1,4 @@
* TODO [38/65] [58%]
* TODO [39/67] [58%]
- [X] Debug output
- [X] DOT output
- [X] LaTeX output
@ -44,11 +44,15 @@
- [X] Only accept specific characters in section names
eg [a-z][a-z_0-9]+
- [X] Random pick of link to follow from a section.
- [ ] Possibility to make predictable random numbers and shuffling for testing
- [X] Possibility to make predictable random numbers and shuffling for testing
- [ ] Test generate examples and compare to expected output in all formats
- [ ] Unit tests (finally...)
- [ ] Verify gamebook with --verify (but how?)
- [ ] Verify gamebook (always; drop the --verify option)
- [ ] Dummy and fake sections (handle properly when verifying)
- [ ] Inline sections
Inline prefix on link or :inline: tag on target section itself.
If tagged or all links to a section are marked inline the section
itself is removed.
- [ ] Counters (life, money, whatever) create and set
count tag to declare new counter, text in tag is display name
optional argument sets the starting value of the tag
@ -65,16 +69,27 @@
test those from nodejs?
- [ ] Javascript GUI tests running in a browser
Preferably headless (in nodejs?). Run tests on gamebook html example(s).
- [ ] Combat
Tag to mark up the link to use to trigger next round.
Tag to mark up the enemy and its values.
Fixed set of combat abilities handled by javascript
(some way to configure ability names, but in that case javascript
for combat, in a separate file, must be overridden)
- [ ] Macros for input(quests etc etc). Generate one or more sections.
- [ ] Macros that can add content to sections (pre or post).
- [ ] Some way to insert character sheet in book introduction
- [ ] Some way to insert dice at bottom of pages for LaTeX
- [ ] Some way to insert optional dice at bottom of pages for LaTeX
- [ ] Some way to insert optional random numbers table at end of book
- [ ] Defensive removal of any weird unicode not handled by quoting.
- [ ] Somewhat user-friendly error messages
- [ ] More formatting possibilities in sections
Look at existing gamebooks to get ideas.
- [ ] Document Gamebook format
- Basic gamebook (static, nothing about magic needed for dynamic; tutorial)
- Advanced (more complex layout options, but still static)
- Dynamic (markup needed to make playable (HTML) version)
- Standard output formats reference
- Customization (make new output formats or override existing)
- [ ] HTML CSS
- [ ] Higher level text-language for Gamebooks
- [ ] BGG forum output (.bgg)