This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
"If the facts don't fit the theory, get new facts" --Albert Einstein
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.
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 or 80 (assume the array starts at 1)
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.
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.