Any advice on making a poker game?

6 views (last 30 days)
John
John on 1 Dec 2014
Commented: Dominic Mazzone on 11 Nov 2019
Hello Everyone!
I need some help with a little project that I'm working on right now and I think all of you smart people may be able to help me out
Basically, it's a poker game made from scratch. I got a matrix of 52 cards, I'm setting down conditions to allow the actual rules of poker to be met, and I'm doing this within 6 rounds while incorporating a graphical user interface, but I'm stumped on a few things
1) How do I prevent the same card from being pulled twice?
The way to chose the card is completely random, but it's a very real chance that it can choose the same card twice and I don't want that to happen, what do I need to do to prevent that
2) How do I associate jpeg images with the selected cards?
In my head it doesn't seem that hard to do, but because I'm make a graphical user interface, when the card is chosen I want to show it. Like the 1st column and the 3rd row I want to be the ace of clubs and I want to display that using gui. I also want to associate changing numerical values with gui in an attempt to display the amount of money that you currently have, and depending on if you change or lose some the amount you have will change depending on how much you bet.
3) Based on the card that is pulled, how do I give it a suit?
I would like to do this as well. It seems that depending on the row that the card is pulled from, or the value of the card, I want to give it a suit. How do I do that exactly? It would make the game a whole lot easier to make if I knew how to do that
4) General tips and advice
I'm not looking for someone to completely do this for me, I get what I need to do in my head but I can't code it. My teacher just went over the basics, and the hardest part for me are the above issues. However some advice is grealy appreciated and wanted. The code is beneath
Maindeck = [1,2,3,4,5,6,7,8,9,10,11,12,13;
1,2,3,4,5,6,7,8,9,10,11,12,13;
1,2,3,4,5,6,7,8,9,10,11,12,13;
1,2,3,4,5,6,7,8,9,10,11,12,13];
Starting_Betting_Amount = 1500;
Suit = randi(4);
Card_Number = randi(13);
Suit_2 = randi(4);
Card_Number2 = randi(13);
Card_1 = Maindeck(Suit,Card_Number);
if Card_1 == 1
Player_Card_1 = 14;
elseif Card_1 == 2
Player_Card_1 = 2;
elseif Card_1 == 3
Player_Card_1 = 3;
elseif Card_1 == 4
Player_Card_1 = 4;
elseif Card_1 == 5
Player_Card_1 = 5;
elseif Card_1 == 6
Player_Card_1 = 6;
elseif Card_1 == 7
Player_Card_1 = 7;
elseif Card_1 == 8
Player_Card_1 = 8;
elseif Card_1 == 9
Player_Card_1 = 9;
elseif Card_1 == 10
Player_Card_1 = 10;
elseif Card_1 == 11
Player_Card_1 = 11;
elseif Card_1 == 12
Player_Card_1 = 12;
elseif Card_1 == 13
Player_Card_1 = 13;
end
Card_2 = Maindeck(Suit_2,Card_Number2);
if Card_2 == 1
Player_Card_2 = 14 ;
elseif Card_2 == 2
Player_Card_2 = 2;
elseif Card_2 == 3
Player_Card_2 = 3;
elseif Card_2 == 4
Player_Card_2 = 4;
elseif Card_2 == 5
Player_Card_2 = 5;
elseif Card_2 == 6
Player_Card_2 = 6;
elseif Card_2 == 7
Player_Card_2 = 7;
elseif Card_2 == 8
Player_Card_2 = 8;
elseif Card_2 == 9
Player_Card_2 = 9;
elseif Card_2 == 10
Player_Card_2 = 10;
elseif Card_2 == 11
Player_Card_2 = 11;
elseif Card_2 == 12
Player_Card_2 = 12;
elseif Card_2 == 13
Player_Card_2 = 13;
end
display(Player_Card_1);
display(Player_Card_2);
Dealt_Card_1 = Maindeck(randi(4),randi(13));
if Dealt_Card_1 == 1
Table_Card_1 = 14;
elseif Dealt_Card_1 == 2
Table_Card_1 = 2;
elseif Dealt_Card_1 == 3
Table_Card_1 = 3;
elseif Dealt_Card_1 == 4
Table_Card_1 = 4;
elseif Dealt_Card_1 == 5
Table_Card_1 = 5;
elseif Dealt_Card_1 == 6
Table_Card_1 = 6;
elseif Dealt_Card_1 == 7
Table_Card_1 = 7;
elseif Dealt_Card_1 == 8
Table_Card_1 = 8;
elseif Dealt_Card_1 == 9
Table_Card_1 = 9;
elseif Dealt_Card_1 == 10
Table_Card_1 = 10;
elseif Dealt_Card_1 == 11
Table_Card_1 = 11;
elseif Dealt_Card_1 == 12
Table_Card_1 = 12;
elseif Dealt_Card_1 == 13
Table_Card_1 = 13;
end
Dealt_Card_2 = Maindeck(randi(4),randi(13));
if Dealt_Card_2 == 1
Table_Card_2 = 14;
elseif Dealt_Card_2 == 2
Table_Card_2 = 2;
elseif Dealt_Card_2 == 3
Table_Card_2 = 3;
elseif Dealt_Card_2 == 4
Table_Card_2 = 4;
elseif Dealt_Card_2 == 5
Table_Card_2 = 5;
elseif Dealt_Card_2 == 6
Table_Card_2 = 6;
elseif Dealt_Card_2 == 7
Table_Card_2 = 7;
elseif Dealt_Card_2 == 8
Table_Card_2 = 8;
elseif Dealt_Card_2 == 9
Table_Card_2 = 9;
elseif Dealt_Card_2 == 10
Table_Card_2 = 10;
elseif Dealt_Card_2 == 11
Table_Card_2 = 11;
elseif Dealt_Card_2 == 12
Table_Card_2 = 12;
elseif Dealt_Card_2 == 13
Table_Card_2 = 13;
end
Dealt_Card_3 = Maindeck(randi(4),randi(13));
if Dealt_Card_3 == 1
Table_Card_3 = 14;
elseif Dealt_Card_3 == 2
Table_Card_3 = 2;
elseif Dealt_Card_3 == 3
Table_Card_3 = 3;
elseif Dealt_Card_3 == 4
Table_Card_3 = 4;
elseif Dealt_Card_3 == 5
Table_Card_3 = 5;
elseif Dealt_Card_3 == 6
Table_Card_3 = 6;
elseif Dealt_Card_3 == 7
Table_Card_3 = 7;
elseif Dealt_Card_3 == 8
Table_Card_3 = 8;
elseif Dealt_Card_3 == 9
Table_Card_3 = 9;
elseif Dealt_Card_3 == 10
Table_Card_3 = 10;
elseif Dealt_Card_3 == 11
Table_Card_3 = 11;
elseif Dealt_Card_3 == 12
Table_Card_3 = 12;
elseif Dealt_Card_3 == 13
Table_Card_3 = 13;
end
Dealt_Card_4 = Maindeck(randi(4),randi(13));
if Dealt_Card_4 == 1
Table_Card_4 = 14;
elseif Dealt_Card_4 == 2
Table_Card_4 = 2;
elseif Dealt_Card_4 == 3
Table_Card_4 = 3;
elseif Dealt_Card_4 == 4
Table_Card_4 = 4;
elseif Dealt_Card_4 == 5
Table_Card_4 = 5;
elseif Dealt_Card_4 == 6
Table_Card_4 = 6;
elseif Dealt_Card_4 == 7
Table_Card_4 = 7;
elseif Dealt_Card_4 == 8
Table_Card_4 = 8;
elseif Dealt_Card_4 == 9
Table_Card_4 = 9;
elseif Dealt_Card_4 == 10
Table_Card_4 = 10;
elseif Dealt_Card_4 == 11
Table_Card_4 = 11;
elseif Dealt_Card_4 == 12
Table_Card_4 = 12;
elseif Dealt_Card_4 == 13
Table_Card_4 = 13;
end
display(Table_Card_1)
display(Table_Card_2)
display(Table_Card_3)
display(Table_Card_4)
display(Starting_Betting_Amount)
Choice = questdlg('How much do you want to bet?', ...
'Options', ...
'100', '200', '300', '300');
switch Choice
case '100'
Round_1_Starting_Total = Starting_Betting_Amount-100;
case '200'
Round_1_Starting_Total = Starting_Betting_Amount-200;
case '300'
Round_1_Starting_Total = Starting_Betting_Amount-300;
end
display(Round_1_Starting_Total)
Dealt_Card_5 = Maindeck(randi(4),randi(13));
if Dealt_Card_5 == 1
Table_Card_5 = 14;
elseif Dealt_Card_5 == 2
Table_Card_5 = 2;
elseif Dealt_Card_5 == 3
Table_Card_5 = 3;
elseif Dealt_Card_5 == 4
Table_Card_5 = 4;
elseif Dealt_Card_5 == 5
Table_Card_5 = 5;
elseif Dealt_Card_5 == 6
Table_Card_5 = 6;
elseif Dealt_Card_5 == 7
Table_Card_5 = 7;
elseif Dealt_Card_5 == 8
Table_Card_5 = 8;
elseif Dealt_Card_5 == 9
Table_Card_5 = 9;
elseif Dealt_Card_5 == 10
Table_Card_5 = 10;
elseif Dealt_Card_5 == 11
Table_Card_5 = 11;
elseif Dealt_Card_5 == 12
Table_Card_5 = 12;
elseif Dealt_Card_5 == 13
Table_Card_5 = 13;
end
display(Table_Card_1)
display(Table_Card_2)
display(Table_Card_3)
display(Table_Card_4)
display(Table_Card_5)
Choice = questdlg('How much do you want to bet?', ...
'Options', ...
'100', '200', '300', '300');
switch Choice
case '100'
Round_1_Mid_Total = Round_1_Starting_Total-100;
case '200'
Round_1_Mid_Total = Round_1_Starting_Total-200;
case '300'
Round_1_Mid_Total = Round_1_Starting_Total-300;
end
display(Round_1_Mid_Total)
Dealt_Card_6 = Maindeck(randi(4),randi(13));
if Dealt_Card_6 == 1
Table_Card_6 = 14;
elseif Dealt_Card_6 == 2
Table_Card_6 = 2;
elseif Dealt_Card_6 == 3
Table_Card_6 = 3;
elseif Dealt_Card_6 == 4
Table_Card_6 = 4;
elseif Dealt_Card_6 == 5
Table_Card_6 = 5;
elseif Dealt_Card_6 == 6
Table_Card_6 = 6;
elseif Dealt_Card_6 == 7
Table_Card_6 = 7;
elseif Dealt_Card_6 == 8
Table_Card_6 = 8;
elseif Dealt_Card_6 == 9
Table_Card_6 = 9;
elseif Dealt_Card_6 == 10
Table_Card_6 = 10;
elseif Dealt_Card_6 == 11
Table_Card_6 = 11;
elseif Dealt_Card_6 == 12
Table_Card_6 = 12;
elseif Dealt_Card_6 == 13
Table_Card_6 = 13;
end
display(Table_Card_1)
display(Table_Card_2)
display(Table_Card_3)
display(Table_Card_4)
display(Table_Card_5)
display(Table_Card_6)
Choice = questdlg('How much do you want to bet?', ...
'Options', ...
'100', '200', '300', '300');
switch Choice
case '100'
Round_1_End_Total = Round_1_Mid_Total-100;
case '200'
Round_1_End_Total = Round_1_Mid_Total-200;
case '300'
Round_1_End_Total = Round_1_Mid_Total-300;
end
display(Round_1_End_Total)
Table1 = [Table_Card_1, Table_Card_2, Table_Card_3, Table_Card_4, Table_Card_5, Table_Card_6];
Player_Card_1_Value = length(find(Player_Card_1 == Table1));
Player_Card_2_Value = length(find(Player_Card_2 == Table1));
if Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 2
Player_Value = 2;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 3
Player_Value = 3;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 4
Player_Value = 4;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 5
Player_Value = 5;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 6
Player_Value = 6;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 7
Player_Value = 7;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 8
Player_Value = 8;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 9
Player_Value = 9;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 10
Player_Value = 10;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 11
Player_Value = 11;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 12
Player_Value = 12;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 13
Player_Value = 13;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 0 && Player_Card_1 == 14
Player_Value = 14;
elseif Player_Card_1_Value == 0 && Player_Card_2_Value == 1 && Player_Card_2 == 2
Player_Value = 2;
elseif Player_Card_1_Value == 0 && Player_Card_2_Value == 1 && Player_Card_2 == 3
Player_Value = 3;
elseif Player_Card_1_Value == 0 && Player_Card_2_Value == 1 && Player_Card_2 == 4
Player_Value = 4;
elseif Player_Card_1_Value == 0 && Player_Card_2_Value == 1 && Player_Card_2 == 5
Player_Value = 5;
elseif Player_Card_1_Value == 0 && Player_Card_2_Value == 1 && Player_Card_2 == 6
Player_Value = 6;
elseif Player_Card_1_Value == 0 && Player_Card_2_Value == 1 && Player_Card_2 == 9
Player_Value = 9;
elseif Player_Card_1_Value == 0 && Player_Card_2_Value == 1 && Player_Card_2 == 10
Player_Value = 10;
elseif Player_Card_1_Value == 0 && Player_Card_2_Value == 1 && Player_Card_2 == 11
Player_Value = 11;
elseif Player_Card_1_Value == 0 && Player_Card_2_Value == 1 && Player_Card_2 == 12
Player_Value = 12;
elseif Player_Card_1_Value == 0 && Player_Card_2_Value == 1 && Player_Card_2 == 13
Player_Value = 13;
elseif Player_Card_1_Value == 0 && Player_Card_2_Value == 1 && Player_Card_2 == 14
Player_Value = 14;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 3
Player_Value = 15;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 4
Player_Value = 16;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 5
Player_Value = 17;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 6
Player_Value = 18;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 7
Player_Value = 19;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 8
Player_Value = 20;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 9
Player_Value = 21;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 10
Player_Value = 22;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 11
Player_Value = 23;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 12
Player_Value = 24;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 13
Player_Value = 25;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 2 && Player_Card_2 == 14
Player_Value = 26;
elseif Player_Card_1_Value == 1 && Player_Card_2_Value == 1 && Player_Card_1 == 3 && Player_Card_2 == 2
Player_Value = 15;
This is all I got so far in terms of code
Player_Card_1_Value is how many times the first of the cards in your hand is equal to the cards out on the table, I do this using the length(find(Player_Card_1 == x)) with x being equal to a number, in turn this will produce a 0, 1, 2, or 3. 1 means a pair, 2 means 3 of a kind, 3 means four of a kind and 0 means nothing is equal to this card. This happens for 2 cards in your hand, depending on number of the card, how many there are and suit will determine the outcome
I'm using the display function right now as a way to display the cards using code, I want to change that and display them when using gui while describing suit and number, I'm using 14 to represent Ace as that is greater than a King which has a value of 13, Queen = 12, Jack = 11, and all of the number cards have a value that is equal to the number of the card itself
I'm also keeping the tradition rules of Texas Hold'em in there as well
Nothing < One-Pair < Two-Pair < 3-of-a-kind < Straight < Flush < Full-House < Four-of-a-Kind < Straight-Flush < Royal-Flush
I know it's a lot, but even the slightest piece of information that will help will be amazingly helpful. Think of my mindset right now as "I'm in focus but I can't get the big picture"
Please comment and help! I'll also attach an image of my current gui so far, only the template though
  2 Comments
Mohammad Abouali
Mohammad Abouali on 1 Dec 2014
My advice is to Share it on FileExchange once it is done, please. That would be really fun to have.
Thank you
Andrew Reibold
Andrew Reibold on 1 Dec 2014
^ That is not advice... that is a request... lol

Sign in to comment.

Answers (2)

the cyclist
the cyclist on 1 Dec 2014
For your Question 1, I suggest one of the following approaches:
If you have the Statistics Toolbox, then you can used the randsample command. Specifically, the command
randIndex = randsample(52,52);
will give you the number 1-52, in a random order, with no repeats.
If you do not have that toolbox, then
[~,randomIndex] = sort(rand(52,1))
will do the same thing.
I suggest looking up the help files on those functions.
  2 Comments
John
John on 1 Dec 2014
Interesting, I tried doing that and it did put the numbers 1-52 in a random order. Is the idea that I just play with the deck like that? Just make a random array of numbers and depending on the value of the numbers the array makes will determine suit and value of the card without choosing it twice?
the cyclist
the cyclist on 1 Dec 2014
Yes. You just need to associate the numbers 1-52 with each card of the deck.

Sign in to comment.


Sean de Wolski
Sean de Wolski on 1 Dec 2014
Build on the cyclist's idea, I would identify card numbers from 1:52 based on mod(card,13)
mod(1:52,13)
This will save you all of those crazy else-ifs that you have.

Categories

Find more on Card games in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!