import carpet ITERATIONS = 10000 def try_drop(game): success = True while success: success = False for suit in carpet.Suit: value = game.foundations[suit] if (suit, value + 1) in game.carpet: success = True game.autodrop() if len(game.offers) > 0 and (suit, value + 1) == game.offers[-1]: success = True game.drop_card_from_offer() stats = {'wins': 0, 'losses': 0} for i in range(ITERATIONS): game = carpet.Game() while game.game_result() is None: # Alg: if we can drop, we drop. If not and we can get card, we get. Else we flip. try_drop(game) if game.free_cells > 0 and len(game.offers) > 0: game.get_card_from_deck() elif len(game.deck) > 0: game.flip_deck() elif game.game_result is None: # otherwise this is last round print('Did we lose?') game.print() if game.game_result(): #print(f'Game {i} won in {game.moves} moves.') stats['wins'] += 1 else: #print(f'Game {i} lost in {game.moves} moves.') stats['losses'] += 1 print(f'Out of {ITERATIONS} games, {stats["wins"]} won, {stats["losses"]} lost.')