1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB
Python

import carpet
import sys
ITERATIONS = int(sys.argv[1]) if len(sys.argv) >= 2 else 10_000
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.')