Package: ggp-template
Toolchain for writing General Game PlayersThis simple script allows you to build
and organize sophisticated general game playing (GGP)
projects. Currently, players are defined by a single.htmlfile,
which means that projects are either confined to a single file
or require a lot of tedious, error-prone manual copy-and-paste if functionality
is spread across different files.This script allows you to defineonlythe functionality
for the player that you are creating, avoiding all the boilerplate
and copying and pasting. It also allows you to manage larger projects
by generating anhtmlfile from a template and (potentially multiple)
javascript files. Finally, it allows you to load web workers
in a natural and easy way.SetupMake sure you have python and pip installed. Then run the following
in a terminal:pip install ggp-templateUsageTo create a new player from the sample template, runpython -m ggp.new myplayer.jsTo build an HTML file from a player, runpython -m ggp.make myplayer.js --ident=your_identifierYou can build multiple javascript files by simply passing multiple
arguments (no dependency resolution is done; the scripts are added
to the HTML file in the order they are passed in):python -m ggp.make lib.js myplayer.js --ident=your_identifierOptionsThemakesubcommand takes the following options:workerWorker scripts are added after main scripts usingtype=javascript/worker, which means they are not run by the browser, but their ids can still be passed toloadWorker.templateThe template HTML file to use (defaults to sample.html fromhttp://ggp.stanford.edu/gamemaster/gameplayers/sample.html)identThe identifier for your playerstrategyThe strategy name that is displayed on the pagetitleThe title for the page (defaults to the strategy and identifier)While javascript files are converted todata:text,(hence URI encoded),
none of the other parameters are escaped. Therefore,
if thetitlecontains valid HTML, it will simply be inserted into the HTML
file without any extra escaping.All script tags will be created with anidcorresponding by default to the stem of the file.
This is useful for loading web workers (see below).Using WebWorkersIf any--workerflags are passed, an extra fileloadworker.jsis automatically loaded.
To useloadWorker, in any file, simply call:const worker = loadWorker(scriptId, dependencies, nestedDependencies);Here,scriptIdis the id of a script that was passed intoggp.make. Note that the default
id for a file is the file name stem (e.g. the id formyplayer/lib/shuffle.jswould beshuffle).
You can change the id by passing it explicitly if you wish:python -m ggp.make myplayer/lib/shuffle.js,newidwould
loadmyplayer/lib/shuffle.jswith idnewid.If the worker itself needs to load new workers, pass those workers and their dependencies intonestedDependencies.
Note that this worker will then have access to the script to pass it intonestedDependenciesitself, so this
allows arbitrarily nested WebWorkers.Note that all main worker scripts should be prefixed with--worker, so that the browser does not execute them on
the top page. Files that simply define utility functions, however, can be loaded without--worker,
even if they are used only by web workers.RecommendationsMost editors will allow you to set up a custom build
command. In vscode, for example, you can create atasks.jsonfile in the project directory and set this to be the default
build task as describedhere.If you want more sophisticated tooling, such as automatic dependency resolution
or compiling from e.g. Typescript, usewebpack.