Skip to content

Commit 0956b06

Browse files
committed
Formatting and fixes
1 parent bbcdf10 commit 0956b06

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

Scalatron/doc/markdown/Scalatron Pluggable Games.md

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The game to be loaded can be specified on the command line with the parameter `-
6565
to `BotWar`. The server will look for a `.jar` file with this name in the `/bin` directory below the main
6666
installation directory. For `BotWar`, for example, it would look for a file called `Scalatron/bin/BotWar.jar`.
6767

68-
Within this `.jar` file, the Scalatron then attempts to locate a class with the fully qualified class name
68+
Within this `.jar` file, Scalatron then attempts to locate a class with the fully qualified class name
6969
`scalatron.GameFactory`. When such a class is found, Scalatron next looks for a method on that class called
7070
`create`, taking no parameters and returning an instance of a class implementing the trait `scalatron.core.Game`.
7171

@@ -83,23 +83,25 @@ following methods on your `Game` implementation:
8383
def runVisually(rounds: Int, scalatron: scalatron.core.ScalatronInward)
8484
def runHeadless(rounds: Int, scalatron: scalatron.core.ScalatronInward)
8585

86-
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).
9092

9193

9294
## Implementation Details
9395

9496
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).
9799

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:
99101

100102
* run an outer loop, iterating over game rounds
101103
* 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:
103105
* update the graphical display, drawing the entities in the game and each player's score
104106
* compute what your entities can see and ask their control functions for appropriate responses
105107
* 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:
109111
## Loose Ends
110112

111113
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:
113115

114116
* the method `Game.cmdArgList` is intended to enumerate the command line arguments that your game implementation
115117
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
128130

129131
# How To Write A Game Plug-In For Scalatron
130132

131-
132133
## Step 1: Pick A Name
133134

134135
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`.
139140
## Step 2: Create The Project
140141

141142
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 [ScalatronDemoGame template on Github](https://github.com/scalatron/scalatron-demo-game).
143144

144145
The layout can be extremely simple:
145146

146147
/MyGame
147148
/src
148149
/scalatron
149-
GameFactory.scala
150-
/myGame
151-
Game.scala
150+
Game.scala
152151

153152
Your game plug-in will rely on the following libraries, which you will need to add as dependencies
154153
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:
157156
akka-actor-2.0.jar (Akka 2.0)
158157
scala-library-jar (Scala 2.9.1)
159158

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
161160
distribution of version 1.1.0.0 or later.
162161

163162
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
165164
have to end up in the Scalatron installation's `/bin` directory.
166165

167166

@@ -172,25 +171,30 @@ you may create to implement the game logic.
172171

173172
### Implement The `Game` Trait
174173

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
176178

177-
package scalatron.myGame
178179
case object Game extends scalatron.core.Game {
179180
...
180181
}
181182

183+
182184
### Implement A `GameFactory` Class
183185

184186
Implement a class `scalatron.GameFactory`, like so:
185187

186188
package scalatron
189+
187190
class GameFactory { def create() = scalatron.myGame.Game }
188191

189192

190193
### Implement Additional Classes
191194

192195
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.
194198

195199

196200

@@ -215,26 +219,27 @@ guide.
215219
The easiest way to do this is via the browser-based editor that is part of the Scalatron IDE provided by the
216220
Scalatron server. Follow these steps:
217221

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
226229

227230
The next time your game plug-in starts a game round and fetches a fresh collection of `EntityController`
228231
instances from Scalatron, your bots should be part of them and show up in your game.
229232

230233

231234

232-
## Step 6: Invite Some Frieds And Run A Tournament
235+
## Step 6: Invite Some Friends And Run A Tournament
233236

234237
Obviously, some minimal preparatory work is required on your part:
235238

236239
* 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)
237240
* 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
242+
* do some testing :-)
238243

239244

240245

0 commit comments

Comments
 (0)