comparing arrays
Blitz3D Forums/Blitz3D Programming/comparing arrays
| ||
I am writing a slot machine game... Really good looking BUT having some problems with sorting out how to figure the wins. I have a wheel mesh with 10 pictures on it spaced... Matty helped me roll that thing and it now stops on whatever the random number says it should. It is beautiful. It creates 4 random numbers from 0 - 9 and stops the wheel on whatever number it is supposed to. This part all works. Now the problem... I put three cherries on the wheel at position 1,5,8 I put two $ signs on the wheel at position 3,7 I put one star on the wheel at position 2 I put one BAR on the wheel at position 4 I put one WILDcard on the wheel at pos. 6 I put a DOUBLEbar on the wheel at pos. 9 and I put a LEMON on the bar at position 0 Minimum win is TWO objects and a WILDcard. Two cherries and a wildcard wins 1X bet. BUT since cherries are at three different positions??? How can I account that on 4 wheels... WHERE the 4th wheel could be anything else? I thought of this: 1. Making EACH object have a distinct point value. Ie: Cherreies=1, $signs = 7, BAR = 16 etc... Then I could just add up the points and do that with math... BUT If you can get 2 cherries and a wildcard AND there is another wheel what would the totals be? CHERRY LEMON CHERRY WILDCARD LEMON CHERRY CHERRY WILDCARD CHERRY WILDCARD WILDCARD CHERRY So I thought this: 2. Recursively testing from the top down... IF 4 lemons = JACKPOT call a test for that first... then 3 lemons and a wildcard... then three lemons and ANYTHING... Then two lemons and a wildcard and anything...... But how do I account for "ANYTHING"? -RZ |
| ||
'Simple solution': How about chaining together the digits on the wheels and using a Select statement to create a virtual lookup table for wins... wheel1 = EvalWheel(Position1) wheel2 = EvalWheel(Position2) wheel3 = EvalWheel(Position3) wheel4 = EvalWheel(Position4) Allwheels = 1000*wheel1 + 100*wheel2 + 10*wheel3 + wheel4 Select Allwheels case 0 ; i.e 0000 = 4 lemons ... pay out for 4 lemons case 1111 ; = 4 cherries ... pay out for 4 cherries case 1116 ; = 3 cherries and wildcard ... pay out for 3 cherries and wildcard case 1161 ; = 3 cherries and wildcard ... pay out for 3 cherries and wildcard case 1611 ; = 3 cherries and wildcard ... pay out for 3 cherries and wildcard case 6111 ; = 3 cherries and wildcard ... pay out for 3 cherries and wildcard ... etc ... default ; no win End Select Function EvalWheel(itsPosition) if (itsposition = 5) or (itsPosition = 8) return 1 endif if (itsPosition = 7) return 3 endif return itsPosition End Function The EvalWheel() function ignores the actual position and only considers the 'object' on the display, so there is less coding, but still a lot of work to figure all winning positions. A possible improvement would be to sort the wheel values before entering the Select block, so that 1116, 1161, 1611 and 6111 would all be evaluated by the 1116 case. |
| ||
You can also put every match for the same action on 1 line:Select Allwheels case 0 ; i.e 0000 = 4 lemons ... pay out for 4 lemons case 1111 ; = 4 cherries ... pay out for 4 cherries case 1116, 1161, 1611, 6111 ; = 3 cherries and wildcard ... pay out for 3 cherries and wildcard ... etc ... default ; no win End Select |
| ||
Both are fantastic and teaching me more about blitz as I go! Thank you both so far... : ) Now Blackjumper... Sort? I understand Sort from spreadsheets etc. but I didn't think Blitz had a sort feature... Lemme look... Nope... would be an interesting feature... I have a feeling that I would have to set up the answer as a string and run through the string about 4 times to move the lowest integers to the left with shift... |
| ||
Looks like PowerPC603's suggestion removes the need to do a sort at all :-) However, all programmers should learn to sort - it's a law of coding or something !! There are some sort routines in the codearcs... Skidracer's bubblesort works on types TFT's Quicksort is based on an array Since you only have 4 wheels to deal with, a quick and dirty routine should be easy enough to code up... |
| ||
Yep... I remember bubblesort vaguely from the Atari daze... I am having to re learn all the BASIC I had forgotten. It is pretty fun and it keeps me sane here... Gotta have a hobby! Seriously thanks for all your help and advice. Good ideas all the way! I hope other people are getting idea or inspiratiopn from this! : ) -RZ |
| ||
Rook, My wife loves slot machine games! Very Interested in seeing how your 'One-Arm Bandit' turns out. |
| ||
I wanted to write one that would not download or install a lot of spyware, malware, casino links on your desktop etc. My wife loves them too... Just finished the hard code and putting in the prettys now. Did a showoff here: http://www.blitzbasic.com/Community/posts.php?topic=44953 :) -RZ |