MCPcopy Index your code
hub / github.com/battlecode/battlecode-2018 / next_turn

Method next_turn

battlecode-engine/src/controller/mod.rs:177–208  ·  view source on GitHub ↗

Submit your current turn and wait for your next turn. Blocks. Don't worry, you'll be paused during the blocking anyway.

(&mut self)

Source from the content-addressed store, hash-verified

175 /// Submit your current turn and wait for your next turn. Blocks. Don't worry, you'll be
176 /// paused during the blocking anyway.
177 pub fn next_turn(&mut self) -> Result<(), Error> {
178 if let None = self.stream {
179 bail!("Controller is not in env mode, has no stream, can't call next_turn()");
180 }
181 if let None = self.player_key {
182 bail!("No player key??");
183 }
184
185 // extract our previous turn, replacing it with an empty one
186 let mut turn_message = TurnMessage { changes: vec![] };
187 mem::swap(&mut self.turn, &mut turn_message);
188
189 // send off our previous turn
190 self.stream.as_mut().unwrap().write(&SentMessage {
191 client_id: self.player_key.as_ref().unwrap().clone(),
192 turn_message
193 })?;
194
195 // block and receive the state for our next turn
196 let msg = self.stream.as_mut().unwrap().read::<ReceivedMessage<StartTurnMessage>>()?;
197 let start_turn = check_message(msg, &self.player_key.as_ref().unwrap()[..])?;
198
199 // setup the world state
200 self.old_world.start_turn(&start_turn);
201 self.world = self.old_world.clone();
202
203 // set the time left
204 self.time_left_ms = Some(start_turn.time_left_ms);
205
206 // yield control to the player
207 Ok(())
208 }
209
210 /// Get the time left at the start of this player's turn, in milliseconds.
211 pub fn get_time_left_ms(&self) -> i32 {

Callers 2

run.pyFile · 0.80
run.pyFile · 0.80

Calls 4

check_messageFunction · 0.85
cloneMethod · 0.80
writeMethod · 0.45
start_turnMethod · 0.45

Tested by

no test coverage detected