Skip to content

Commit b09fc6e

Browse files
authored
#84: Marking functions as required/optional. Docs for postBuild
1 parent ca81fd9 commit b09fc6e

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

docs/10-required-functions.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Functions a module must include
1+
# Main functions called when running a module
22

33
Modules, containing any specific code to run for a game, are added to the object `modules`, for example `modules.myModule = {}`.
44

5-
The Bot Playtesting Toolkit expects some functions in a module. These functions should be added to the individual module objects, for example `modules.myModule.buildInitialData = function() {...}`.
5+
The Bot Playtesting Toolkit expects some functions in a module. Additionally, some particular functions are called if they exist and are otherwise skipped. These functions are added to the individual module objects, for example `modules.myModule.buildInitialData = function() {...}`.
66

77
## buildInitialData()
88

9-
This function is responsible for two things.
9+
This function is optional. It is responsible for two things.
1010

1111
**The first is populating the `BPTstatic` object with appropriate data.** This is a good place to put values that are used in different parts of the code, such as the number of victory points that ends the game, default values for various things, or other data you might want to store in globally accessible variables. Note that all the data stored here should be non-changing, and _not_ change between games or within games.
1212

@@ -27,27 +27,33 @@ Building the data for these types of objects is usually done by reading data fro
2727

2828
Note that `buildInitialData()` must return the game state seed, and should thus end with `return gameStateSeed`.
2929

30+
## postBuild()
31+
32+
This function is optional. It is used to process any data after the gameState has been created, but before the first iteration. Its intended use is to make any heavy processing of data once only, when possible.
33+
34+
Any data that should be stored must be stored using setCache(), to be available throughout all iterations. **Note that objects with methods (such as spaces, decks, etc.) can not be cached.**
35+
3036
## preIteration()
3137

32-
The game state seed is processed by BPT before each game iteration, and the globally accessible `gameState` variable is set up. There are a number of things that can be taken care of automatically, such as shuffling decks, filling card displays or placing pawns on tracks, but there may by other more customized preparations that needs to be taken care of as well. Any such preparations are done by `preIteration()`.
38+
This function is optional. The game state seed is processed by BPT before each game iteration, and the globally accessible `gameState` variable is set up. There are a number of things that can be taken care of automatically, such as shuffling decks, filling card displays or placing pawns on tracks, but there may by other more customized preparations that needs to be taken care of as well. Any such preparations are done by `preIteration()`.
3339

3440
This function could for example give each agent a random quest card, randomize player order, or place cubes on the board according to the top three cards in a deck. The function may manipulate `gameState` in any way necessary. It does not take any arguments and is not expected to return anything.
3541

3642
## playRound()
3743

38-
This function contains much of the actual game. For complex games, this function will probably either be quite long or split up into sub functions. Much of the complex work is also delegated to the agent strategies.
44+
This function is required. It contains much of the actual game. For complex games, this function will probably either be quite long or split up into sub functions. Much of the complex work is also delegated to the agent strategies.
3945

4046
The function is called by BPT once every round, but for some games it might be easier to instead consider each round as a turn. The number of the round is stored in `gameState.round` by BPT.
4147

4248
This function may use or manipulate `gameState` in any way necessary. It does not take any arguments and is not expected to return anything.
4349

4450
## gameOver()
4551

46-
This function is called before each round. It reads the `gameState` and returns either `true` or `false`. If it returns `true`, the current game iteration ends.
52+
This function is required. It is called before each round. It reads the `gameState` and returns either `true` or `false`. If it returns `true`, the current game iteration ends.
4753

4854
## buildStatistics()
4955

50-
This function is called after the end of each game iteration. It should collect or build any data from the `gameState` that should be included in the statistics for all the played games. The data should be returned in an object, with column header as property name.
56+
This function is required. It is called after the end of each game iteration. It should collect or build any data from the `gameState` that should be included in the statistics for all the played games. The data should be returned in an object, with column header as property name.
5157

5258
Some things to note:
5359

0 commit comments

Comments
 (0)