Texas Hold'em Card Problem
조회 수: 1 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156987/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156992/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156994/image.jpeg)
=====================================================
function CardMatrix=Texas_HoldEm(card1, card2) Cards = {'A','K','Q','J','10','9','8','7','6','5','4','3','2'};
Suits = {'S','D','H','C'};
NumSuits = length(Suits);
NumCards = length(Cards);
%Parse Player 1's cards
PlayersCards = zeros(1, 2);
PlayersCards(1) = GetCard(card1);
PlayersCards(2) = GetCard(card2);
if PlayersCards(1) == PlayersCards(2)
error('Player 1 must be dealt two different cards')
end
%Organize Player 1's cards into a matrix
CardMatrix = zeros(4,13);
CardMatrix(PlayersCards) = 1;
------------------------------------------------
% Gets the card associated with a card string
function card = GetCard(cardStr)
if isempty(cardStr)
card = 0;
else
cardNum = find(strcmpi(Cards,cardStr(1:(end-1))));
suit = find(strcmpi(Suits,cardStr(end)));
if ((length(cardNum) ~= 1) || (length(suit) ~= 1))
card = 0;
else
card = suit + (cardNum - 1) * NumSuits;
end
end
end
end
===================================================
>> I think I got the first task, but I want to know how to make it simpler, like declare and initialise at the same time maybe?
syms numPairs
syms array
syms probPair
numPairs = 0;
array = 0;
probPair = 0;
numRows = size(CardMatrix,1); % The number of rows
% Collapse matrix into an array by summing along the rows
for i = 1:numRows;
array = CardMatrix(i,:) + array;
end;
% Count the number of possible pairs that P2 can make
for j = 1:length(array);
numPairs = nchoosek( numRows - array(j), 1 ) + numPairs;
end;
% Determine the probability that P2 has a pair
probPair = numPairs/nchoosek(50,2)
-------------------------------------------------
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156997/image.jpeg)
I am stuck on task 2 now.. can someone give me some hints?
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Acquisition Toolbox Supported Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!