model clue starved in hanabi instances/games

This commit is contained in:
Maximilian Keßler 2023-05-10 17:30:57 +02:00
parent 9886e68084
commit 5598887c64
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -87,6 +87,7 @@ class HanabiInstance():
num_players: int, # number of players that play this deck, in range [2,6] num_players: int, # number of players that play this deck, in range [2,6]
hand_size: Optional[int] = None, # number of cards that each player holds hand_size: Optional[int] = None, # number of cards that each player holds
num_strikes: Optional[int] = None, # number of strikes that leads to game loss num_strikes: Optional[int] = None, # number of strikes that leads to game loss
clue_starved: bool = False, # if true, discarding and playing fives only gives back half a clue
variant_id: Optional[int] = None # optional: variant id of hanab.live, useful if instance gets exported to be viewed in browser variant_id: Optional[int] = None # optional: variant id of hanab.live, useful if instance gets exported to be viewed in browser
): ):
assert(2 <= num_players <= 6) assert(2 <= num_players <= 6)
@ -96,6 +97,7 @@ class HanabiInstance():
self.num_players = num_players self.num_players = num_players
self.hand_size = hand_size or constants.HAND_SIZES[self.num_players] self.hand_size = hand_size or constants.HAND_SIZES[self.num_players]
self.num_strikes = num_strikes or constants.NUM_STRIKES self.num_strikes = num_strikes or constants.NUM_STRIKES
self.clue_starved = clue_starved
# normalize deck indices # normalize deck indices
for (idx, card) in enumerate(self.deck): for (idx, card) in enumerate(self.deck):
@ -141,6 +143,10 @@ class HanabiInstance():
def max_score(self): def max_score(self):
return 5 * self.num_suits return 5 * self.num_suits
@property
def clue_increment(self):
return 0.5 if self.clue_starved else 1
# returns True if the instance has values matching hanabi-live rules # returns True if the instance has values matching hanabi-live rules
# (i.e. standard + extra variants with 5 / 6 suits) # (i.e. standard + extra variants with 5 / 6 suits)
def is_standard(self): def is_standard(self):
@ -190,7 +196,7 @@ class GameState():
case ActionType.ColorClue | ActionType.RankClue: case ActionType.ColorClue | ActionType.RankClue:
assert(self.clues > 0) assert(self.clues > 0)
self.actions.append(action) self.actions.append(action)
self.clues -= 1 self.clues -= self.instance.clue_increment
self.__make_turn() self.__make_turn()
# TODO: could check that the clue specified is in fact legal # TODO: could check that the clue specified is in fact legal
case ActionType.Play: case ActionType.Play:
@ -205,7 +211,7 @@ class GameState():
if card.rank == self.stacks[card.suitIndex] + 1: if card.rank == self.stacks[card.suitIndex] + 1:
self.stacks[card.suitIndex] += 1 self.stacks[card.suitIndex] += 1
if card.rank == 5 and self.clues != 8: if card.rank == 5 and self.clues != 8:
self.clues += 1 self.clues += self.instance.clue_increment
else: else:
self.strikes += 1 self.strikes += 1
self.trash.append(self.instance.deck[card_idx]) self.trash.append(self.instance.deck[card_idx])
@ -218,7 +224,7 @@ class GameState():
def discard(self, card_idx): def discard(self, card_idx):
assert(self.clues < 8) assert(self.clues < 8)
self.actions.append(Action(ActionType.Discard, target=card_idx)) self.actions.append(Action(ActionType.Discard, target=card_idx))
self.clues += 1 self.clues += self.instance.clue_increment
self.pace -= 1 self.pace -= 1
self.trash.append(self.instance.deck[card_idx]) self.trash.append(self.instance.deck[card_idx])
self.__replace(card_idx) self.__replace(card_idx)