pacai.core.ticket
1import typing 2 3import edq.util.json 4 5class Ticket(edq.util.json.DictConverter): 6 """ 7 An agent's Ticket determines when they will move next. 8 A ticket is a tuple of three values: (next move time, last move time, number of moves). 9 Tickets should be treated as immutable. 10 The agent with the lowest ticket (starting with the first value and moving to the next on a tie) gets to move next. 11 All "time" values represented by a ticket are abstract and do not relate to any actual time units. 12 """ 13 14 def __init__(self, 15 next_time: int, 16 last_time: int, 17 num_moves: int) -> None: 18 self.next_time: int = next_time 19 """ The next time the ticket is allowed to move. """ 20 21 self.last_time: int = last_time 22 """ The last time that the agent moved. """ 23 24 self.num_moves: int = num_moves 25 """ The total number of times this agent has moved so far. """ 26 27 def is_before(self, other: 'Ticket') -> bool: 28 """ Return true if this ticket comes before the other ticket. """ 29 30 self_tuple = (self.next_time, self.last_time, self.num_moves) 31 other_tuple = (other.next_time, other.last_time, other.num_moves) 32 33 return self_tuple < other_tuple 34 35 def next(self, move_delay: int) -> 'Ticket': 36 """ Get the next ticket in the sequence for this agent. """ 37 38 return Ticket( 39 next_time = self.next_time + move_delay, 40 last_time = self.next_time, 41 num_moves = self.num_moves + 1, 42 ) 43 44 def to_dict(self) -> dict[str, typing.Any]: 45 return vars(self).copy() 46 47 @classmethod 48 def from_dict(cls, data: dict[str, typing.Any]) -> typing.Any: 49 data = data.copy() 50 return cls(**data)
6class Ticket(edq.util.json.DictConverter): 7 """ 8 An agent's Ticket determines when they will move next. 9 A ticket is a tuple of three values: (next move time, last move time, number of moves). 10 Tickets should be treated as immutable. 11 The agent with the lowest ticket (starting with the first value and moving to the next on a tie) gets to move next. 12 All "time" values represented by a ticket are abstract and do not relate to any actual time units. 13 """ 14 15 def __init__(self, 16 next_time: int, 17 last_time: int, 18 num_moves: int) -> None: 19 self.next_time: int = next_time 20 """ The next time the ticket is allowed to move. """ 21 22 self.last_time: int = last_time 23 """ The last time that the agent moved. """ 24 25 self.num_moves: int = num_moves 26 """ The total number of times this agent has moved so far. """ 27 28 def is_before(self, other: 'Ticket') -> bool: 29 """ Return true if this ticket comes before the other ticket. """ 30 31 self_tuple = (self.next_time, self.last_time, self.num_moves) 32 other_tuple = (other.next_time, other.last_time, other.num_moves) 33 34 return self_tuple < other_tuple 35 36 def next(self, move_delay: int) -> 'Ticket': 37 """ Get the next ticket in the sequence for this agent. """ 38 39 return Ticket( 40 next_time = self.next_time + move_delay, 41 last_time = self.next_time, 42 num_moves = self.num_moves + 1, 43 ) 44 45 def to_dict(self) -> dict[str, typing.Any]: 46 return vars(self).copy() 47 48 @classmethod 49 def from_dict(cls, data: dict[str, typing.Any]) -> typing.Any: 50 data = data.copy() 51 return cls(**data)
An agent's Ticket determines when they will move next. A ticket is a tuple of three values: (next move time, last move time, number of moves). Tickets should be treated as immutable. The agent with the lowest ticket (starting with the first value and moving to the next on a tie) gets to move next. All "time" values represented by a ticket are abstract and do not relate to any actual time units.
15 def __init__(self, 16 next_time: int, 17 last_time: int, 18 num_moves: int) -> None: 19 self.next_time: int = next_time 20 """ The next time the ticket is allowed to move. """ 21 22 self.last_time: int = last_time 23 """ The last time that the agent moved. """ 24 25 self.num_moves: int = num_moves 26 """ The total number of times this agent has moved so far. """
28 def is_before(self, other: 'Ticket') -> bool: 29 """ Return true if this ticket comes before the other ticket. """ 30 31 self_tuple = (self.next_time, self.last_time, self.num_moves) 32 other_tuple = (other.next_time, other.last_time, other.num_moves) 33 34 return self_tuple < other_tuple
Return true if this ticket comes before the other ticket.
36 def next(self, move_delay: int) -> 'Ticket': 37 """ Get the next ticket in the sequence for this agent. """ 38 39 return Ticket( 40 next_time = self.next_time + move_delay, 41 last_time = self.next_time, 42 num_moves = self.num_moves + 1, 43 )
Get the next ticket in the sequence for this agent.
Return a dict that can be used to represent this object. If the dict is passed to from_dict(), an identical object should be reconstructed.
48 @classmethod 49 def from_dict(cls, data: dict[str, typing.Any]) -> typing.Any: 50 data = data.copy() 51 return cls(**data)
Return an instance of this subclass created using the given dict. If the dict came from to_dict(), the returned object should be identical to the original.