Hi, I'm in an intro to Computer Programming class, and we need to make a program that rolls 5 die, and tells you if you have any combinations (pair, 3 of a kind, 4 of a kind, 5 of a kind, and Pair+3 of a kind) My program rolls perfectly, however, I cannot figure out how to compare my labels to tell if I have any matches. Here is my code:

import Tkinter
import random

class Die:
    def __init__(self, initVal, master):
        self.value = initVal
        self.display = Tkinter.Label(master, relief="ridge", borderwidth=2, text=self.value, font=("Courier New", 30))

    def roll(self):
        self.value = random.randrange(1,7)
        self.value = self.display.config(text = str(self.value))

gameWindow = Tkinter.Tk()
RTitle=gameWindow.title("Dice Poker")
gameWindow.geometry("600x150")

frame=Tkinter.Frame(gameWindow)
row1=Die(1, frame)
row1.display.pack(side="left")
row2=Die(1, frame)
row2.display.pack(side="left")
row3=Die(1, frame)
row3.display.pack(side="left")
row4=Die(1, frame)
row4.display.pack(side="left")
row5=Die(1, frame)
row5.display.pack(side="left")
frame.pack()
message=Tkinter.Label(gameWindow, text = " ", font=("Courier New", 30))
message.pack()
Dice = [row1, row2, row3, row4, row5]

def rollAll():
    for i in range(5):
        Dice[i].roll()

    if row1.value == row2.value == row3.value or row2.value == row3.value == row4.value or row3.value == row4.value == row5.value:
        message.config(text="You have 3 of a Kind.")
    elif row1.value == row2.value == row3.value == row4.value or row2.value == row3.value == row4.value == row5.value:
        message.config(text="You have 4 of a Kind.")
    elif row1.value == row2.value == row3.value == row4.value == row5.value:
        message.config(text="You have 5 of a Kind.")
    elif row1.value == row2.value or row2.value == row3.value or row3.value == row4.value or row4.value == row5.value:
        message.config(text="You have a Pair.")
    elif row1.value == row2.value == row3.value and row4.value == row5.value or row3.value == row4.value == row5.value and row1.value == row2.value:
        message.config(text="""You have a Pair.
                             You have 3 of a Kind.""")
    else:
        message.config(text="You have nothing useful.")

button=Tkinter.Button(gameWindow, command=rollAll, text="roll", width=5, font=("Courier New", 30))
button.pack()

gameWindow.mainloop()

Work with coumts of unique dice values not individual dice.

Instead of complicated and+or statements without parens so no one knows what the computer is actually doing

elif row1.value == row2.value == row3.value and row4.value == row5.value or row3.value == row4.value == row5.value and row1.value == row2.value:

use --> for unique value in list of rolls/dice, count each unique value and use a dictionary or list to associate with "pair", "3 of a kind", etc.

## Simplified example
import random

dice_values=[random.randrange(1, 7) for die in range(5)]
print "initial values =", dice_values

set_values = set(dice_values)
print "remove duplicates =", set_values

for value in set_values:
    print "%d value occurs %d times" % (value, dice_values.count(value))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.