How to test if two elements in a vector are of the same value.
19 次查看(过去 30 天)
显示 更早的评论
I am trying to find where two elements of a vector share the same value. As well as put it through an if statement to change different things in my poker GUI (which checks your hand and the river to tell you what hand exists on the table). My matlab skills are basic so some explanation would be helpful!
for i=1:7
box(i)=0
end
box(1)=str2double(get(handles.edit1,'string'));
%Continues to fill to the element of box(7)
box(7)=str2double(get(handles.edit7,'string'));
box=sort(box);
%Say that box=[1 1 3 8 9 11 12]
if box(1)==box(2)
set(handles.Hand,'string','One Pair')
end
0 个评论
采纳的回答
Kevin Rawson
2019-4-13
编辑:Kevin Rawson
2019-4-13
If we assume you are using numbers 1 through 14 to represent the face value of the cards (neglecting joker), then:
cardCounts = histc(box, 1:14);
This counts the number of cards with a given face value (from 1 to 14) that exist in box.
Then if you take the sum(cardCounts == 2), you know how many single pairs you have.
0 个评论
更多回答(1 个)
Image Analyst
2019-4-13
You might be interested in my attached poker app where I compute the probability of the major hands of poker using a Monte Carlo approach.
Found 422410 "One Pair" in 1000000 hands. That is one in every 2 hands.
Percentage of "One Pair" = 42.241000%. Theory says 42.2569%
Found 47995 "Two Pairs" in 1000000 hands. That is one in every 21 hands.
Percentage of "Two Pairs" = 4.799500%. Theory says 4.7539%
Found 20894 "3 of a kind" in 1000000 hands. That is one in every 48 hands.
Percentage of "3 of a kind" = 2.089400%. Theory says 2.1128%
Found 3689 straights in 1000000 hands. That is one in every 271 hands.
Percentage of straights = 0.368900%. Theory says 0.3925%
Found 1870 Flushes (excluding straight and royal) in 1000000 hands. That is one in every 535 hands.
Percentage of Flushes = 0.187000%. Theory says 0.1956%
Found 1427 Full Houses in 1000000 hands. That is one in every 701 hands.
Percentage of Full Houses = 0.142700%. Theory says 0.1441%
Found 247 "4 of a kind" in 1000000 hands. That is one in every 4049 hands.
Percentage of "4 of a kind" = 0.024700%. Theory says 0.0240%
Found 11 straight flushes (excluding royal) in 1000000 hands. That is one in every 90909 hands.
Percentage of straight flushes = 0.001100%. Theory says 0.00139%.
Found 2 Royal Flushes in 1000000 hands. That is one in every 500000 hands.
Percentage of Royal Flushes = 0.000200%. Theory says 0.000154%
See attached m-file. Adapt as needed.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!