Skip to content

Commit 0881936

Browse files
committed
Merge commit '4bfd5673764f1bcce7a16391812a0c567c9ce372'
2 parents f0abb30 + 4bfd567 commit 0881936

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

Scalatron/doc/markdown/Scalatron Protocol.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ to an empty string deletes it from the state.
244244

245245
# Opcodes of Server-to-Plugin Commands
246246

247-
These are the opcodes valid for commands sent by the server to a plug-ins control function.
247+
These are the opcodes valid for commands sent by the server to a plug-in's control function.
248248
Only one opcode will be present per control function invocation.
249249

250250

@@ -333,7 +333,7 @@ Parameters:
333333
# Opcodes of Plugin-to-Server Commands
334334

335335
These are the opcodes valid for commands returned by a plug-in to a server. Multiple such
336-
commands can be combined into a multi-command by separating them with a pipe (�|�) character.
336+
commands can be combined into a multi-command by separating them with a pipe ('|') character.
337337

338338
### Move(direction=int:int)
339339

@@ -342,7 +342,7 @@ signed integers. The permitted range values are "-1", "0" or "1".
342342

343343
Parameters:
344344

345-
* `direction` desired displacement for the move, e.g. 1:1 or 0:-1
345+
* `direction` desired displacement for the move, e.g. '1:1' or '0:-1'
346346

347347
Example:
348348

@@ -362,7 +362,7 @@ position, expressed relative to the current position.
362362

363363
Parameters:
364364

365-
* `direction` desired displacement for the spawned mini-bot, e.g. -1:1
365+
* `direction` desired displacement for the spawned mini-bot, e.g. '-1:1'
366366
* `name` arbitrary string, except the following characters are
367367
not permitted: '|', ',', '=', '('
368368
* `energy` energy budget to transfer to the spawned mini-bot (minimum: 100 EU)
@@ -473,6 +473,22 @@ Energy Cost/Permissions:
473473

474474

475475

476+
### MarkCell(position=int:int,color=string)
477+
478+
Displays a cell as marked. You can use this as a debugging tool.
479+
480+
Parameters:
481+
482+
* `position` desired displacement relative to the current bot, e.g. '-2:4' (defaults to '0:0')
483+
* `color` color to use for marking the cell (defaults to '#8888ff'), e.g. '#ff8800'
484+
485+
Energy Cost/Permissions:
486+
487+
* for master bot: permitted, no energy consumed
488+
* for mini-bot: permitted, no energy consumed
489+
490+
491+
476492
### Log(text=string)
477493

478494
Shortcut for setting the state property `debug`, which by convention contains an optional

Scalatron/src/scalatron/botwar/AugmentedDynamics.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ case object AugmentedDynamics extends ((State,Random,Iterable[(Entity.Id,Iterabl
302302
throw new IllegalStateException("Explode() command is illegal for non-player bots")
303303
}
304304

305+
case markedCell: Command.MarkCell => // "MarkCell(position=x:y,color=#ff0000)"
306+
updatedBoard = updatedBoard.addDecoration(thisBotPos + markedCell.pos, time, Decoration.MarkedCell(markedCell.color))
307+
305308
case _ =>
306309
// unknown command!
307310
throw new IllegalStateException("unknown command: " + command)

Scalatron/src/scalatron/botwar/Command.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ object Command
4545
def opcode = Protocol.PluginOpcode.Set
4646
def paramMap = map
4747
}
48-
48+
case class MarkCell(pos: XY, color: String) extends Command {
49+
def opcode = Protocol.PluginOpcode.MarkCell
50+
def paramMap = Map(Protocol.PluginOpcode.ParameterName.Position -> pos, Protocol.PluginOpcode.ParameterName.Color -> color)
51+
}
52+
4953
def fromControlFunctionResponse(controlFunctionResponse: String): Iterable[Command] = {
5054
val commandMap = MultiCommandParser.splitStringIntoParsedCommandMap(controlFunctionResponse)
5155
if(commandMap.isEmpty)
@@ -83,6 +87,11 @@ object Command
8387
case Protocol.PluginOpcode.Log => // "Log(text=<string>)"
8488
Log(params.get(Protocol.PluginOpcode.ParameterName.Text).getOrElse(""))
8589

90+
case Protocol.PluginOpcode.MarkCell => // "MarkCell(position=x:y,color=#ff0000)"
91+
MarkCell(
92+
params.get(Protocol.PluginOpcode.ParameterName.Position).map(s => XY(s)).getOrElse( XY.Zero),
93+
params.get(Protocol.PluginOpcode.ParameterName.Color).getOrElse("#8888ff")) // default to a light blue
94+
8695
case _ =>
8796
throw new IllegalStateException("unknown opcode: '" + opcode + "'")
8897
}

Scalatron/src/scalatron/botwar/Entity.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ object Decoration {
318318
case object Bonk extends Variety { def lifeTime = 40 }
319319
case object Annihilation extends Variety { def lifeTime = 40 }
320320
case class Text(text: String) extends Variety { def lifeTime = 40 }
321+
case class MarkedCell(color: String) extends Variety { def lifeTime = 40 }
321322
}
322323

323324

Scalatron/src/scalatron/botwar/Protocol.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ object Protocol {
2323
val Set = "Set"
2424
val Explode = "Explode"
2525
val Log = "Log"
26+
val MarkCell = "MarkCell"
2627

2728
object ParameterName {
2829
val Direction = "direction"
2930
val Text = "text"
3031
val BlastRadius = "size"
32+
val Position = "position"
33+
val Color = "color"
3134
}
3235
}
3336

Scalatron/src/scalatron/botwar/renderer/GameStateRenderer.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ object GameStateRenderer {
219219
val color = makeTransparent(AnnihilationColor, alpha)
220220
ctx.setColor(color)
221221
ctx.drawOval(centerX - age, centerY - age, age * 2, age * 2)
222+
223+
case markedCell: Decoration.MarkedCell =>
224+
println("rendering marked cell: " + markedCell.color)
225+
val color = makeTransparent(Color.decode(markedCell.color), alpha)
226+
ctx.setColor(color)
227+
val radius = ctx.pixelsPerCell / 2
228+
ctx.fillOval(centerX - radius, centerY - radius, radius * 2, radius * 2)
222229

223230
case _ => // OK
224231
}

0 commit comments

Comments
 (0)