Command Execution Order


#1

I’m trying to debug some unexpected behaviour in my bot, and I’m just trying to work out if its an error in my code or expected behaviour with how the turns are processed by the Halite engine.

Are player turns processed sequentially?
Eg.

  • Player 1 - Submits commands for turn 1,
  • Engine Processes commands for player 1 and sends new game state to player 2.
  • Player 2 - Gets updated state (including Player 0’s move).
    - Submits commands for turn 1.
  • Engine Processes commands for Player 2. Sends new game state to Player 1.
  • Player 1 - Gets updated state.
    - Submits commands for turn 2.
  • etc…

Or are the players all executed simultaneously?
Eg.

  • Engine Gets commands from all players for turn 1.
  • Engine Executes:
    - First Command (Player 1)
    - First Command (Player 2)
    - Second Command (player 1)
    - Second Command (player 2)
    - …
    - Final commands executed.
  • Engine sends new game state to all players.

Logging the server output seems to indicate the latter (simultaneous execution) as they both receive the same game state. If so, are collisions calculated at the end of the turn, or after each command?
Eg.

Turn 5:
Player 1 ship at Cell (1,1)
Player 2 ship at Cell (1, 2)

Player 1 ship moves to Cell (1, 2)
Player 2 ship moves to Cell (1, 1)

Are both ships destroyed or do they both just swap places?

I’m assuming it must be at the end of the turn, or it would give an unfair advantage to the player who moved first, but just wanted to double-check my assumptions.


#2

It is possible for two ships to swap places so I think that means all collisions are processed at the end of the turn.


#3

Collisions are resolved at a separate end of turn stage based on how many ships are in a cell after movement, hence ships moving towards each other swap position (counter-intuitive as it may seem).


#4

Running locally, I seem to be seeing something different from that. Below is a log from my bot:

INFO:root:=============== TURN 004 ================
INFO:root:Ship(id=1, Position(23, 17), cargo=182 halite)
INFO:root:Ship(id=2, Position(23, 15), cargo=0 halite)
INFO:root:Ship(id=4, Position(23, 16), cargo=0 halite)
INFO:root:[‘m 1 o’, ‘m 2 w’, ‘m 4 n’, ‘g’]
INFO:root:=============== TURN 005 ================
INFO:root:Ship(id=1, Position(23, 17), cargo=319 halite)
INFO:root:Ship(id=5, Position(23, 16), cargo=0 halite)
INFO:root:[‘m 1 w’, ‘m 5 n’, ‘g’]

It seems that on turn 4, ships 2 and 4 collide. According to the command queue:
2 moves West from (23, 15) to (22, 15)
4 moves North from (23, 16) to (23, 15)

I’d have expected that to be fine, but it looks like that’s wrong. Am I missing something?

EDIT: yes, I am! 2 can’t move because it has no halite, so it fails and the collision happens.