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
The parameters are `rounds`, which specifies the number of tournament rounds (games) you should run before
87
-
returning, and `scalatron', which is a reference to a `trait ScalatronInward`, the API Scalatron exposes toward
88
-
game plug-ins (as opposed to `ScalatronOutward`, which is what it exposes to external users, such as the main
89
-
function and the web server).
86
+
The parameters are:
87
+
88
+
*`rounds`, which specifies the number of tournament rounds (games) you should run before returning, and
89
+
*`scalatron', which is a reference to a `trait ScalatronInward`, the API Scalatron exposes toward
90
+
game plug-ins (as opposed to `ScalatronOutward`, which is what it exposes to external users, such as the main
91
+
function and the web server).
90
92
91
93
92
94
## Implementation Details
93
95
94
96
Once control passes to `runVisually()` or `runHeadless()`, it's up to you what happens next. For details,
95
-
you can refer either to the example implementation [ScalatronDemoGame](https://github.com/scalatron/scalatron-demo-game)
96
-
or to the implementation of [BotWar](https://github.com/scalatron/scalatron/tree/master/BotWar/src/scalatron).
97
+
you can refer either to the simple example implementation in[ScalatronDemoGame](https://github.com/scalatron/scalatron-demo-game)
98
+
or to the full and rather more complex implementation of [BotWar](https://github.com/scalatron/scalatron/tree/master/BotWar/src/scalatron).
97
99
98
-
But roughly speaking, your plug-in should be doing the following things:
100
+
Roughly speaking, your plug-in should be doing the following things:
99
101
100
102
* run an outer loop, iterating over game rounds
101
103
* at the start of each round, ask Scalatron for a collection of control functions representing the bots
102
-
* run an inner loop, iterating over the simulations steps within a game; with each step:
104
+
* run an inner loop, iterating over the simulations steps within a game; within each step:
103
105
* update the graphical display, drawing the entities in the game and each player's score
104
106
* compute what your entities can see and ask their control functions for appropriate responses
105
107
* decode the responses (presumably commands) and update the game state and scores as appropriate
@@ -109,7 +111,7 @@ But roughly speaking, your plug-in should be doing the following things:
109
111
## Loose Ends
110
112
111
113
There are a few more aspects you could pay attention to, even though they are not required for a minimal
112
-
implementation (and may still change as the whole concept gets refined). These include:
114
+
implementation (and may still change as the whole concept of pluggable games gets refined). These include:
113
115
114
116
* the method `Game.cmdArgList` is intended to enumerate the command line arguments that your game implementation
115
117
understands and that a user can provide to configure your game. The BotWar game, for example uses settings like
@@ -128,7 +130,6 @@ implementation (and may still change as the whole concept gets refined). These i
128
130
129
131
# How To Write A Game Plug-In For Scalatron
130
132
131
-
132
133
## Step 1: Pick A Name
133
134
134
135
Pick a name for your game. Then derive a standardized name from it that contains no spaces or other characters
@@ -139,16 +140,14 @@ For this example, we'll use `MyGame`.
139
140
## Step 2: Create The Project
140
141
141
142
Create a directory structure for your project. The easiest way to do this is probably by copying and renaming
142
-
the `ScalatronDemoGame`[template on Github](https://github.com/scalatron/scalatron-demo-game).
143
+
the [ScalatronDemoGametemplate on Github](https://github.com/scalatron/scalatron-demo-game).
143
144
144
145
The layout can be extremely simple:
145
146
146
147
/MyGame
147
148
/src
148
149
/scalatron
149
-
GameFactory.scala
150
-
/myGame
151
-
Game.scala
150
+
Game.scala
152
151
153
152
Your game plug-in will rely on the following libraries, which you will need to add as dependencies
154
153
to your SBT build file or to your IDE-specific project file:
@@ -157,11 +156,11 @@ to your SBT build file or to your IDE-specific project file:
157
156
akka-actor-2.0.jar (Akka 2.0)
158
157
scala-library-jar (Scala 2.9.1)
159
158
160
-
You can find the first library, ScalatronCore.jar, in the Scalatron installation directory of a Scalatron
159
+
You can find the first library, `ScalatronCore.jar`, in the Scalatron installation directory of a Scalatron
161
160
distribution of version 1.1.0.0 or later.
162
161
163
162
You will then need to configure your project to generate a Java Archive (.jar) artifact with the appropriate
164
-
name, in our case `MyGame.jar`. You can build this wherever you want, but to activate it it will eventually
163
+
name, in our case `MyGame.jar`. You can build this wherever you want, but to activate it, it will eventually
165
164
have to end up in the Scalatron installation's `/bin` directory.
166
165
167
166
@@ -172,25 +171,30 @@ you may create to implement the game logic.
172
171
173
172
### Implement The `Game` Trait
174
173
175
-
Implement a class `scalatron.myGame.Game` that implements the `scalatron.core.Game` trait, like so:
174
+
Implement a class `scalatron.Game` (or `scalatron.myGame.Game` if you want a custom package - it does not matter)
175
+
that implements the `scalatron.core.Game` trait, like so:
176
+
177
+
package scalatron
176
178
177
-
package scalatron.myGame
178
179
case object Game extends scalatron.core.Game {
179
180
...
180
181
}
181
182
183
+
182
184
### Implement A `GameFactory` Class
183
185
184
186
Implement a class `scalatron.GameFactory`, like so:
185
187
186
188
package scalatron
189
+
187
190
class GameFactory { def create() = scalatron.myGame.Game }
188
191
189
192
190
193
### Implement Additional Classes
191
194
192
195
Flesh out the functionality of your `Game` implementation, starting with the method `runVisually()`.
193
-
Please check out the example code of the `ScalatronDemoGame` for details.
196
+
Please check out the example code of the `ScalatronDemoGame` and the outline of the overally architecture above
197
+
for details.
194
198
195
199
196
200
@@ -215,26 +219,27 @@ guide.
215
219
The easiest way to do this is via the browser-based editor that is part of the Scalatron IDE provided by the
216
220
Scalatron server. Follow these steps:
217
221
218
-
* launch the Scalatron server app, as described above
219
-
* this should automatically bring up a browser window pointing at the correct address
220
-
* create one or more user accounts that will be associated with your bots, say `PlayerA` and `PlayerB`
221
-
* log in as each of these players in turn
222
-
* create a source code file that contains the required classes (see the Player Setup guide):
223
-
`ControlFunctionFactory` and a bot implementation.
224
-
* in the editor toolbar, click **Publish into Tournament**
225
-
* this will upload the source code, build it and publish the bot into the tournament
222
+
* Launch the Scalatron server app, as described above
223
+
* This should automatically bring up a browser window pointing at the correct address
224
+
* Create one or more user accounts that will be associated with your bots, say `PlayerA` and `PlayerB`
225
+
* Log in as each of these players in turn
226
+
* Create a source code file that contains the required `ControlFunctionFactory` implementation (see the Player Setup guide)
227
+
* In the editor toolbar, click **Publish into Tournament**
228
+
* This will upload the source code, build it and publish the bot into the tournament
226
229
227
230
The next time your game plug-in starts a game round and fetches a fresh collection of `EntityController`
228
231
instances from Scalatron, your bots should be part of them and show up in your game.
229
232
230
233
231
234
232
-
## Step 6: Invite Some Frieds And Run A Tournament
235
+
## Step 6: Invite Some Friends And Run A Tournament
233
236
234
237
Obviously, some minimal preparatory work is required on your part:
235
238
236
239
* write some documentation for the rules of your game (see the [Scalatron Game Rules for BotWar](https://github.com/scalatron/scalatron/blob/master/Scalatron/doc/markdown/Scalatron%20Game%20Rules.md) for an example)
237
240
* write some documentation for the game/bot protocol of your game (see the [Scalatron Protocol for BotWar](https://github.com/scalatron/scalatron/blob/master/Scalatron/doc/markdown/Scalatron%20Protocol.md) for an example)
241
+
* write a few simple bots as examples and for testing purposes
0 commit comments