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

Method end_turn

battlecode-manager/server.py:216–260  ·  view source on GitHub ↗

This function handles the release of all locks and moving the player to the next turn. It also handles sleeping the docker instances. Args: client_id: The int of the client that this thread is related to

(self)

Source from the content-addressed store, hash-verified

214
215
216 def end_turn(self):
217 '''
218 This function handles the release of all locks and moving the player to
219 the next turn. It also handles sleeping the docker instances.
220 Args:
221 client_id: The int of the client that this thread is related to
222 '''
223
224 if self.terminal_viewer:
225 if sys.platform == 'win32':
226 # Windows terminal only supports escape codes starting from Windows 10 in the 'Threshold 2' update.
227 # So fall back to other commands to ensure compatibility
228 os.system('cls')
229 else:
230 # Move the cursor to coordinate (0,0) on the screen.
231 # Compared the clearing the entire screen, this reduces flicker.
232 # See https://en.wikipedia.org/wiki/ANSI_escape_code
233 sys.stdout.write("\033[0;0H")
234 # os.system('clear')
235
236 print('[rnd: {}] [rK: {}] [bK: {}]'.format(
237 self.manager.round(),
238 self.manager.manager_karbonite(bc.Team.Red),
239 self.manager.manager_karbonite(bc.Team.Blue),
240 ))
241 self.manager.print_game_ansi()
242
243 if sys.platform != 'win32':
244 # Clear the screen from the cursor to the end of the screen.
245 # Just in case some text has been left over there from earlier frames.
246 sys.stdout.write("\033[J")
247 for player in sorted(self.players, key=_key):
248 p = player['player']
249 print('-- [{}{}] --'.format('e' if p.planet == bc.Planet.Earth else 'm', 'r' if p.team == bc.Team.Red else 'b'))
250 logs = player['logger'].logs.getvalue()[-1000:].splitlines()[-5:]
251 for line in logs:
252 print(line)
253
254 if self.extra_delay:
255 import time
256 time.sleep(self.extra_delay / 1000.)
257
258 # Increment to the next player
259 self.current_player_index = (self.current_player_index + 1) % len(self.players)
260 self.set_player_turn(self.current_player_index)
261
262 def get_viewer_messages(self):
263 '''

Callers 1

player_handlerMethod · 0.45

Calls 6

set_player_turnMethod · 0.95
formatMethod · 0.80
print_game_ansiMethod · 0.80
writeMethod · 0.45
roundMethod · 0.45
manager_karboniteMethod · 0.45

Tested by

no test coverage detected