As a hobby project, I’m coding a mini gambling/card-game that I invented, similar to blackjack. You can play the current demo here, but I wanted to add a more complex mechanic and I’m not sure how to do the coding that it would entail.
Would welcome all the help I can get!! Or even just thoughts on the mechanics!
Basic rules of the game
- There are 8 types of cards (peasant all the way up to Pope), each with a different score. There are also special “pairings” that give you special scores (e.g. King with Queen, two peasants, all royals etc.)
- You place a starting bid. So does your opponent.
- You draw a card, your opponent draws a card. You can add to your original bid, if you want.
- You draw another card. Your opponent draws another card.
- You tally up the scores of both your cards. The person with the highest score wins.
Right now, I’m using a random number generator to generate what cards are drawn. Each card is assigned a number from 1 to 8. (Peasant = 1, Jester = 2 etc.)
Like blackjack, the game would be so much cooler if there’s a fixed number of each type of card in the deck, so that getting one of them would affect the chances of getting another one of them in the next draw. E.g. if there are only 2 cards of each type in a deck, and you get a peasant, then you can tell that the probability of getting another peasant is lower.
However, I’m not sure how to code this - how do I craft a custom “list” for random number generator (beyond setting the min and max range) to exclude cards (i.e. “numbers”) that have been drawn before? More importantly, what’s the most elegant way to automate the updating of this list so that it isn’t super clunky?
What the code looks like currently
For now, to avoid the problem of dealing with differing probabilities (e.g. if there are only 2, or 3 of each type of card), I’ve said that there are 4 of each type in a deck. Meaning that you can get a King without there being a lower probability of getting a King again in your next draw (nor will your opponent’s likelihood of getting a King be affected).
This means the code is relatively straightforward:
*rand first_card_generator 0 8 *if first_card_generator = 1 *set first_card "peasant" It's a [i]peasant[/i]. 1 point. *if first_card_generator = 2 *set first_card "jester" It's a [i]jester[/i]. 2 points. *if first_card_generator = 3 *set first_card "scholar" It's a [i]scholar[/i]. 3 points. *if first_card_generator = 4 *set first_card "marshall" It's a [i]marshall[/i]. 4 points. *if first_card_generator = 5 *set first_card "chancellor" It's a [i]chancellor[/i]. *if first_card_generator = 6 *set first_card "queen" It's a [i]queen[/i]. 6 points. *if first_card_generator = 7 *set first_card "king" It's a [i]king[/i]. *if first_card_generator = 8 *set first_card "pope" It's a [i]pope[/i]. 8 points.
Thanks very much in advance