You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/10-required-functions.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
# Functions a module must include
1
+
# Main functions called when running a module
2
2
3
3
Modules, containing any specific code to run for a game, are added to the object `modules`, for example `modules.myModule = {}`.
4
4
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() {...}`.
6
6
7
7
## buildInitialData()
8
8
9
-
This function is responsible for two things.
9
+
This function is optional. It is responsible for two things.
10
10
11
11
**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.
12
12
@@ -27,27 +27,33 @@ Building the data for these types of objects is usually done by reading data fro
27
27
28
28
Note that `buildInitialData()` must return the game state seed, and should thus end with `return gameStateSeed`.
29
29
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
+
30
36
## preIteration()
31
37
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()`.
33
39
34
40
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.
35
41
36
42
## playRound()
37
43
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.
39
45
40
46
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.
41
47
42
48
This function may use or manipulate `gameState` in any way necessary. It does not take any arguments and is not expected to return anything.
43
49
44
50
## gameOver()
45
51
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.
47
53
48
54
## buildStatistics()
49
55
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.
0 commit comments