wood burning stoves*
The moose likes Java in General and the fly likes Style Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Style Question" Watch "Style Question" New topic
Author

Style Question

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

I have a style question relating to a project I am currently working on. In this project I need to verify the contents of a configuration file with holds sets of rules for games played on three-reel slot machines.

In this list I am given a set of symbols that are the faces on the reel strip( i.e. 7,BAR,CHERRY..etc), and also given the amount of money the user wins in a list after the symbols(10 20 30 40 50 (space delimited)). The user wins a certain amount of money by having 1-5 coins in the machine on a bet(the 1-5 coins are the index into the winnings array)

From this list I need to make every possible combination of symbols for each winning (so every single combination with appear 5 times) and display the players winnings for that combination of 3-symbols. The way I have currently performing this is something like this:




Sorry for the long explanation, now my question.

How many levels nested is too many?

Thanks,
Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2840
    
  11

You can reduce the levels of for loops by breaking things into different functions, like getSpin() for example.

The main thing is I don't think the program is doing what you think it's doing. It looks like you define a number of times the gambler is going to pull the handle, range(bets), but for every single bet you go through every possible spin combination and compare it to the prize list.

I also don't like the "every combination will appear 5 times". I think I know what you mean, though I don't think that's accurate. Because of permutations, combinations of the same three symbols will appear from one to six times (one if you have three of the same symbol, six if they are all different, and three for two of one and one of another.) Unless the position of symbols makes a difference to your prizes, I would eliminate the duplicates from the prize list, then sort the spin to find a match. If you play your cards right , you can even use a binary search, rather than linear search to find that match.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

This is solely for testing the game client. So I want to see every possible combination for every pay out.

So if the user can enter up to 5 coins, I want to see

BAR BAR BAR 1
BAR BAR BAR 2 (Where 1 - 5 reflect the number of coins the user has put in, and reflect their winnings)
BAR BAR BAR 3 (So if the user enters 3 coins for a bet, and the winning_array = [20,40,80,160,500], they would win winning_array[3] or 80 (assume the array starts at 1)
etc...

Thank you for the getSpin() suggestion.

Hunter
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11160
    
  16

I'd probably move the generation of the spins into it's own method, and store them in a collection. You can have another method that iterates through the collection, and outputs the winnings for each.

You also don't need each possible spin five times, you just need to print what the five possible score is for each spin.

pseudocode:



There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

fred rosenberger wrote:I'd probably move the generation of the spins into it's own method, and store them in a collection. You can have another method that iterates through the collection, and outputs the winnings for each.

You also don't need each possible spin five times, you just need to print what the five possible score is for each spin.

pseudocode:




Thanks for the suggestions Fred
The reason I print them all out 5 times is because I'm going to be matching the data I create and the data that was generated by an automated test. The company I intern for thinks there is an error inside their automated system, and the way the automated test runs is with all possible combinations for every bet.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11160
    
  16

ok...but you still don't need to generate a single combination five time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Style Question
 
Similar Threads
Vending Machine Project
Vending Machine.
Vending Machine Project
Urgent help needed to produce a java slot machine applet , for college
unexpected output