How do i correct this 'if loop' ?
|
Patryk Under
Registered User
Join date: 3 Mar 2005
Posts: 45
|
03-28-2005 12:02
I've been trying to make this slot machine work for over 30hours straight now, all is ok except when i add wild symbols to it. (8's = tripplebar symbol, 10's = wild symbol) if (((wheel1_score ==  && (wheel2_score ==  && (wheel3_score ==  ) || ((wheel1_score == 10) && (wheel2_score ==  && (wheel3_score == 10)) || ((wheel1_score ==  && (wheel2_score == 10) && (wheel3_score == 10)) || ((wheel1_score == 10) && (wheel2_score == 10) && (wheel3_score ==  ) || ((wheel1_score ==  && (wheel2_score ==  && (wheel3_score == 10)) || ((wheel1_score ==  && (wheel2_score == 10) && (wheel3_score ==  ) || ((wheel1_score == 10) && (wheel2_score ==  && (wheel3_score ==  )) three_bar = TRUE; Can anyone please help me correcting this ?  Thanx in advance
|
Olmy Seraph
Valued Member
Join date: 1 Nov 2004
Posts: 502
|
03-28-2005 12:13
That's some brute force logic there. I'd use the power of MATH instead. Encode each score as a prime number, then multiply all three wheel scores together, and see if they match the required product.
scores = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29];
val1 = llList2Intger(scores, wheel1); val2 = llList2Intger(scores, wheel2); val3 = llList2Intger(scores, wheel3);
prod = val1 * val2 * val3;
THREE_BAR = ((prod == 19 * 19 * 19) || (prod == 19 * 19 * 29)) ;
_____________________
Some people are like Slinkies... not really good for anything, but they sure bring a smile to your face when you push them down the stairs.
|
Patryk Under
Registered User
Join date: 3 Mar 2005
Posts: 45
|
03-30-2005 04:24
Thanks alot for this suggestion, it's far more effective than mine. However i made my code work in the way i made it in the first place, reason i chose to coninue my logic madness is because it's much easier to modify and sort out later, multiplying results can easlity lead to wrong results once the code gets advanced enough. Here's some more of Patryk's brute force logic  else if (((wheel1_score == 3) && (wheel2_score == 5) && (wheel3_score == 9)) || ((wheel1_score == 3) && (wheel2_score == 9) && (wheel3_score == 5)) || ((wheel1_score == 5) && (wheel2_score == 3) && (wheel3_score == 9)) || ((wheel1_score == 5) && (wheel2_score == 9) && (wheel3_score == 3)) || ((wheel1_score == 9) && (wheel2_score == 3) && (wheel3_score == 5)) || ((wheel1_score == 9) && (wheel2_score == 5) && (wheel3_score == 3)) || ((wheel1_score == 3) && (wheel2_score == 3) && (wheel3_score == 5)) || ((wheel1_score == 3) && (wheel2_score == 5) && (wheel3_score == 3)) || ((wheel1_score == 5) && (wheel2_score == 3) && (wheel3_score == 3)) || ((wheel1_score == 3) && (wheel2_score == 3) && (wheel3_score == 9)) || ((wheel1_score == 3) && (wheel2_score == 9) && (wheel3_score == 3)) || ((wheel1_score == 9) && (wheel2_score == 3) && (wheel3_score == 3)) || ((wheel1_score == 5) && (wheel2_score == 5) && (wheel3_score == 3)) || ((wheel1_score == 5) && (wheel2_score == 3) && (wheel3_score == 5)) || ((wheel1_score == 3) && (wheel2_score == 5) && (wheel3_score == 5)) || ((wheel1_score == 5) && (wheel2_score == 5) && (wheel3_score == 9)) || ((wheel1_score == 5) && (wheel2_score == 9) && (wheel3_score == 5)) || ((wheel1_score == 9) && (wheel2_score == 5) && (wheel3_score == 5)) || ((wheel1_score == 9) && (wheel2_score == 9) && (wheel3_score == 3)) || ((wheel1_score == 9) && (wheel2_score == 3) && (wheel3_score == 9)) || ((wheel1_score == 3) && (wheel2_score == 9) && (wheel3_score == 9)) || ((wheel1_score == 9) && (wheel2_score == 9) && (wheel3_score == 5)) || ((wheel1_score == 9) && (wheel2_score == 5) && (wheel3_score == 9)) || ((wheel1_score == 5) && (wheel2_score == 9) && (wheel3_score == 9)) || ((wheel1_score == 3) && (wheel2_score == 3) && (wheel3_score == 11)) || ((wheel1_score == 3) && (wheel2_score == 11) && (wheel3_score == 3)) || ((wheel1_score == 11) && (wheel2_score == 3) && (wheel3_score == 3)) || ((wheel1_score == 11) && (wheel2_score == 11) && (wheel3_score == 3)) || ((wheel1_score == 11) && (wheel2_score == 3) && (wheel3_score == 11)) || ((wheel1_score == 3) && (wheel2_score == 11) && (wheel3_score == 11)) || ((wheel1_score == 5) && (wheel2_score == 5) && (wheel3_score == 11)) || ((wheel1_score == 5) && (wheel2_score == 11) && (wheel3_score == 5)) || ((wheel1_score == 11) && (wheel2_score == 5) && (wheel3_score == 5)) || ((wheel1_score == 11) && (wheel2_score == 11) && (wheel3_score == 5)) || ((wheel1_score == 11) && (wheel2_score == 5) && (wheel3_score == 11)) || ((wheel1_score == 5) && (wheel2_score == 11) && (wheel3_score == 11)) || ((wheel1_score == 9) && (wheel2_score == 9) && (wheel3_score == 11)) || ((wheel1_score == 9) && (wheel2_score == 11) && (wheel3_score == 9)) || ((wheel1_score == 11) && (wheel2_score == 9) && (wheel3_score == 9)) || ((wheel1_score == 11) && (wheel2_score == 11) && (wheel3_score == 9)) || ((wheel1_score == 11) && (wheel2_score == 9) && (wheel3_score == 11)) || ((wheel1_score == 9) && (wheel2_score == 11) && (wheel3_score == 11)) || ((wheel1_score == 3) && (wheel2_score == 5) && (wheel3_score == 11)) || ((wheel1_score == 11) && (wheel2_score == 3) && (wheel3_score == 5)) || ((wheel1_score == 3) && (wheel2_score == 11) && (wheel3_score == 5)) || ((wheel1_score == 5) && (wheel2_score == 11) && (wheel3_score == 5)) || ((wheel1_score == 5) && (wheel2_score == 3) && (wheel3_score == 11)) || ((wheel1_score == 11) && (wheel2_score == 5) && (wheel3_score == 3)) || ((wheel1_score == 3) && (wheel2_score == 9) && (wheel3_score == 11)) || ((wheel1_score == 11) && (wheel2_score == 3) && (wheel3_score == 9)) || ((wheel1_score == 3) && (wheel2_score == 11) && (wheel3_score == 9)) || ((wheel1_score == 9) && (wheel2_score == 11) && (wheel3_score == 9)) || ((wheel1_score == 9) && (wheel2_score == 3) && (wheel3_score == 11)) || ((wheel1_score == 11) && (wheel2_score == 9) && (wheel3_score == 3)) || ((wheel1_score == 5) && (wheel2_score == 9) && (wheel3_score == 11)) || ((wheel1_score == 11) && (wheel2_score == 5) && (wheel3_score == 9)) || ((wheel1_score == 5) && (wheel2_score == 11) && (wheel3_score == 9)) || ((wheel1_score == 9) && (wheel2_score == 11) && (wheel3_score == 9)) || ((wheel1_score == 9) && (wheel2_score == 5) && (wheel3_score == 11)) || ((wheel1_score == 11) && (wheel2_score == 9) && (wheel3_score == 5))) any_bar = TRUE;
|
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
|
03-30-2005 04:30
Dude I am seriously going to create a Most Horrible Code Award, just so you can win it 
|
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
|
03-30-2005 07:42
Um... holy crap.  Perhaps you should use a global variable or two instead, and check for differences in each bar? 
_____________________
---
|
Olmy Seraph
Valued Member
Join date: 1 Nov 2004
Posts: 502
|
03-30-2005 07:55
Sacre merde! Dude, have you ever heard of matching data with a table? Structuring your data as opcodes is rather inefficient and hard to maintain compared to putting it in a table (list), and creating an algorithm that matches the runtime data to whatever constants you've declared.
I've learned over the years that the most important ability of a programmer is the flexibility to work within the programming model of a language/system. Every language has its own idioms, and you won't be effective unless you learn to speak with them (see my sig). I've seen people write Pascal code in Smalltallk, FORTRAN in HyperTalk, and now I've seen someone write assembly in LSL.
_____________________
Some people are like Slinkies... not really good for anything, but they sure bring a smile to your face when you push them down the stairs.
|
Flyingroc Chung
:)
Join date: 3 Jun 2004
Posts: 329
|
03-30-2005 08:51
Patryk, you might want to make a function called element_of like so: integer element_of(list lis, integer elem) { if(llListFindList(lis, [elem]) == -1) { //did not find the thing return FALSE; } else { return TRUE; } }
then in your code you can do something like list any_bar_list = [3, 5, 9, 11]; //... else if( element_of(any_bar_list, wheel1) && element_of(any_bar_list, wheel2) && element_of(any_bar_list, wheel3) {
any_bar = TRUE;
}
You might need a !(wheel1 == wheel2 && wheel2 == wheel3) too, depending on what your previous if statements were. This way may be closer to how you think about the program (no multiplications), but may be easier to understand (at least should be much easier to write  . (CAVEAT: I ahvent actually tried this 
|
Tiger Crossing
The Prim Maker
Join date: 18 Aug 2003
Posts: 1,560
|
03-30-2005 11:04
Use a character for each wheel position, which is more human-readable than prime numbers: b = bar w = wild etc... Create a string based on the curent position of the wheels, like string curent = "bbw"; // = bar, bar, wild Then a global list like this can hold all the winning combos: list gWins = [ "bbb", "bbw", "bwb", "wbb", "bww", "www" ]; Limit this list as you like. Make it a strided list, and you can add the winning amount or multiplier in as well, if you want to put all the winning paterns in one list. Or make a separate list for each win type. Then just test for the presence of your current wheel pattern in the list (or lists): integer pos = llListFindList( gWins, curent ); if ( pos != -1 ) llSay( 0, "We HAVE a WHINNAAAH!" );
_____________________
~ Tiger Crossing ~ (Nonsanity)
|
Olmy Seraph
Valued Member
Join date: 1 Nov 2004
Posts: 502
|
03-30-2005 11:54
From: Tiger Crossing Use a character for each wheel position, which is more human-readable than prime numbers: But they don't combine to form unique products. However, you *could* sort characters alphabetically and eliminate redundant combos like bbw/bwb/wbb.
_____________________
Some people are like Slinkies... not really good for anything, but they sure bring a smile to your face when you push them down the stairs.
|
Patryk Under
Registered User
Join date: 3 Mar 2005
Posts: 45
|
03-30-2005 12:33
Thank's alot for all these good suggestions helping me alot, ithink the path i'll choose is somewhere around that gstring table thingy.
Btw. reply to Eggy Lippmann's comment, i realy hope i'd win it, anything else would be very frightening.
|
Tiger Crossing
The Prim Maker
Join date: 18 Aug 2003
Posts: 1,560
|
03-30-2005 12:39
From: Olmy Seraph But they don't combine to form unique products. However, you *could* sort characters alphabetically and eliminate redundant combos like bbw/bwb/wbb. Yes, if position doesn't matter, but in many slot machines, position does matter. In the classic 21 Bell machine that I based my own slots on, for example, BAR is used as a wildcard only on the third wheel. I could ot have used the prime trick for mine. I don't know our thread-host's needs however. But the prime trick IS very handy for many applications! I didn't mean to knock it, Olmy, just to provide an option. 
_____________________
~ Tiger Crossing ~ (Nonsanity)
|