Skip to content

Commit 8a16de7

Browse files
committed
Revert "Revert "Preparatory refactoring towards pluggable games; separates out into 'scalatron.core' a set of classes shared by game implementations and Scalatron API""
This reverts commit 76b7d33.
1 parent 76b7d33 commit 8a16de7

24 files changed

+178
-185
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
layout: default
3+
title: Scalatron Pluggable Games
4+
subtitle: Draft Architecture Documentation
5+
---
6+
7+
WARNING: this is a draft documenting a work-in-progress!
8+
9+
# Summary
10+
11+
The goal of this project is to move the implementation of the BotWar game implementation into a plug-in and to turn
12+
Scalatron into a framework and server for hosting a variety of such pluggable games.
13+
14+
15+
# Decisions
16+
17+
The primary decisions concern the level of abstraction: what should the framework require all pluggable games to
18+
have in common?
19+
20+
21+
# TODO
22+
23+
24+
25+
26+
27+

Scalatron/src/scalatron/botwar/AugmentedDynamics.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package scalatron.botwar
55

66
import scala.util.Random
77
import scalatron.botwar.Decoration.{Bonus, Explosion, Text, Bonk, Annihilation}
8-
import scalatron.scalatron.impl.TournamentRoundResult
8+
import scalatron.core.TournamentRoundResult
99

1010

1111
case object AugmentedDynamics extends ((State,Random,Iterable[(Entity.Id,Iterable[Command])]) => Either[State,TournamentRoundResult])

Scalatron/src/scalatron/botwar/Board.scala

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ package scalatron.botwar
55

66
import State.Time
77
import scala.util.Random
8-
import scalatron.scalatron.impl.Plugin
98
import BoardParams.Perimeter
109
import akka.dispatch.{Await, Future, ExecutionContext}
11-
import akka.util.Duration
1210
import akka.util.duration._
1311
import java.util.concurrent.TimeoutException
12+
import scalatron.core.Plugin
1413

1514

1615
/** Contains the temporally variable aspects of the game state.
@@ -180,17 +179,12 @@ object Board
180179
val controlFunction = plugin.controlFunctionFactory.apply()
181180

182181
// invoke Welcome()
183-
plugin match {
184-
case external: Plugin.External =>
185-
controlFunction(
186-
Protocol.ServerOpcode.Welcome + "(" +
187-
"name=" + external.name + "," +
188-
"path=" + external.dirPath + "," +
189-
"apocalypse=" + stepsPerRound + "," +
190-
"round=" + roundIndex +
191-
")")
192-
case internal: Plugin.Internal => // OK
193-
}
182+
controlFunction(
183+
Protocol.ServerOpcode.Welcome + "(" +
184+
"name=" + plugin.name + "," +
185+
"apocalypse=" + stepsPerRound + "," +
186+
"round=" + roundIndex +
187+
")")
194188

195189
Some((plugin, controlFunction))
196190
} catch {

Scalatron/src/scalatron/botwar/BotWar.scala

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ package scalatron.botwar
66
import renderer.Renderer
77
import scalatron.botwar.BotWarSimulation.SimState
88
import java.awt.event.{WindowEvent, WindowAdapter, KeyEvent, KeyListener}
9-
import scalatron.scalatron.api.Scalatron
10-
import scalatron.scalatron.impl.{TournamentRoundResult, TournamentState, Plugin, PluginCollection, Game}
119
import akka.dispatch.ExecutionContext
1210
import akka.actor.ActorSystem
11+
import scalatron.core._
1312

1413

1514
/** BotWar: an implementation of the Scalatron Game trait.
@@ -18,12 +17,7 @@ case object BotWar extends Game
1817
{
1918
val name = Constants.GameName
2019

21-
val pluginLoadSpec =
22-
PluginCollection.LoadSpec(
23-
Scalatron.Constants.JarFilename, // "ScalatronBot.jar"
24-
"scalatron.botwar.botPlugin",
25-
"ControlFunctionFactory")
26-
20+
def gameSpecificPackagePath = "scalatron.botwar.botPlugin"
2721

2822
def runVisually(
2923
pluginPath: String,
@@ -95,7 +89,7 @@ case object BotWar extends Game
9589
}
9690

9791

98-
var pluginCollection = PluginCollection(pluginPath, pluginLoadSpec, verbose)
92+
var pluginCollection = PluginCollection(pluginPath, gameSpecificPackagePath, verbose)
9993

10094
// now perform game runs ad infinitum
10195
var roundIndex = 0
@@ -166,7 +160,7 @@ case object BotWar extends Game
166160
tournamentState.addResult(tournamentRoundResult)
167161
}
168162

169-
var pluginCollection = PluginCollection(pluginPath, pluginLoadSpec, verbose)
163+
var pluginCollection = PluginCollection(pluginPath, gameSpecificPackagePath, verbose)
170164

171165
// now perform game runs ad infinitum
172166
var roundIndex = 0
@@ -208,7 +202,7 @@ case object BotWar extends Game
208202
* @return the initial simulation state
209203
*/
210204
def startHeadless(
211-
plugins: Iterable[Plugin.External],
205+
plugins: Iterable[Plugin.FromJarFile],
212206
secureMode: Boolean,
213207
argMap: Map[String,String]
214208
)(
@@ -240,7 +234,7 @@ case object BotWar extends Game
240234
* @return the initial simulation state
241235
*/
242236
def startHeadless(
243-
plugins: Iterable[Plugin.External],
237+
plugins: Iterable[Plugin.FromJarFile],
244238
permanentConfig: PermanentConfig,
245239
gameConfig: Config
246240
)(

Scalatron/src/scalatron/botwar/BotWarSimulation.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package scalatron.botwar
55

66
import scala.util.Random
7-
import scalatron.scalatron.impl.{Plugin, TournamentRoundResult}
7+
import scalatron.core.{Plugin, TournamentRoundResult}
88
import akka.dispatch.ExecutionContext
99
import akka.actor.ActorSystem
1010

@@ -27,7 +27,7 @@ object BotWarSimulation
2727

2828

2929
case class Factory(config: Config) extends Simulation.Factory[SimState,TournamentRoundResult] {
30-
def createInitialState(randomSeed: Int, plugins: Iterable[Plugin.External])(executionContextForUntrustedCode: ExecutionContext) = {
30+
def createInitialState(randomSeed: Int, plugins: Iterable[Plugin.FromJarFile])(executionContextForUntrustedCode: ExecutionContext) = {
3131
val state = State.createInitial(config, randomSeed, plugins)(executionContextForUntrustedCode)
3232
SimState(state)
3333
}

Scalatron/src/scalatron/botwar/Config.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
package scalatron.botwar
55

6-
import scalatron.scalatron.impl.Plugin
6+
import scalatron.core.{PermanentConfig, Plugin}
77

88

99
/** Configuration container for a specific game rounds. Incorporates the permanent configuration
@@ -17,7 +17,7 @@ case class Config(
1717

1818

1919
object Config {
20-
def create(permanentConfig: PermanentConfig, roundIndex: Int, plugins: Iterable[Plugin.External], argMap: Map[String,String]) = {
20+
def create(permanentConfig: PermanentConfig, roundIndex: Int, plugins: Iterable[Plugin.FromJarFile], argMap: Map[String,String]) = {
2121
val pluginCount = plugins.size
2222

2323
// compute the default arena size

Scalatron/src/scalatron/botwar/Dynamics.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
package scalatron.botwar
55

66
import scala.util.Random
7-
import scalatron.scalatron.impl.TournamentRoundResult
87
import akka.util.duration._
98
import akka.dispatch._
109
import java.util.concurrent.TimeoutException
1110
import akka.actor.ActorSystem
1211
import akka.util.Duration
12+
import scalatron.core.TournamentRoundResult
1313

1414

1515
/** Game dynamics. Function that, when applied to a game state, returns either a successor

Scalatron/src/scalatron/botwar/Entity.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package scalatron.botwar
66
import State.Time
77
import util.Random
88
import java.lang.IllegalStateException
9-
import scalatron.scalatron.impl.Plugin
9+
import scalatron.core.Plugin
1010

1111

1212
/** A game entity. An entity can be a collidable Bot (player, slave, beast, plant, wall) or

Scalatron/src/scalatron/botwar/Simulation.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
*/
44
package scalatron.botwar
55

6-
import scalatron.scalatron.impl.Plugin
76
import akka.util.Duration
87
import akka.dispatch.{ExecutionContext, Future, Await}
98
import akka.actor.ActorSystem
9+
import scalatron.core.Plugin
1010

1111

1212
/** Traits for generic simulations, of which a game like BotWar is an example.
@@ -32,7 +32,7 @@ object Simulation
3232
* @tparam R type of the result returned by the simulator (arbitrary)
3333
*/
3434
trait Factory[S <: State[S, R], R] {
35-
def createInitialState(randomSeed: Int, plugins: Iterable[Plugin.External])(executionContextForUntrustedCode: ExecutionContext) : S
35+
def createInitialState(randomSeed: Int, plugins: Iterable[Plugin.FromJarFile])(executionContextForUntrustedCode: ExecutionContext) : S
3636
}
3737

3838
/** Simulation.Runner: a generic runner for simulations that uses .step() to iteratively
@@ -52,7 +52,7 @@ object Simulation
5252
* @return an optional simulation result (if the simulation was not prematurely aborted)
5353
*/
5454
def apply(
55-
plugins: Iterable[Plugin.External],
55+
plugins: Iterable[Plugin.FromJarFile],
5656
randomSeed: Int
5757
)(
5858
actorSystem: ActorSystem,

Scalatron/src/scalatron/botwar/State.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
package scalatron.botwar
55

66
import State.Time
7-
import scalatron.scalatron.impl.Plugin
87
import akka.dispatch.ExecutionContext
8+
import scalatron.core.Plugin
99

1010

1111
/** Game state storing the current (game) time, the board parameters, the actual board (i.e.

0 commit comments

Comments
 (0)