Poker Hand Detection


A big part of our game is having the player collect cards as they progress the run in order to buff up their character. And as they collect those cards they will also be able to create a poker hand from the cards they've collected. So,  implementing a way for the game to recognize what poker hand the player currently has is necessary. To do this, I needed to create a way for the game to not only keep track of what cards the player has but as well to sort those cards in order to know if the cards produce a hand. Sorting is necessary since the player can have a pair in hand but if the cards aren't gotten one after the other, then it wouldn't have detected a pair since they aren't right next to each other. To fix this, I made a copy list of the cards in hand and then sorted that copy based of the rank and suits of the card.

(Despite it saying High Card x5 it will use the highest poker hand which in this case is Royal Flush)

 I needed to create some helper functions that allowed me to get the Rank and Suit of the card using the name of the card in to do so (Some string manipulation) as well as making a custom sort that would organize the hand based of the rank as well as suit using LINQ.


 With this done I've made a way for the game to recognize which poker hand the player has as soon as a card is picked up, it does not check constantly only once a card is added. Now, some testing is needed to ensure that any combination of card pickups will correctly be assessed to give the player their buff. To do this, A team member created a specific card pickup that can be used for testing by using a passed in scriptable game object .  I then made scriptable game objects for each card and so we have ways for testing a multitude of card pickup combinations as well as having specific card pickups for the future.



Published 4/12/2024 

Author: Gustavo Camacho

Get Suits of the Abyss

Leave a comment

Log in with itch.io to leave a comment.