|
1 | 1 | # About |
2 | 2 |
|
3 | | -The Game Runner lets you run your game locally during developement. It comes with a handy HTML package to watch each game's replay. |
4 | | - |
5 | | -You can create your own AI for your game and use the Game Runner to connect it to your game's implementation. |
6 | | - |
7 | | -You can also fiddle with your game's initialization input, such as the seed for random values (for **Multiplayer** games) or a test case file (for **Solo** games, the content of such files is detailed below). |
8 | | - |
9 | | -# Usage |
10 | | - |
11 | | -Include the dependency below in the pom.xml of your project. |
12 | | -```xml |
13 | | -<dependency> |
14 | | - <groupId>com.codingame.gameengine</groupId> |
15 | | - <artifactId>runner</artifactId> |
16 | | - <version>2.3</version> |
17 | | -</dependency> |
18 | | -``` |
19 | | -Or a more recent version. |
20 | | - |
21 | | -Instantiate a `MultiplayerGameRunner` or a `SoloGameRunner` to launch a game with the `start()` method. This will create a temporary directory and start a server to serve the files of that directory. You need not stop the previous server to launch a new game. |
22 | | - |
23 | | -By default, you can access the game viewer for testing at [http://localhost:8888/test.html](http://localhost:8888/test.html). You may change the configuration of the game viewer by editing the `config.js` file. |
24 | | - |
25 | | -Warning ⚠ To use the game viewer locally, your browser must support ES6 JavaScript **modules**. For Chrome, that's version 61 or more. For Firefox, from version 54 this feature is behind the `dom.moduleScripts.enabled` preference. To change preferences in Firefox, visit `about:config`. |
26 | | - |
27 | | - |
28 | | -# Examples |
29 | | - |
30 | | -In order to run a game, you must have prepared a `Referee` and a `Player`. The game will surely fail to finish if they are not properly implemented. See [Game Manager](../engine/core/) for details. |
31 | | - |
32 | | -## Running a **Multiplayer** game |
33 | | - |
34 | | -### Using the same java class for each player: |
35 | | -```java |
36 | | -MultiplayerGameRunner gameRunner = new MultiplayerGameRunner(); |
37 | | -gameRunner.addAgent(Player.class); |
38 | | -gameRunner.addAgent(Player.class); |
39 | | -gameRunner.start(); |
40 | | - |
41 | | -``` |
42 | | -⚠ _This method will prevent the agent from printing to stdout from any other class than Player. It has been deprecated for this reason._ |
43 | | - |
44 | | -### Using external python programs as players: |
45 | | -```java |
46 | | -MultiplayerGameRunner gameRunner = new MultiplayerGameRunner(); |
47 | | - |
48 | | -gameRunner.addAgent("python3 /home/user/player1.py"); |
49 | | -gameRunner.addAgent("python3 /home/user/player2.py"); |
50 | | -gameRunner.addAgent("python3 /home/user/player3.py"); |
51 | | - |
52 | | -gameRunner.start(); |
53 | | -``` |
54 | | - |
55 | | -### Using a custom seed: |
56 | | -```java |
57 | | -// I want to debug the strange case of this particuliar seed: 53295539 |
58 | | - |
59 | | -Properties refereeInput = new Properties(); |
60 | | -refereeInput.put("seed", "53295539"); |
61 | | - |
62 | | -MultiplayerGameRunner gameRunner = new MultiplayerGameRunner(); |
63 | | -gameRunner.setGameParameters(refereeInput); |
64 | | -gameRunner.addAgent(Player1.class); |
65 | | -gameRunner.addAgent(Player2.class); |
66 | | -gameRunner.start(); |
67 | | -``` |
68 | | - |
69 | | -## Running a **Solo** game |
70 | | - |
71 | | -### Using a java class and a test case with its filename: |
72 | | -```java |
73 | | -SoloGameRunner gameRunner = new SoloGameRunner(); |
74 | | -gameRunner.setTestCase("test1.json"); // You must set a test case to run your game. |
75 | | -gameRunner.setAgent(Player.class); |
76 | | -gameRunner.start(); |
77 | | -``` |
78 | | - |
79 | | ---- |
80 | | -### Test case file |
81 | | - |
82 | | -You will need to create test case files to run your **Solo** game. If you are creating a **Multiplayer** game, you can skip this section. |
83 | | - |
84 | | -Your test cases must be named `test<number>.json` and placed in the `config` directory. Their `<number>` determine the order they will be listed in the CodinGame IDE. Here is an example: |
85 | | - |
86 | | -`test1.json` |
87 | | -```json |
88 | | -{ |
89 | | - "title": { |
90 | | - "2": "One path", |
91 | | - "1": "Un seul chemin" |
92 | | - }, |
93 | | - "testIn": ".o...\\n.ooo.\\n...o.", |
94 | | - "isTest": "true", |
95 | | - "isValidator": "false" |
96 | | -} |
97 | | -``` |
98 | | -- **title:** |
99 | | - - **2:** English title, this parameter is mandatory. |
100 | | - - **1:** French title, optional. |
101 | | -- **testIn:** The content of your test case. It can contain multiple lines separated with `\\n`. |
102 | | -- **isTest:** If true, this test will be visible and used as a regular test case. |
103 | | -- **isValidator:** If true, this test will be use to validate the player's code. You can use this to avoid hardcoded solutions. |
104 | | - |
105 | | -### Activating game logs |
106 | | - |
107 | | -You can view the data that the Referee and the Players send each other by editing the built-in logger's settings. |
108 | | -To do this, open `log4j2.properties` in the root of your project and replace ```rootLogger.level = warn``` with ```rootLogger.level = info```. |
109 | | -Additionally, if you would like to see the output of the different modules, you can use: |
110 | | -`rootLogger.level = trace`. |
111 | | - |
112 | | - |
113 | | -## Viewing a replay |
114 | | - |
115 | | -Once a game is run, files are copied into a temporary folder. A server is started to serve those files on `localhost:8888`. |
116 | | - |
117 | | -The test page `/test.html` let's you watch the replay as it would appear on CodinGame. |
118 | | - |
119 | | -Many of the viewers game-specific parameters may be changed by the default `config.js` file located in `src/main/resources/view` of your game's project. These parameters include: |
120 | | -* The list of modules needed by the game. |
121 | | -* The colours for the different players (affects the IDE). |
122 | | - |
123 | | -### Loading assets |
124 | | -Assets are expected to be placed in the `src/main/resources/view/assets` folder of your game's project. |
125 | | - |
126 | | -You can then use the images in the texture cache with the [Graphic Entity Module](../modules/entities/): |
127 | | -```java |
128 | | -entityManager.createSprite.setImage("background.png"); |
129 | | -``` |
130 | | - |
131 | | -The game's replay is run using an engine based on [Pixi.js](http://www.pixijs.com/). |
132 | | - |
133 | | -# Documentation |
134 | | - |
135 | | -## Reference API |
136 | | - TODO |
| 3 | +Check the [game runner documentation](https://tech.io/playgrounds/25775/codingame-sdk-documentation/game-runner). |
0 commit comments