coding the drinking game "kings"

I am supposed to code a game as a final project for my class and I was thinking that coding the drinking game "Kings" would be simple. Basically you pick a card and whatever rank you pick, there is a certain action you must do. So if you pull an ace, you must waterfall your drink. So there would just be 13 actions associated with the game that is it. I am not very good at coding and was hoping someone could show me how to start and then give me steps in completing this game.

5 Kommentare

Walter Roberson
Walter Roberson am 1 Dez. 2020
randperm(52) to get the shuffled deck. mod() 13 to get the rank 0 to 12. switch() on the rank.
Connor Mondock
Connor Mondock am 1 Dez. 2020
If you don't mind, do you think you could be a little more specific and maybe show me? Like I stated, I am not a good coder at all.
deck = expression that shuffles the cards, returning a vector of card numbers
first_card = index deck to pull out the first value
first_rank = take mod of first_card and 13
switch first_rank
0: do something for ace
1: do something for deuce
end
Connor Mondock
Connor Mondock am 1 Dez. 2020
Okay thank you this will help me.
Connor Mondock
Connor Mondock am 1 Dez. 2020
Actually if you don't mind, could you show me how to do the mod() thing you are talking about? I do not understand that. I know how to get a random card from the deck and how to do the switch part but I do not know what you mean when you say "mod() of the ranks".

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Vimal Rathod
Vimal Rathod am 3 Dez. 2020

0 Stimmen

Hi,
From the comments what Walter meant was to assign each card with numbers such as 0-12 for spades, 13-25 hearts and so on. So when you do randperm(52) you get random numbers that means the cards are shuffled.
You could use mod function to do modulo of that number. Suppose the number is 16 you do modulo of 13 and you get 3 which means the card has a number 4 on it and as its above 13 you have assigned it to hearts.
Refer the following link for modulo Function.

Kategorien

Mehr zu Strategy & Logic finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 1 Dez. 2020

Beantwortet:

am 3 Dez. 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by