@@ -133,44 +133,37 @@ object Bot {
133
133
}
134
134
135
135
val view = state.flattenedBoard.computeView(botPos, Constants .SlaveHorizonHalfSize )
136
- view.occlude() // caution: in situ!
137
- val renderedView = view.cells.map(cell => Player .cellContentToChar(cell, bot) ).mkString
138
- val stateMapString =
139
- stateMap
140
- .filter(_._1 != Protocol .PropertyName .Debug )
141
- .map(entry => entry._1 + " =" + entry._2)
142
- .mkString(" ," )
143
- val controlFunctionInput =
144
- Protocol .ServerOpcode .React + " (" +
145
- Protocol .PropertyName .Generation + " =" + generation + " ," + " " +
146
- Protocol .PropertyName .Name + " =" + name + " ," + " " +
147
- Protocol .PropertyName .Time + " =" + state.time + " ," + " " +
148
- Protocol .PropertyName .Energy + " =" + bot.energy + " ," +
149
- Protocol .ServerOpcode .ParameterName .Master + " =" + deltaToMaster + " ," +
150
- Protocol .PropertyName .View + " =" + renderedView +
151
- (if (stateMapString.isEmpty) " " else " ," + stateMapString) +
152
- " )"
153
- controlFunctionInput
136
+ computeControlFunctionInput(view, Some (deltaToMaster))
154
137
}
155
138
156
139
def computeBotInputForMaster (bot : Bot , state : State ): String = {
157
140
val view = state.flattenedBoard.computeView(bot.pos, Constants .MasterHorizonHalfSize )
141
+ computeControlFunctionInput(view)
142
+ }
143
+
144
+ def computeControlFunctionInput (view : FlattenedBoard , maybeDeltaToMaster : Option [XY ] = None ): String = {
158
145
view.occlude() // caution: in situ!
159
146
val renderedView = view.cells.map(cell => Player .cellContentToChar(cell, bot) ).mkString
160
147
val stateMapString =
161
148
stateMap
162
149
.filter(_._1 != Protocol .PropertyName .Debug )
163
150
.map(entry => entry._1 + " =" + entry._2)
164
151
.mkString(" ," )
152
+ val maybeMasterParameter =
153
+ maybeDeltaToMaster
154
+ .map(Protocol .ServerOpcode .ParameterName .Master + " =" + _ + " ," )
155
+ .getOrElse(" " )
165
156
val controlFunctionInput =
166
157
Protocol .ServerOpcode .React + " (" +
167
158
Protocol .PropertyName .Generation + " =" + generation + " ," + " " +
168
159
Protocol .PropertyName .Name + " =" + name + " ," + " " +
169
160
Protocol .PropertyName .Time + " =" + state.time + " ," +
170
161
Protocol .PropertyName .View + " =" + renderedView + " ," +
162
+ maybeMasterParameter +
171
163
Protocol .PropertyName .Energy + " =" + bot.energy +
172
164
(if (stateMapString.isEmpty) " " else " ," + stateMapString) +
173
165
" )"
166
+
174
167
controlFunctionInput
175
168
}
176
169
0 commit comments