diff --git a/__pycache__/bunco.cpython-312.pyc b/__pycache__/bunco.cpython-312.pyc new file mode 100644 index 0000000..12593ad Binary files /dev/null and b/__pycache__/bunco.cpython-312.pyc differ diff --git a/__pycache__/config.cpython-312.pyc b/__pycache__/config.cpython-312.pyc new file mode 100644 index 0000000..f3f4780 Binary files /dev/null and b/__pycache__/config.cpython-312.pyc differ diff --git a/__pycache__/roll.cpython-312.pyc b/__pycache__/roll.cpython-312.pyc new file mode 100644 index 0000000..e4659e7 Binary files /dev/null and b/__pycache__/roll.cpython-312.pyc differ diff --git a/__pycache__/score.cpython-312.pyc b/__pycache__/score.cpython-312.pyc new file mode 100644 index 0000000..543d05f Binary files /dev/null and b/__pycache__/score.cpython-312.pyc differ diff --git a/bunco.py b/bunco.py new file mode 100644 index 0000000..e9581d0 --- /dev/null +++ b/bunco.py @@ -0,0 +1,34 @@ +from retro.game import Game +from random import randint +import score +import config +import roll + +state = { +#state displayed in the bootom section of the game + "1. Current Team": 1, + "2. Current Round": 1, + "3. Blue Team Score": 0, + "4. Red Team Score": 0 +} + +agents = [ + roll.Roller(), + roll.Die((20, 15), "die1"), + roll.Die((30, 15), "die2"), + roll.Die((40, 15), "die3"), + +] + +game = Game(agents, state, color="black_on_white") +game.play() + + + + + + + + + + diff --git a/config.py b/config.py new file mode 100644 index 0000000..2e410b6 --- /dev/null +++ b/config.py @@ -0,0 +1 @@ +ROUNDS = 6 \ No newline at end of file diff --git a/die.py b/die.py new file mode 100644 index 0000000..1b67587 --- /dev/null +++ b/die.py @@ -0,0 +1,12 @@ +from random import randint + +class Die: + def __init__(self): + self.roll() + + def __str__(self): + return str(self.face) + + def roll(self): + self.face = randint(1, 6) + return self.face diff --git a/display.py b/display.py new file mode 100644 index 0000000..8616998 --- /dev/null +++ b/display.py @@ -0,0 +1,12 @@ +class BG: + + def __init__(self, position, name): + self.position = position + self.name = name + self.draw_bg() + + def draw_bg(self): + bg1 = "-" + bg2= "|" + bg = bg1 + bg2 + bg2 + bg1 + return bg \ No newline at end of file diff --git a/proposal.md b/proposal.md index cff31ff..0c2cc1a 100644 --- a/proposal.md +++ b/proposal.md @@ -18,7 +18,7 @@ Display roll button for each team with an indicator for whose turn it is. Recalculate and display score after each roll. Milestones - -1. Start with a display of three blank dice on the screen and a roll button as well as non-functioning Score display. +1. Start with a screen and a roll button as well as non-functioning Score display. 2. When the roll button is pressed, the dice are rolled and a value is displayed on them. 3. A change in turn changes the label over the button to the appropriate team and player - Team 1 player 1 - Team 2 player 2 - Team 1 player 3 Team 2 player 4 so they know who should press the "roll" button. 4. Later phases would populate the score and determine Buncos and Winners. diff --git a/roll.py b/roll.py new file mode 100644 index 0000000..6bc7018 --- /dev/null +++ b/roll.py @@ -0,0 +1,51 @@ +from retro.game import Game +from random import randint +import config + +class Die: +#rolls a die and returns the result for display + color = "white_on_black" + def __init__(self, position, name): + self.position = position + self.name = name + self.roll_die() + + def __str__(self): + return str(self.face) + + def roll_die(self): + self.face = randint(1, 6) + self.character = str(self.face) + + +class Roller: + display = False + + def handle_keystroke(self, keystroke, game): + if keystroke == " ": + + die1 = game.get_agent_by_name("die1") + die1.roll_die() + die2 = game.get_agent_by_name("die2") + die2.roll_die() + die3 = game.get_agent_by_name("die3") + die3.roll_die() + + + + + +""" + three_dice = [1,3,4] + roll_score = score.RollScore().get_score(three_dice, game.state['Current Round']) + print (roll_score) + + if roll_score < 21: + #is the round over? + if game.state['Current Team'] == 1: + #Add the score for the roll to the approriate team + game.state['Blue Team Score'] += roll_score + else: + game.state['Red Team Score'] += roll_score + else: + game.end()""" \ No newline at end of file diff --git a/score.py b/score.py new file mode 100644 index 0000000..52e1c5f --- /dev/null +++ b/score.py @@ -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 + + + + + + + + + + + + + + + + +