Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Bogus Dice game Bogus is nearly the opposite of the dice game Yahtzee. In Yahtze

ID: 3769900 • Letter: B

Question

Bogus Dice game Bogus is nearly the opposite of the dice game Yahtzee. In Yahtzee, you have five dice that are rolled. You then have the opportunity to re-roll some of the dice in order to improve the results. The best roll possible roll in that game is five-of-a-kind, where all dice are showing the same value. In that game, that roll is called a Yahtzee. In bogus dice, we're trying to get as few matching dice as possible. As in Yahtzee, a turn will consist of three rolls. Unlike Yahtzee, we are forced to re-roll a set number of dice based on how good or bad our current set of dice are. Hand names: Nothing- no dice have matching values A pair - two of the dice have matching values Two pair- two sets of two dice have matching values, the remaining die is different from these Three of a kind-three dice have matching values, the other two are different Full house -three dice have matching values, the other two are different value, but match each other

Explanation / Answer

import random

def calHand(Dices, rollNum):

Dices2 = set(Dices)

#print Dices2

if (len(Dices2) == 5):

score = 10

print "Hand: Nothing"

if(rollNum < 3):

print "You must re-roll all five dices"

elif (len(Dices2) == 4):

score = 5

print "Hand: A Pair"

if(rollNum < 2):

print "You have to re-roll four amongst the five dices"

print "Enter the dice numbers you want to re-roll: "

elif (len(Dices2) == 3):

j = 0

while(1):

numMatch = 0

for i in range(len(Dices)):

if(Dices[j] == Dices[i]):

numMatch += 1

if(numMatch == 3):

score = 2

print "Hand: Three of a kind"

if(rollNum < 2):

print "You have to re-roll three dices"

print "Enter the dice numbers you want to re-roll: "

break

elif(numMatch == 2):

score = 4

print "Hand: Two Pairs"

if(rollNum < 2):

print "You have to re-roll three dices"

print "Enter the dice numbers you want to re-roll: "

break

else:

j += 1

elif (len(Dices2) == 2):

numMatch = 0

for i in range(len(Dices)):

if(Dices[0] == Dices[i]):

numMatch += 1

if(numMatch == 4 or numMatch == 1):

score = -2

print "Hand: Four of a kind"

if(rollNum < 2):

print "You have to re-roll two dices of your choice"

print "Enter the dice numbers you want to re-roll: "

else:

score = 0

print "Hand: Full House"

if(rollNum < 2):

print "You have to re-roll two dices of your choice"

print "Enter the dice numbers you want to re-roll: "

else:

score = -5

print "Hand: Five of a kind: Bogus!!!"

if(rollNum < 2):

print "You can re-roll only one die of your choice"

print "Enter the die number you want to re-roll"

if(rollNum >= 3):

return score

def main():

p1Score = 0

p2Score = 0

while(1):

p1Dices = [0, 0, 0, 0, 0]

p2Dices = [0, 0, 0, 0, 0]

p1Sel = [0, 1, 2, 3, 4]

p2Sel = [0, 1, 2, 3, 4]

rollNum = 0

while(rollNum < 3):

print "Rolling dices for player 1: "

for i in range(5):

if(i in p1Sel):

p1Dices[i] = random.randint(1,6)

print "Dices: ", p1Dices

calHand(p1Dices, rollNum)

Dices2 = set(p1Dices)

if(len(Dices2) != 5 and rollNum < 2):

s = raw_input()

p1Sel = map(int, s.split())

p1Sel[:] = [x - 1 for x in p1Sel]

#print p1Sel

rollNum += 1

print "After three rolls, Player 1 hand: "

p1Score += calHand(p1Dices, rollNum)

print "Player 1 Total score", p1Score

if(p1Score >= 40):

print "Player 1 wins"

break

rollNum = 0

while(rollNum < 3):

print "Rolling dices for player 2: "

for i in range(5):

if(i in p2Sel):

p2Dices[i] = random.randint(1,6)

print "Dices: ", p2Dices

calHand(p2Dices, rollNum)

Dices2 = set(p2Dices)

if(len(Dices2) != 5 and rollNum < 2):

s = raw_input()

p2Sel = map(int, s.split())

p2Sel[:] = [x - 1 for x in p2Sel]

#print p1Sel

rollNum += 1

print "After three rolls, Player 2 hand: "

p2Score += calHand(p2Dices, rollNum)

print "Player 2 Total score", p2Score

if(p2Score >= 40):

print "Player 2 wins"

break

main()