generated from mwc/project_game
wip
This commit is contained in:
97
score.py
Normal file
97
score.py
Normal file
@@ -0,0 +1,97 @@
|
||||
from retro.game import Game
|
||||
import config
|
||||
import bunco
|
||||
from tqdm import tqdm
|
||||
|
||||
class Score:
|
||||
def score_display(self, team):
|
||||
score = RollScore.get_score()
|
||||
|
||||
|
||||
class RollScore:
|
||||
# takes the values from three rolled die and returns the score for the roll
|
||||
def get_score(self, dice, round_number):
|
||||
score = 0
|
||||
|
||||
for die in dice:
|
||||
if die.face == round_number:
|
||||
score += round_number
|
||||
if score == score/round_number:
|
||||
#bunco
|
||||
score += 21
|
||||
if ThreeDice.is_three_of_a_kind() == True:
|
||||
score += 5
|
||||
|
||||
return score
|
||||
|
||||
|
||||
class ThreeDice:
|
||||
def __init__(self):
|
||||
self.dice = [Die() for number in range(3)]
|
||||
|
||||
def roll(self):
|
||||
for die in self.dice:
|
||||
die.roll()
|
||||
return self.faces()
|
||||
|
||||
def faces(self):
|
||||
return [die.face for die in self.dice]
|
||||
|
||||
def value_count(self):
|
||||
#will count how many of each kind of dice and return a list of how many of each value
|
||||
count_ones = 0
|
||||
count_twos = 0
|
||||
count_threes = 0
|
||||
count_fours = 0
|
||||
count_fives = 0
|
||||
count_sixes = 0
|
||||
|
||||
for face in self.faces():
|
||||
if face == 1:
|
||||
count_ones += 1
|
||||
if face == 2:
|
||||
count_twos += 1
|
||||
if face == 3:
|
||||
count_threes += 1
|
||||
if face == 4:
|
||||
count_fours += 1
|
||||
if face == 5:
|
||||
count_fives += 1
|
||||
if face == 6:
|
||||
count_sixes += 1
|
||||
counts = {
|
||||
"ones": count_ones,
|
||||
"twos": count_twos,
|
||||
"threes": count_threes,
|
||||
"fours": count_fours,
|
||||
"fives": count_fives,
|
||||
"sixes": count_sixes}
|
||||
# print (counts)
|
||||
return counts
|
||||
|
||||
def is_three_of_a_kind(self):
|
||||
#determine if the dice roll is three of a kind
|
||||
value_count = None
|
||||
value_count = self.value_count()
|
||||
for value in value_count.values():
|
||||
if value > 3:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user