def update(self, champion_id, position): """ Attempt to update the current state of the draft and pick/ban lists with a given championId. Returns: True is selection was successful, False otherwise Args: champion_id (int): Id of champion to add to pick list. position (int): Position of champion to be selected. The value of position determines if championId is interpreted as a pick or ban: position = -1 -> champion ban submitted. position = 0 -> champion selection submitted by the opposing team. 0 < position <= num_positions -> champion selection submitted by our team for pos = position """ # Special case for NULL ban submitted. if (champion_id is None and position == -1): # Only append NULL bans to ban list (nothing done to state matrix) self.bans.append(champion_id) return True # Submitted picks of the form (champ_id, pos) correspond with the selection champion = champion_id in position = pos. # Bans are given pos = -1 and enemy picks pos = 0. However, this is not how they are stored in the state array. # Finally this doesn't match indexing used for state array and action vector indexing (which follow state indexing). if((position < -1) or (position > self.num_positions) or (not valid_champion_id(champion_id))): return False index = self.champ_id_to_state_index[champion_id] pos_index = self.get_position_index(position) if(position == -1): self.bans.append(champion_id) else: self.picks.append(champion_id) self.selected_pos.append(position) self.state[index,pos_index] = True return True
def can_ban(self, champion_id): """ Check to see if a champion is available to be banned. Returns: True if champion is a valid ban, False otherwise. Args: champion_id (int): Id of champion to check for valid ban. """ return ((champion_id not in self.bans) and valid_champion_id(champion_id))
def can_pick(self, champion_id): """ Check to see if a champion is available to be selected. Returns: True if champion is a valid selection, False otherwise. Args: champion_id (int): Id of champion to check for valid selection. """ return ((champion_id not in self.picks) and valid_champion_id(champion_id))
def add_ban(self, champion_id): """ Attempt to add a champion to the banned champion list and update the state. Returns: True is ban was successful, False otherwise Args: champion_id (int): Id of champion to add to bans. """ if(not valid_champion_id(champion_id)): return False self.bans.append(champion_id) index = self.get_state_index(champion_id) self.state[index,self.get_position_index(-1)] = True return True
def add_pick(self, champion_id, position): """ Attempt to add a champion to the selected champion list and update the state. Returns: True is selection was successful, False otherwise Args: champion_id (int): Id of champion to add to pick list. position (int): Position of champion to be selected. If position = 0 this is interpreted as a selection submitted by the opposing team. """ if((position < 0) or (position > self.num_positions) or (not valid_champion_id(champion_id))): return False self.picks.append(champion_id) index = self.get_state_index(champion_id) pos_index = self.get_position_index(position) self.state[index,pos_index] = True return True