in pyhanabi/tools/run_human_game.py [0:0]
def filter_game(history, num_players, skip_player_name_check=False):
if history["num_players"] != num_players:
return False
expected_hand_size = 5 if num_players <= 3 else 4
for hand in history["hands"]:
if len(hand) != expected_hand_size:
return False
if history["abandoned"]:
return False
player_ids = list(set([m.player_name for m in history["moves"]]))
if (
not skip_player_name_check
and len(player_ids) > 1
and len(player_ids) != num_players
):
return False
sim_hands = [[copy.copy(c) for c in hand] for hand in history["hands"]]
sim_deck = [copy.copy(c) for c in history["deck"]]
hints = 8
for move_idx, move in enumerate(history["moves"]):
hand = sim_hands[move.player_id]
if move.type == "playCard" or move.type == "discardCard":
hand.pop(move.value)
if sim_deck:
hand.append(sim_deck.pop())
if move.type == "discardCard":
if hints >= 8:
return False
hints += 1
elif move.type == "hintValue":
hints -= 1
other_hand: List[Card] = sim_hands[move.target_player]
if not (move.value in [x.value for x in other_hand]):
return False
elif move.type == "hintColor":
hints -= 1
other_hand: List[Card] = sim_hands[move.target_player]
if not (move.value in [x.color for x in other_hand]):
return False
return True