The Rules for each players flip. 1. Flip the 3 coins. a. If there are no heads (
ID: 3748192 • Letter: T
Question
The Rules for each players flip.
1. Flip the 3 coins.
a. If there are no heads ( all tails ),
i. The pot gets set to zero
ii. The other player goes to step 1.
b. The number of heads is added to the pot.
2. User can choose to hold or flip again.
a. Choice FLIP. Return to Step 1.
b. Choice HOLD.
i. Increment Player score by the pot amount.
ii. Pot gets set to 0.
iii. second player gets to flip and goes to Step 1.
Program Requirements : Before each opponent begins flipping..
Output the score for the person and the computer.
Output the opponents whose turn is beginning and ask the user to hit enter to continue.
With each flip of the coins.
Output the result, and amount of the round pot.
If it’s the users flip ask if they want to Flip again ( F ) or Hold ( H ). Your program should allow r, R, h or H as valid input.
The AI will continue playing until the round pot is 8 or more.
Once a players pot is greater or equal to 20 then they have won, it will no longer ask if they want to keep playing.
Once there is a winner Score totals are output along with who the winner was. User or Computer
Player is asked if they want to play again Y or N. Valid input should be y, Y, yes, YES, or n, N, no, NO.
When a new game starts the starting flip goes to the player that did not flip last. If the User flipped last in the previous game, then the computer flips first and vice versa
This is what i have so far:
import random
human= 0
AI = 0
print('WELCOME TO GREEDY DICE')
def Human ():
global human
option= "f"
input("Your turn. Hit enter to continue.")
while (option == 'f' or option == 'F'):
pot = 0
coin= random.randint(0,2)
print("COINS : ",end= "")
if (coin == 1):
print("TTH ",end="")
elif (coin == 2):
print ("THH ",end="")
elif (coin == 3):
print("HHH ",end="")
else:
print("TTT ",end="")
pot = pot + coin
human = human + coin
print("Pot : ",pot, end="")
if (human >=20):
print("Winner!")
print("SCORE: You: ",human," AI: ", AI)
break
if (coin == 0):
print("BUST!")
human = 0
break
else: option = input("Flip Again or Hold?")
def AI ():
global AI
pot = 0
input("It's the computers turn. Hit ENTER to continue.")
while(pot<20):
coin= random.randint(0,2)
print("COINS : ",end= "")
if (coin == 1):
print("TTH ",end="")
elif (coin == 2):
print ("THH ",end="")
elif (coin == 3):
print("HHH ",end="")
else:
print("TTT ",end="")
pot = pot + coin
AI = AI + coin
print("Pot : ",pot, end="")
if (AI >=20):
print("Winner!")
print("SCORE: You: ",human," AI: ", AI)
break
if (coin == 0):
print("BUST!")
AI = 0
break
def prompt():
choice = input("Do you want to play Greedy Coin again? (YES/Y/NO/N)")
if (choice.upper() == "YES" or choice.upper() =="Y"):
return 1;
elif(choice.upper() == "NO" or choice.upper()=="N"):
return 0;
else:
prompt()
prev_turn = 0
while(1):
turn = prev_turn
while(human <= 20 and AI <= 20):
print("SCORE: You :",human," AI: ", AI)
if(turn == 0):
Human()
turn=1
else:
AI()
turn=0
if(prompt()==0):
break
if(prev_turn==0):
prev_turn=1
else:
prev_turn=0
print("Game over!")
Its still not working that well-- any suggestions on how i can get it to work.. PYTHON
Thank you so so much
Explanation / Answer
from random import randint
from time import sleep
import re
class CoinFlip(object):
def __init__(self):
self.re_head = re.compile('heads?', re.IGNORECASE)
self.re_tail = re.compile('tails?', re.IGNORECASE)
def flip(self):
""" Flip a coin and return the outcome. """
print "Flipping coin..."
sleep (2)
outcome = randint(0,1)
if outcome == 1:
print "Tails."
else:
print "Heads."
return outcome
def query(self):
""" Prompt user and return guess. """
while True:
guess = raw_input("What's your guess?[heads/tails]> ")
if self.re_head.match(guess):
return 0
elif self.re_tail.match(guess):
return 1
else:
print "Pardon?"
def play(self):
""" Loop to play a single round of Heads or Tails and returns win status. """
print "Let's flip a coin."
while True:
guess = self.query()
outcome = self.flip()
if guess == outcome:
print "You guessed right!"
return 1
else:
print "You guessed wrong."
return 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.