fix bug in replay creation: equal cards with different deck idx: replace correct one
This commit is contained in:
parent
4c98c4f645
commit
9704411001
1 changed files with 15 additions and 4 deletions
|
@ -35,9 +35,11 @@ class CardState():
|
||||||
|
|
||||||
|
|
||||||
class GameState():
|
class GameState():
|
||||||
def __init__(self, num_players, deck):
|
def __init__(self, num_players, deck, debug=False):
|
||||||
assert ( 2 <= num_players <= 6)
|
assert ( 2 <= num_players <= 6)
|
||||||
|
|
||||||
|
self.debug = debug
|
||||||
|
|
||||||
self.num_players = num_players
|
self.num_players = num_players
|
||||||
self.deck = deck
|
self.deck = deck
|
||||||
for (idx, card) in enumerate(self.deck):
|
for (idx, card) in enumerate(self.deck):
|
||||||
|
@ -47,6 +49,7 @@ class GameState():
|
||||||
self.hand_size = STANDARD_HAND_SIZE[self.num_players]
|
self.hand_size = STANDARD_HAND_SIZE[self.num_players]
|
||||||
self.players = ["Alice", "Bob", "Cathy", "Donald", "Emily"][:self.num_players]
|
self.players = ["Alice", "Bob", "Cathy", "Donald", "Emily"][:self.num_players]
|
||||||
|
|
||||||
|
|
||||||
# dynamic game state
|
# dynamic game state
|
||||||
self.progress = self.num_players * self.hand_size # index of next card to be drawn
|
self.progress = self.num_players * self.hand_size # index of next card to be drawn
|
||||||
self.hands = [deck[self.hand_size * p : self.hand_size * (p+1)] for p in range(0, num_players)]
|
self.hands = [deck[self.hand_size * p : self.hand_size * (p+1)] for p in range(0, num_players)]
|
||||||
|
@ -70,9 +73,13 @@ class GameState():
|
||||||
self.turn = (self.turn + 1) % self.num_players
|
self.turn = (self.turn + 1) % self.num_players
|
||||||
if self.progress == self.deck_size:
|
if self.progress == self.deck_size:
|
||||||
self.remaining_extra_turns -= 1
|
self.remaining_extra_turns -= 1
|
||||||
|
if self.debug:
|
||||||
|
print("Elapsed {} turns, last action was {}. Current board state:\n{} with stacks:{}".format(
|
||||||
|
len(self.actions), self.actions[-1], self.hands, self.stacks
|
||||||
|
))
|
||||||
|
|
||||||
def __replace(self, card_idx):
|
def __replace(self, card_idx):
|
||||||
idx_in_hand = self.cur_hand.index(self.deck[card_idx])
|
idx_in_hand = next(i for (i, card) in enumerate(self.cur_hand) if card.deck_index == card_idx)
|
||||||
for i in range(idx_in_hand, self.hand_size - 1):
|
for i in range(idx_in_hand, self.hand_size - 1):
|
||||||
self.cur_hand[i] = self.cur_hand[i + 1]
|
self.cur_hand[i] = self.cur_hand[i + 1]
|
||||||
if self.progress < self.deck_size:
|
if self.progress < self.deck_size:
|
||||||
|
@ -206,6 +213,9 @@ class GreedyStrategy():
|
||||||
plays = [cstate for cstate in cur_hand if cstate.card_type == CardType.Playable]
|
plays = [cstate for cstate in cur_hand if cstate.card_type == CardType.Playable]
|
||||||
trash = next((cstate for cstate in cur_hand if cstate.card_type == CardType.Trash), None)
|
trash = next((cstate for cstate in cur_hand if cstate.card_type == CardType.Trash), None)
|
||||||
|
|
||||||
|
|
||||||
|
# actual decision on what to do
|
||||||
|
|
||||||
if len(plays) > 0:
|
if len(plays) > 0:
|
||||||
play = max(plays, key=lambda s: s.weight)
|
play = max(plays, key=lambda s: s.weight)
|
||||||
self.game_state.play(play.card.deck_index)
|
self.game_state.play(play.card.deck_index)
|
||||||
|
@ -241,6 +251,7 @@ def test():
|
||||||
|
|
||||||
wins = open("won_seeds.txt", "a")
|
wins = open("won_seeds.txt", "a")
|
||||||
losses = open("lost_seeds.txt", "a")
|
losses = open("lost_seeds.txt", "a")
|
||||||
|
crits = open("crits_lost.txt", "a")
|
||||||
|
|
||||||
lost = 0
|
lost = 0
|
||||||
won = 0
|
won = 0
|
||||||
|
@ -263,12 +274,12 @@ def run_deck(seed, num_players, deck_str):
|
||||||
# wins.write("Seed {:10} {}:\n{}\n".format(seed, str(deck), link(gs.to_json())))
|
# wins.write("Seed {:10} {}:\n{}\n".format(seed, str(deck), link(gs.to_json())))
|
||||||
won += 1
|
won += 1
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# losses.write("Seed {} {}lost crit:\n{}\n".format(seed, str(deck), link(gs.to_json())))
|
crits.write("Seed {} {}lost crit:\n{}\n".format(seed, str(deck), link(gs.to_json())))
|
||||||
crits_lost += 1
|
crits_lost += 1
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute("SELECT seed, num_players, deck FROM seeds WHERE variant_id = 0 AND num_players = 2 limit 1000")
|
cur.execute("SELECT seed, num_players, deck FROM seeds WHERE variant_id = 0 AND num_players = 3 limit 1000")
|
||||||
print()
|
print()
|
||||||
for r in cur:
|
for r in cur:
|
||||||
run_deck(*r)
|
run_deck(*r)
|
||||||
|
|
Loading…
Reference in a new issue