Skip to content

Commit

Permalink
Revert "Preparatory refactoring towards pluggable games; separates ou…
Browse files Browse the repository at this point in the history
…t into 'scalatron.core' a set of classes shared by game implementations and Scalatron API"

This reverts commit 578efa3.
  • Loading branch information
scalatron committed May 21, 2012
1 parent 578efa3 commit 76b7d33
Show file tree
Hide file tree
Showing 24 changed files with 185 additions and 178 deletions.
27 changes: 0 additions & 27 deletions Scalatron/doc/markdown/Scalatron Pluggable Games.md

This file was deleted.

2 changes: 1 addition & 1 deletion Scalatron/src/scalatron/botwar/AugmentedDynamics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package scalatron.botwar

import scala.util.Random
import scalatron.botwar.Decoration.{Bonus, Explosion, Text, Bonk, Annihilation}
import scalatron.core.TournamentRoundResult
import scalatron.scalatron.impl.TournamentRoundResult


case object AugmentedDynamics extends ((State,Random,Iterable[(Entity.Id,Iterable[Command])]) => Either[State,TournamentRoundResult])
Expand Down
20 changes: 13 additions & 7 deletions Scalatron/src/scalatron/botwar/Board.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ package scalatron.botwar

import State.Time
import scala.util.Random
import scalatron.scalatron.impl.Plugin
import BoardParams.Perimeter
import akka.dispatch.{Await, Future, ExecutionContext}
import akka.util.Duration
import akka.util.duration._
import java.util.concurrent.TimeoutException
import scalatron.core.Plugin


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

// invoke Welcome()
controlFunction(
Protocol.ServerOpcode.Welcome + "(" +
"name=" + plugin.name + "," +
"apocalypse=" + stepsPerRound + "," +
"round=" + roundIndex +
")")
plugin match {
case external: Plugin.External =>
controlFunction(
Protocol.ServerOpcode.Welcome + "(" +
"name=" + external.name + "," +
"path=" + external.dirPath + "," +
"apocalypse=" + stepsPerRound + "," +
"round=" + roundIndex +
")")
case internal: Plugin.Internal => // OK
}

Some((plugin, controlFunction))
} catch {
Expand Down
18 changes: 12 additions & 6 deletions Scalatron/src/scalatron/botwar/BotWar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package scalatron.botwar
import renderer.Renderer
import scalatron.botwar.BotWarSimulation.SimState
import java.awt.event.{WindowEvent, WindowAdapter, KeyEvent, KeyListener}
import scalatron.scalatron.api.Scalatron
import scalatron.scalatron.impl.{TournamentRoundResult, TournamentState, Plugin, PluginCollection, Game}
import akka.dispatch.ExecutionContext
import akka.actor.ActorSystem
import scalatron.core._


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

def gameSpecificPackagePath = "scalatron.botwar.botPlugin"
val pluginLoadSpec =
PluginCollection.LoadSpec(
Scalatron.Constants.JarFilename, // "ScalatronBot.jar"
"scalatron.botwar.botPlugin",
"ControlFunctionFactory")


def runVisually(
pluginPath: String,
Expand Down Expand Up @@ -89,7 +95,7 @@ case object BotWar extends Game
}


var pluginCollection = PluginCollection(pluginPath, gameSpecificPackagePath, verbose)
var pluginCollection = PluginCollection(pluginPath, pluginLoadSpec, verbose)

// now perform game runs ad infinitum
var roundIndex = 0
Expand Down Expand Up @@ -160,7 +166,7 @@ case object BotWar extends Game
tournamentState.addResult(tournamentRoundResult)
}

var pluginCollection = PluginCollection(pluginPath, gameSpecificPackagePath, verbose)
var pluginCollection = PluginCollection(pluginPath, pluginLoadSpec, verbose)

// now perform game runs ad infinitum
var roundIndex = 0
Expand Down Expand Up @@ -202,7 +208,7 @@ case object BotWar extends Game
* @return the initial simulation state
*/
def startHeadless(
plugins: Iterable[Plugin.FromJarFile],
plugins: Iterable[Plugin.External],
secureMode: Boolean,
argMap: Map[String,String]
)(
Expand Down Expand Up @@ -234,7 +240,7 @@ case object BotWar extends Game
* @return the initial simulation state
*/
def startHeadless(
plugins: Iterable[Plugin.FromJarFile],
plugins: Iterable[Plugin.External],
permanentConfig: PermanentConfig,
gameConfig: Config
)(
Expand Down
4 changes: 2 additions & 2 deletions Scalatron/src/scalatron/botwar/BotWarSimulation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package scalatron.botwar

import scala.util.Random
import scalatron.core.{Plugin, TournamentRoundResult}
import scalatron.scalatron.impl.{Plugin, TournamentRoundResult}
import akka.dispatch.ExecutionContext
import akka.actor.ActorSystem

Expand All @@ -27,7 +27,7 @@ object BotWarSimulation


case class Factory(config: Config) extends Simulation.Factory[SimState,TournamentRoundResult] {
def createInitialState(randomSeed: Int, plugins: Iterable[Plugin.FromJarFile])(executionContextForUntrustedCode: ExecutionContext) = {
def createInitialState(randomSeed: Int, plugins: Iterable[Plugin.External])(executionContextForUntrustedCode: ExecutionContext) = {
val state = State.createInitial(config, randomSeed, plugins)(executionContextForUntrustedCode)
SimState(state)
}
Expand Down
4 changes: 2 additions & 2 deletions Scalatron/src/scalatron/botwar/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package scalatron.botwar

import scalatron.core.{PermanentConfig, Plugin}
import scalatron.scalatron.impl.Plugin


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


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

// compute the default arena size
Expand Down
2 changes: 1 addition & 1 deletion Scalatron/src/scalatron/botwar/Dynamics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
package scalatron.botwar

import scala.util.Random
import scalatron.scalatron.impl.TournamentRoundResult
import akka.util.duration._
import akka.dispatch._
import java.util.concurrent.TimeoutException
import akka.actor.ActorSystem
import akka.util.Duration
import scalatron.core.TournamentRoundResult


/** Game dynamics. Function that, when applied to a game state, returns either a successor
Expand Down
2 changes: 1 addition & 1 deletion Scalatron/src/scalatron/botwar/Entity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package scalatron.botwar
import State.Time
import util.Random
import java.lang.IllegalStateException
import scalatron.core.Plugin
import scalatron.scalatron.impl.Plugin


/** A game entity. An entity can be a collidable Bot (player, slave, beast, plant, wall) or
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/** This material is intended as a community resource and is licensed under the
* Creative Commons Attribution 3.0 Unported License. Feel free to use, modify and share it.
*/
package scalatron.core
package scalatron.botwar


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


object PermanentConfig
{
def fromArgMap(secureMode: Boolean, argMap: Map[String, String]) = {
object PermanentConfig {
def fromArgMap(secureMode: Boolean, argMap: Map[String,String]) = {
val steps = argMap.get("-steps").map(_.toInt).getOrElse(5000)
PermanentConfig(secureMode = secureMode, stepsPerRound = steps)
}
Expand Down
6 changes: 3 additions & 3 deletions Scalatron/src/scalatron/botwar/Simulation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*/
package scalatron.botwar

import scalatron.scalatron.impl.Plugin
import akka.util.Duration
import akka.dispatch.{ExecutionContext, Future, Await}
import akka.actor.ActorSystem
import scalatron.core.Plugin


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

/** Simulation.Runner: a generic runner for simulations that uses .step() to iteratively
Expand All @@ -52,7 +52,7 @@ object Simulation
* @return an optional simulation result (if the simulation was not prematurely aborted)
*/
def apply(
plugins: Iterable[Plugin.FromJarFile],
plugins: Iterable[Plugin.External],
randomSeed: Int
)(
actorSystem: ActorSystem,
Expand Down
2 changes: 1 addition & 1 deletion Scalatron/src/scalatron/botwar/State.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package scalatron.botwar

import State.Time
import scalatron.scalatron.impl.Plugin
import akka.dispatch.ExecutionContext
import scalatron.core.Plugin


/** Game state storing the current (game) time, the board parameters, the actual board (i.e.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.awt.Color

import RenderUtil.makeTransparent
import scalatron.botwar._
import scalatron.scalatron.impl.TournamentState

object GameStateRenderer {
def drawGameState(state: State, drawBotHorizon: Boolean)(implicit ctx: RenderContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package scalatron.botwar.renderer


import java.awt.{Font, Color}
import scalatron.core.TournamentState
import scalatron.scalatron.impl.TournamentState


object LeaderboardPanelRenderer
Expand Down
6 changes: 3 additions & 3 deletions Scalatron/src/scalatron/botwar/renderer/RenderStage.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package scalatron.botwar.renderer

import scalatron.botwar.State
import java.awt.{Color, Graphics2D}
import scalatron.core.{PermanentConfig, TournamentState}
import scalatron.scalatron.impl.TournamentState
import scalatron.botwar.{PermanentConfig, State}
import java.awt.{Font, Color, Graphics2D}


case class RenderSourceAndTarget(
Expand Down
2 changes: 1 addition & 1 deletion Scalatron/src/scalatron/botwar/renderer/Renderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ package scalatron.botwar.renderer

import scalatron.botwar.Display.RenderTarget

import scalatron.scalatron.impl.TournamentState
import scalatron.botwar._
import akka.util.Duration
import java.awt.Color
import akka.dispatch.{ExecutionContext, Await, Future}
import scalatron.core.{PermanentConfig, TournamentState}


object Renderer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package scalatron.botwar.renderer

import java.awt.{Font, Color}
import scalatron.botwar.State
import scalatron.core.{PermanentConfig, TournamentState}
import scalatron.scalatron.impl.TournamentState
import scalatron.botwar.{PermanentConfig, State}


object StatsPanelRenderer
Expand Down
3 changes: 3 additions & 0 deletions Scalatron/src/scalatron/scalatron/api/Scalatron.scala
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,9 @@ object Scalatron {
val SamplesSourceDirectoryName = "src" // e.g. in "/Scalatron/samples/{sample}/src"

val gitDirectoryName = ".git"

val JarFilename = "ScalatronBot.jar"
val BackupJarFilename = "ScalatronBot.backup.jar"
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
/** This material is intended as a community resource and is licensed under the
* Creative Commons Attribution 3.0 Unported License. Feel free to use, modify and share it.
*/

package scalatron.core
package scalatron.scalatron.impl

import akka.dispatch.ExecutionContext
import akka.actor.ActorSystem
import scalatron.botwar.Config
import scalatron.botwar.{Config, PermanentConfig}
import scalatron.botwar.BotWarSimulation.SimState

/** This material is intended as a community resource and is licensed under the
* Creative Commons Attribution 3.0 Unported License. Feel free to use, modify and share it.
*/
/** Base trait for game implementations that run within a Scalatron server (e.g. BotWar). */
trait Game
{
/** @return the name of this game; TODO: like player names, should be derived from plug-in name, e.g. "BotWar" */
def name: String
trait Game {
def name: String // e.g. "BotWar"

/** @return the package path to be used for constructing fully qualified class names for bot plug-ins,
* e.g. "scalatron.botwar.botPlugin" */
def gameSpecificPackagePath: String
/** The parameters of this game that are relevant for loading plug-ins (e.g. game name). */
def pluginLoadSpec: PluginCollection.LoadSpec

/** Dump the game-specific command line configuration options via println. */
def printArgList()
Expand Down Expand Up @@ -71,11 +67,11 @@ trait Game


def startHeadless(
plugins: Iterable[Plugin.FromJarFile],
plugins: Iterable[Plugin.External],
permanentConfig: PermanentConfig,
gameConfig: Config
)(
executionContextForUntrustedCode: ExecutionContext
): SimState
) : SimState

}
Loading

0 comments on commit 76b7d33

Please sign in to comment.