Okay so I almost have my entire game of Yahtzee finished I just have one question that I need help with.

What would be the most efficient way to figure out if the user has a 3 of a kind, yahtzee, full house etc? Basically just the bottom section of the scorecard, the rest is working perfect!

So for example for a 3 of a kind would I need to do

if (DieRollOne == 1 && DieRollTwo == 1 && DieRollThree == 1 || DieRollOne == 1 &&...etc)
{
   some sort of indication of a 3 of a kind
}

Would there be an easier way of putting in EVERY combination?
Like some way of stating that if any of DieRollOne - DieRollFive have the same value then it could be a three of a kind.

EDIT: I am also trying to export it as a JAR. I am using the BlueJ IDE and i am running windows XP. When i try to run the JAR it says Fatal eceeption occured. Program will exit. Any ideas?

Member Avatar for ztini

Well you certainly wouldn't need EVERY combination of 5 dice rolls (11C5 = 462). That's a lot of hard coding. A better solution would be to apply some logic testing. Start with largest prize, yahtzee/large straight/etc then work lower and lower.

There are several ways you could approach this, honestly. Maybe you have a solution class which takes dice rolls as a parameter, then your parent class holds an array of solutions and you invoke compareTo(). You could also have boolean isSolved(), so in case this solution is already scored.

Another way to approach this could be representing a die roll as an array, with 0 = 1, 1 = 2 dots, etc. Then you could have the data == the number of that dice that was rolled. So, a 45661 would look like this: [1, 0, 0, 1, 1, 2]. That might make logic easier to test.

I have attached (in zip form) all my files. I am quite new to java so I ended up keeping everything in one class. Im not sure how to do what you are trying to explain without breaking it up into smaller classes which i was having trouble with to begin with.

Member Avatar for ztini

Hrm, lots going on there.

You could probably get rid of a lot of the drawing stuff and just use swing JPanels and GridBagLayout to organize it. Oracle has a great tutorial on layouts here.

The best thing to do is break your program down into smaller pieces---mouseClicked() is probably way longer than it needs to be. Take a look my 2nd suggestion (using array) from my previous post; that will probably be a good way to process logic.

Also, don't be afraid to work out the logic/test cases before you implement a GUI. The console and JUnit are great tools to work out the kinks before making it "pretty". The front-end interface is generally the last part of the program implemented; at least in my experience.

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.