Poker Stuff in Game Maker
Posted Jun 08 2024(I'm just kinda writing out my thoughts 'n process while working on this game. I might do this again, might not. All just for fun!)
I've been working on a Poker game as of late in Game Maker, and I haven't gotten a terribly good chance to make use of Game Maker's Structs they added back in 2.3 - they're incredibly powerful and lightweight, compared to previous solutions.
Structs are little containers for data, much like a Game Maker Object. Unlike a GM Object, they don't have any default variables attached to them - none of the default variables like hspeed, direction, sprite_index, etc. will be available to you on Structs unless you add them. That's what makes them so lightweight, and way better for what I'm doing here - I don't need all the extra stuff, and it uses up less memory (although I need to take care of memory management of these manually, but that's fine).
num = _num;
suit = _suit;
}
From here, I create 52 of these cards and put them into an array that'll act as our deck, making sure that we make one of each unique combination. I also make an empty array to act as the discard pile.
I also handle my cards' strengths from 2 to Ace, since that tends to be easier to calculate strength from (it's a little more work for hands like a 5-high Straight, but that's fine).
After that, I can make as many hands as I want as their own arrays, and push 5 cards from the deck into each hand.
I've made functions that split up the work here to make things easier, and build off each other - here was the idea.
First off,
1. Evaluate a hand and get its strength (High Card, Flush, Straight, etc.), then return that strength value.
We can then store the individual strengths of each hand, and as long as they don't match strengths, then we know who won. But what happens if you get a match? Well...
2. Check both hands - if they don't match, return the winner. Otherwise we run a state machine, with the current "state" being the matched strengths. Now all we gotta do is individually check on each strength type, and return the winner (or a tie) in that case.
There's a few methods I found online, but the one I grasped was the 'bucket' histogram method, which works for most hands - and the ones left over have to be done manually.
Okay, so then what?
3. A function set up to clear the hand using an array of indexes, and put them into the discard pile. This might seem odd, but this is planning ahead for two things: clearing a hand between rounds, and letting the player (or bots) pick specific cards they wanna throw out.
And finally,
4. A function set off by the 3rd function, meant to empty out the discard pile, shove it into the deck, and then shuffle it.
As well as-
5. A function meant to fill out each hand from the deck, and will also set off the 4th function if we run out of cards in the deck.
With all that set up, the fun part is making the turn order, betting, CPUs, etc. - but the fundamentals we need to plug into are done.
And that's just about where I've been while working on this - it's been a blast though, personally. This started out of a challenge just to evaluate any Poker hand back in December, but coming back to it in March really gave me some time to refresh. I ended up with a better way to handle it that actually works, and I knocked out the challenge within a couple hours. Everything past the first function I described here has all just been extra stuff on top of that challenge, but it's been suprisingly enjoyable. I'm working hard on it still, and it's coming out really solid - I should have something for y'all to play by the end of the year, that's for sure.
I'm sure I'll have some more stuff to talk about with Game Maker stuff in the future.
If y'all have any questions or suggestions, feel free to shoot me a message about it on BlueSky or Cohost!
Thanks for reading!
-Chloe