Skip to content

Commit 76b7d33

Browse files
committed
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 578efa3.
1 parent 578efa3 commit 76b7d33

24 files changed

+185
-178
lines changed

Scalatron/doc/markdown/Scalatron Pluggable Games.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

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.core.TournamentRoundResult
8+
import scalatron.scalatron.impl.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: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ package scalatron.botwar
55

66
import State.Time
77
import scala.util.Random
8+
import scalatron.scalatron.impl.Plugin
89
import BoardParams.Perimeter
910
import akka.dispatch.{Await, Future, ExecutionContext}
11+
import akka.util.Duration
1012
import akka.util.duration._
1113
import java.util.concurrent.TimeoutException
12-
import scalatron.core.Plugin
1314

1415

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

181182
// invoke Welcome()
182-
controlFunction(
183-
Protocol.ServerOpcode.Welcome + "(" +
184-
"name=" + plugin.name + "," +
185-
"apocalypse=" + stepsPerRound + "," +
186-
"round=" + roundIndex +
187-
")")
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+
}
188194

189195
Some((plugin, controlFunction))
190196
} catch {

Scalatron/src/scalatron/botwar/BotWar.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ 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}
911
import akka.dispatch.ExecutionContext
1012
import akka.actor.ActorSystem
11-
import scalatron.core._
1213

1314

1415
/** BotWar: an implementation of the Scalatron Game trait.
@@ -17,7 +18,12 @@ case object BotWar extends Game
1718
{
1819
val name = Constants.GameName
1920

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

2228
def runVisually(
2329
pluginPath: String,
@@ -89,7 +95,7 @@ case object BotWar extends Game
8995
}
9096

9197

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

94100
// now perform game runs ad infinitum
95101
var roundIndex = 0
@@ -160,7 +166,7 @@ case object BotWar extends Game
160166
tournamentState.addResult(tournamentRoundResult)
161167
}
162168

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

165171
// now perform game runs ad infinitum
166172
var roundIndex = 0
@@ -202,7 +208,7 @@ case object BotWar extends Game
202208
* @return the initial simulation state
203209
*/
204210
def startHeadless(
205-
plugins: Iterable[Plugin.FromJarFile],
211+
plugins: Iterable[Plugin.External],
206212
secureMode: Boolean,
207213
argMap: Map[String,String]
208214
)(
@@ -234,7 +240,7 @@ case object BotWar extends Game
234240
* @return the initial simulation state
235241
*/
236242
def startHeadless(
237-
plugins: Iterable[Plugin.FromJarFile],
243+
plugins: Iterable[Plugin.External],
238244
permanentConfig: PermanentConfig,
239245
gameConfig: Config
240246
)(

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.core.{Plugin, TournamentRoundResult}
7+
import scalatron.scalatron.impl.{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.FromJarFile])(executionContextForUntrustedCode: ExecutionContext) = {
30+
def createInitialState(randomSeed: Int, plugins: Iterable[Plugin.External])(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.core.{PermanentConfig, Plugin}
6+
import scalatron.scalatron.impl.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.FromJarFile], argMap: Map[String,String]) = {
20+
def create(permanentConfig: PermanentConfig, roundIndex: Int, plugins: Iterable[Plugin.External], 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
78
import akka.util.duration._
89
import akka.dispatch._
910
import java.util.concurrent.TimeoutException
1011
import akka.actor.ActorSystem
1112
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.core.Plugin
9+
import scalatron.scalatron.impl.Plugin
1010

1111

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

Scalatron/src/scalatron/core/PermanentConfig.scala renamed to Scalatron/src/scalatron/botwar/PermanentConfig.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/** This material is intended as a community resource and is licensed under the
22
* Creative Commons Attribution 3.0 Unported License. Feel free to use, modify and share it.
33
*/
4-
package scalatron.core
4+
package scalatron.botwar
5+
56

67
/** Configuration settings that won't change round-to-round
78
* @param secureMode if true, certain bot processing restrictions apply
@@ -10,9 +11,8 @@ package scalatron.core
1011
case class PermanentConfig(secureMode: Boolean, stepsPerRound: Int)
1112

1213

13-
object PermanentConfig
14-
{
15-
def fromArgMap(secureMode: Boolean, argMap: Map[String, String]) = {
14+
object PermanentConfig {
15+
def fromArgMap(secureMode: Boolean, argMap: Map[String,String]) = {
1616
val steps = argMap.get("-steps").map(_.toInt).getOrElse(5000)
1717
PermanentConfig(secureMode = secureMode, stepsPerRound = steps)
1818
}

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
67
import akka.util.Duration
78
import akka.dispatch.{ExecutionContext, Future, Await}
89
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.FromJarFile])(executionContextForUntrustedCode: ExecutionContext) : S
35+
def createInitialState(randomSeed: Int, plugins: Iterable[Plugin.External])(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.FromJarFile],
55+
plugins: Iterable[Plugin.External],
5656
randomSeed: Int
5757
)(
5858
actorSystem: ActorSystem,

0 commit comments

Comments
 (0)