Ejemplo n.º 1
0
def test_message_float_list():
    val = [1.0, 3.0, 9.0]
    msg_out = OutgoingMessage()
    msg_out.write_float32_list(val)

    msg_in = IncomingMessage(msg_out.buffer)
    read_val = msg_in.read_float32_list()
    # These won't be exactly equal in general, since python floats are 64-bit.
    assert val == read_val

    # Test reading with defaults
    assert [] == msg_in.read_float32_list()
    assert val == msg_in.read_float32_list(default_value=val)
Ejemplo n.º 2
0
 def on_message_received(self, msg: IncomingMessage) -> None:
     agent_id = msg.read_int32()
     step = msg.read_int32()
     new_rewards = msg.read_float32_list()
     if agent_id in self._rewards:
         last_step, last_rewards = self._rewards[agent_id]
         assert last_step == -1 or last_step == step
         for i in range(len(new_rewards)):
             new_rewards[i] += last_rewards
     self._rewards[agent_id] = (step, new_rewards)