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

class WarGame(object): \'Implement a Luck Seven Game. A lucky seven is defined a

ID: 3709205 • Letter: C

Question


class WarGame(object): 'Implement a Luck Seven Game. A lucky seven is defined as 3 or more 7s being rolled.' def __init__(self,sh): 'Constructor that takes a mandatory shaker as a parameter' pass
def roll(self): 'main game logic' pass
def getScore(self): 'get the score of how many games won' pass
def getGameCount(self): 'get the total rolls in the game' pass player. The game compares the values of each individual die of the computer roll to the value at the index of player rolls. If the player gets the same value or greater than the computer, they win the roll. If the player wins 50% or more of all the rolls, they win the rolled 4,6,5,3. 4 beats 3,6 beats 4, 5 beats 3 and 3 beats 2. The player won 100% of the rolls winning the round. This game was initialized with a DiceShaker that had 4 dice >>> ds=DiceShaker (4) 1 Computer rolled: [4, 2, 6, 11 5 1 Computer rolled: [6, 5, 3, 5] Player rolled: [5, 2, 4, 5] 1 Computer rolled: [2, 1, 1, 3] 5

Explanation / Answer

import random
class Die(object):
def __init__(self, dieSides=6):
self.dieSides = dieSides
self.roll()
def roll(self):
self.value = random.randrange(self.dieSides) + 1
return self.value
def get(self):
return self.value
class DiceShaker(object):
'DiceShaker class'
def __init__(self,dieCount=1, dieSides=6):
self.dieCount = dieCount
self.dieSides = dieSides
self.dices = [Die(dieSides) for i in range(dieCount)]
  
def shake(self):
for die in self.dices:
die.roll()
  
def getTotalRoll(self):
total = 0
for die in self.dices:
total += die.get()
return total
  
def getIndividualRolls(self):
return [die.get() for die in self.dices]

def __str__(self):
string = ""
rolls = self.getIndividualRolls()
for roll in rolls:
string += str(roll) + " "
return string


class WarGame(object):
'Implement a Luck Seven Game. A lucky seven is defined as 3 or more 7s being rolled.'
def __init__(self,sh):
self.shaker = sh
self.roll()
self.computer = sh.getIndividualRolls()
self.roll()
self.player = sh.getIndividualRolls()
self.gameCount = 0
self.winCount = 0

def roll(self):
self.shaker.shake()
self.computer = sh.getIndividualRolls()
self.shaker.shake()
self.player = sh.getIndividualRolls()
count = 0
n = len(self.computer)
for i in range(n):
if self.player[i] > self.computer[i]:
count += 1
percent = count*100.0/n
self.gameCount += 1
if percent >= 50:
self.winCount += 1
  
print("You win! You had %.1f values (%d of %d) greater than equal to the computer." % (percent, count, n))
  
  

def getScore(self):
self.winCount

def getGameCount(self):
return self.gameCount

# copy pastable code link: https://paste.ee/p/cpsLd