Skip to content

Commit 1951447

Browse files
committed
Merge commit '003522e3183654146825436539c56f04d90c7332'
2 parents 859802c + 003522e commit 1951447

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed

Scalatron/doc/markdown/Scalatron Protocol.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,23 @@ Energy Cost/Permissions:
489489

490490

491491

492+
### DrawLine(from=int:int,to=int:int,color=string)
493+
494+
Draws a line. You can use this as a debugging tool.
495+
496+
Parameters:
497+
498+
* `from` starting cell of the line to draw, e.g. '-2:4' (defaults to '0:0')
499+
* `to` destination cell of the line to draw, e.g. '3:-2' (defaults to '0:0')
500+
* `color` color to use for marking the cell (defaults to '#ff8888'), e.g. '#ffffff' for a white line
501+
502+
Energy Cost/Permissions:
503+
504+
* for master bot: permitted, no energy consumed
505+
* for mini-bot: permitted, no energy consumed
506+
507+
508+
492509
### Log(text=string)
493510

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

Scalatron/src/scalatron/botwar/AugmentedDynamics.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ case object AugmentedDynamics extends ((State,Random,Iterable[(Entity.Id,Iterabl
305305
case markedCell: Command.MarkCell => // "MarkCell(position=x:y,color=#ff0000)"
306306
updatedBoard = updatedBoard.addDecoration(thisBotPos + markedCell.pos, time, Decoration.MarkedCell(markedCell.color))
307307

308+
case line: Command.DrawLine => // "DrawLine(from=x1:y1,to=x2:y2,color=#cccccc)"
309+
updatedBoard = updatedBoard.addDecoration(
310+
thisBotPos + line.fromPos, time, Decoration.Line(thisBotPos + line.toPos, line.color))
311+
308312
case _ =>
309313
// unknown command!
310314
throw new IllegalStateException("unknown command: " + command)

Scalatron/src/scalatron/botwar/Command.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ object Command
4949
def opcode = Protocol.PluginOpcode.MarkCell
5050
def paramMap = Map(Protocol.PluginOpcode.ParameterName.Position -> pos, Protocol.PluginOpcode.ParameterName.Color -> color)
5151
}
52+
case class DrawLine(fromPos: XY, toPos: XY, color: String) extends Command {
53+
def opcode = Protocol.PluginOpcode.DrawLine
54+
def paramMap = Map(
55+
Protocol.PluginOpcode.ParameterName.From -> fromPos,
56+
Protocol.PluginOpcode.ParameterName.To -> toPos,
57+
Protocol.PluginOpcode.ParameterName.Color -> color)
58+
}
5259

5360
def fromControlFunctionResponse(controlFunctionResponse: String): Iterable[Command] = {
5461
val commandMap = MultiCommandParser.splitStringIntoParsedCommandMap(controlFunctionResponse)
@@ -91,6 +98,12 @@ object Command
9198
MarkCell(
9299
params.get(Protocol.PluginOpcode.ParameterName.Position).map(s => XY(s)).getOrElse( XY.Zero),
93100
params.get(Protocol.PluginOpcode.ParameterName.Color).getOrElse("#8888ff")) // default to a light blue
101+
102+
case Protocol.PluginOpcode.DrawLine => // "DrawLine(from=x:y,to=x:y,color=#ffffff)"
103+
DrawLine(
104+
params.get(Protocol.PluginOpcode.ParameterName.From).map(s => XY(s)).getOrElse( XY.Zero),
105+
params.get(Protocol.PluginOpcode.ParameterName.To).map(s => XY(s)).getOrElse( XY.Zero),
106+
params.get(Protocol.PluginOpcode.ParameterName.Color).getOrElse("#cccccc")) // default to a light grey
94107

95108
case _ =>
96109
throw new IllegalStateException("unknown opcode: '" + opcode + "'")

Scalatron/src/scalatron/botwar/Entity.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ object Decoration {
319319
case object Annihilation extends Variety { def lifeTime = 40 }
320320
case class Text(text: String) extends Variety { def lifeTime = 40 }
321321
case class MarkedCell(color: String) extends Variety { def lifeTime = 40 }
322+
case class Line(toPos: XY, color: String) extends Variety { def lifeTime = 40 }
322323
}
323324

324325

Scalatron/src/scalatron/botwar/Protocol.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ object Protocol {
2424
val Explode = "Explode"
2525
val Log = "Log"
2626
val MarkCell = "MarkCell"
27+
val DrawLine = "DrawLine"
2728

2829
object ParameterName {
2930
val Direction = "direction"
3031
val Text = "text"
3132
val BlastRadius = "size"
3233
val Position = "position"
34+
val From = "from"
35+
val To = "to"
3336
val Color = "color"
3437
}
3538
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ object GameStateRenderer {
226226
val radius = ctx.pixelsPerCell / 2
227227
ctx.fillOval(centerX - radius, centerY - radius, radius * 2, radius * 2)
228228

229+
case line: Decoration.Line =>
230+
val color = makeTransparent(Color.decode(line.color), alpha)
231+
ctx.setColor(color)
232+
val (toX, toY) = ctx.center(line.toPos)
233+
ctx.drawLine(centerX, centerY, toX, toY)
234+
229235
case _ => // OK
230236
}
231237
})

0 commit comments

Comments
 (0)