Skip to content

Commit 1775ffe

Browse files
committed
Issue scalatron#52: Welcome op now provides "maxslaves" parameter (maximum allowed mini-bots) and React op provides "slaves" parameter (a count of mini-bots on issue).
1 parent 9ca584d commit 1775ffe

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

BotWar/src/scalatron/botwar/AugmentedDynamics.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ case object AugmentedDynamics extends ((State,Random,Iterable[(Entity.Id,Iterabl
138138
val maxSlaveCount = state.config.boardParams.maxSlaveCount
139139
if(maxSlaveCount < Int.MaxValue) {
140140
val siblings = board.siblingsOfBot(thisBot)
141-
val siblingCount = siblings.size
142-
if(siblingCount > maxSlaveCount + 1) {
141+
val slaveCount = siblings.size - 1
142+
if (slaveCount >= maxSlaveCount) {
143143
throw new IllegalStateException("Spawn(): maximum permissible number of mini-bots has been reached: " + maxSlaveCount )
144144
}
145145
}

BotWar/src/scalatron/botwar/Board.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ object Board
163163
)
164164
= {
165165
val boardSize = boardParams.size
166+
val maxSlaves = boardParams.maxSlaveCount
166167

167168
var updatedBoard = Empty
168169
val rnd = new Random(randomSeed)
@@ -180,6 +181,7 @@ object Board
180181
"name=" + entityController.name + "," +
181182
"apocalypse=" + stepsPerRound + "," +
182183
"round=" + roundIndex +
184+
(if (maxSlaves < Int.MaxValue) ",maxslaves=" + maxSlaves else "") +
183185
")")
184186
} catch {
185187
case t: Throwable =>

BotWar/src/scalatron/botwar/Entity.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,16 @@ object Bot {
173173
Protocol.PropertyName.Time + "=" + state.time + "," +
174174
Protocol.PropertyName.View + "=" + renderedView + "," +
175175
maybeMasterParameter +
176-
Protocol.PropertyName.Energy + "=" + bot.energy +
176+
Protocol.PropertyName.Energy + "=" + bot.energy + "," +
177+
Protocol.PropertyName.Slaves + "=" + slaveCount(bot, state) +
177178
(if(stateMapString.isEmpty) "" else "," + stateMapString) +
178179
")"
179180

180181
controlFunctionInput
181182
}
182183

184+
def slaveCount(bot: Bot, state: State): Int = state.board.siblingsOfBot(bot).size - 1
185+
183186
val controlFunctionInput =
184187
if(isMaster) computeBotInputForMaster(bot, state)
185188
else computeBotInputForSlave(bot, state)

BotWar/src/scalatron/botwar/Protocol.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ object Protocol {
4747
val Collision = "collision"
4848
val Generation = "generation"
4949
val Name = "name"
50+
val Slaves = "slaves"
5051

5152
val ListOfReserved =
5253
List(
53-
Energy, Time, View, Generation, Name,
54+
Energy, Time, View, Generation, Name, Slaves,
5455
PluginOpcode.ParameterName.Direction,
5556
ServerOpcode.ParameterName.Master
5657
)

0 commit comments

Comments
 (0)