Texas Hold'em Card Problem
2 ビュー (過去 30 日間)
古いコメントを表示



=====================================================
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)
-------------------------------------------------

I am stuck on task 2 now.. can someone give me some hints?
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!