Advertisement
cipheron

Chick Fil A Game

Sep 19th, 2024 (edited)
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. import random
  2.  
  3. # Function to initialize game state
  4. def initialize_game():
  5. return {
  6. 'tokens': {
  7. 'red': {'big_eyes': 3, 'small_eyes': 3},
  8. 'green': {'big_eyes': 3, 'small_eyes': 3},
  9. 'blue': {'big_eyes': 3, 'small_eyes': 3},
  10. 'yellow': {'big_eyes': 3, 'small_eyes': 3}
  11. },
  12. 'grey_pieces': 0
  13. }
  14.  
  15. def roll_dice():
  16. """Rolls a 6-sided dice and returns the result."""
  17. return random.randint(1, 6)
  18.  
  19. def remove_eye_type(tokens, eye_type):
  20. """Removes a token of the specified eye type from the color with the most total tokens."""
  21. max_total_tokens = -1
  22. max_color = None
  23.  
  24. # Find the color with the most total tokens
  25. for color, values in tokens.items():
  26. total_tokens = values['big_eyes'] + values['small_eyes']
  27. if total_tokens > max_total_tokens and values[eye_type] > 0: # Ensure it has the specified eye type
  28. max_total_tokens = total_tokens
  29. max_color = color
  30.  
  31. if max_color:
  32. tokens[max_color][eye_type] -= 1
  33. else:
  34. return False # No valid token to remove
  35.  
  36. return True # Successfully removed a token
  37.  
  38. def remove_color(tokens, color):
  39. """Removes a token from the specified color based on the eye type with the highest total value."""
  40. # Calculate the total big eyes and small eyes across all colors
  41. total_big_eyes = sum(values['big_eyes'] for values in tokens.values())
  42. total_small_eyes = sum(values['small_eyes'] for values in tokens.values())
  43.  
  44. # Choose the eye type with the highest total across all colors
  45. if total_big_eyes >= total_small_eyes and tokens[color]['big_eyes'] > 0:
  46. tokens[color]['big_eyes'] -= 1
  47. elif tokens[color]['small_eyes'] > 0:
  48. tokens[color]['small_eyes'] -= 1
  49. else:
  50. return False # No valid token to remove
  51.  
  52. return True # Successfully removed a token
  53.  
  54. def all_tokens_removed(tokens):
  55. """Checks if all tokens have been removed from the board."""
  56. return all(values['big_eyes'] == 0 and values['small_eyes'] == 0 for values in tokens.values())
  57.  
  58. def remove_token(game_state, roll):
  59. """Removes a token based on the dice roll (color or eye type)."""
  60. tokens = game_state['tokens']
  61.  
  62. # Roll outcomes: 1-4 = color, 5 = big eyes, 6 = small eyes
  63. if 1 <= roll <= 4:
  64. color_map = {1: 'red', 2: 'green', 3: 'blue', 4: 'yellow'}
  65. color = color_map[roll]
  66. if not remove_color(tokens, color):
  67. game_state['grey_pieces'] += 1 # No valid move, add a grey piece
  68.  
  69. elif roll == 5:
  70. if not remove_eye_type(tokens, 'big_eyes'):
  71. game_state['grey_pieces'] += 1 # No valid move, add a grey piece
  72.  
  73. elif roll == 6:
  74. if not remove_eye_type(tokens, 'small_eyes'):
  75. game_state['grey_pieces'] += 1 # No valid move, add a grey piece
  76.  
  77. def play_game():
  78. """Plays a single game and returns whether the player won or lost."""
  79. game_state = initialize_game()
  80.  
  81. # Game continues until either a win (all tokens removed) or loss (3 grey pieces)
  82. while True:
  83. roll = roll_dice()
  84. remove_token(game_state, roll)
  85. print(f"Rolled: {["","Red ","Green ","Blue ", "Yellow", "SmallE", "BigE "][roll]}, Tokens: {game_state}")
  86.  
  87. if game_state['grey_pieces'] >= 3:
  88. return False # Loss condition
  89. elif all_tokens_removed(game_state['tokens']):
  90. return True # Win condition
  91.  
  92. def simulate_games(num_games):
  93. """Simulates multiple games and counts wins and losses."""
  94. wins = 0
  95. losses = 0
  96.  
  97. for _ in range(num_games):
  98. if play_game():
  99. wins += 1
  100. else:
  101. losses += 1
  102.  
  103. print()
  104.  
  105. return wins, losses
  106.  
  107. # Simulate 1000 games
  108. num_games = 1000
  109. wins, losses = simulate_games(num_games)
  110.  
  111. # Print the results
  112. print(f"Out of {num_games} games:")
  113. print(f"Wins: {wins}")
  114. print(f"Losses: {losses}")
  115. input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement