Need to figure out how to scan trough combinations

81 Views Asked by At

I have been working on a slot machine code and I have the reels input and I coded all the different combinations that can occur. I output it to a file and sure enough everything is there. Now I need to somehow scan all the combinations and based on rules for payments (2x, 3x and 5x the same symbol) and rules that if 2 wins are there ex. aabbb that only the higher paying one will be paid out, make counters for all the payout conditions.

Here is what I have so far:

#include <stdio.h>

int main() {
    freopen("C:\\tmp\\output.txt", "w", stdout);
    char reel1[37] = { 'A', '1', 'W', 'Q', '9', 'L', '1', 'J', 'H', 'Q', '9', 'W', '1', 'A', 'M', 'K', 'Q', 'L', 'A', '9', '1', 'M', 'K', 'Q', 'H', '9', 'A', 'Q', 'K', 'T', '9', 'J', 'W', '9', '1', 'L', '9' };
    char reel2[36] = { 'A', 'K', 'L', '1', '9', 'M', 'J', '1', 'K', 'M', 'Q', '9', 'T', 'A', '1', 'Q', 'W', 'K', '9', 'L', 'J', '1', 'Q', 'L', 'K', 'J', 'W', 'A', '9', 'K', 'H', 'Q', '1', 'K', 'Q', '1' };
    char reel3[35] = { 'J', 'K', '9', 'A', '1', 'Q', 'L', '9', 'A', '1', 'T', 'J', '9', 'A', 'H', '1', 'J', '9', 'L', 'Q', '1', 'J', 'H', '9', 'K', '1', 'M', 'A', 'J', 'K', 'W', '9', '1', 'J', '1' };
    char reel4[32] = { 'K', 'A', 'L', 'Q', '1', 'M', 'A', 'K', 'J', 'M', 'Q', '1', 'H', 'J', 'A', 'K', 'M', '9', 'J', 'H', '1', 'Q', '9', 'J', '1', 'W', 'K', '9', 'J', 'T', '1', 'J' };
    char reel5[32] = { 'J', '1', 'Q', 'W', 'K', '9', 'Q', 'J', 'K', '9', '1', 'H', 'J', '9', 'A', 'M', '9', 'J', '1', '9', 'L', 'A', '9', 'J', 'L', '9', 'K', 'Q', '9', 'T', 'K', 'Q' };
    int a, b, c, d, e;
    for (a = 0; a <= 36; a++) {
        for (b = 0; b <= 35; b++) {
            for (c = 0; c <= 34; c++) {
                for (d = 0; d <= 31; d++) {
                    for (e = 0; e <= 31; e++) {
                        printf("%c%c%c%c%c\n", reel1[a], reel2[b], reel3[c], reel4[d], reel5[e]);
                    }
                }
            }
        }
    }
    return 0;
}

How do I tackle this now? I know that I have to put up counters for all the payout combinations and once it shows up and is the highest paying one on the reel, to iterate it by one until I have gone trough the whole list. But how to get there beats me. How to scan all the combinations? Anyone have suggestions?

1

There are 1 best solutions below

9
On

Your code does print all 47,738,880 possible combinations of slot values. There will be many duplicates as the wheels have duplicate items and the order probably does not matter.

Here is how you could proceed: instead of printing the combinations, call a function with the 5 slot values that will:

  • check the various winning combinations and keep the best one
  • output the combination along with the corresponding best win.

Then you can run the program and pipe its output to sort | uniq -c to get a listing with duplicates removed (and counted).

You might want to omit the losing combinations in the listing.

In addition to printing the winning combinations, you could compute the total possible wins (the sum of all wins as computed above) and divide that by the total number of outputs (37*36*35*32*32) to verify what the odds are for the player and the casino.