필터 지우기
필터 지우기

Texas Hold'em Card Problem

조회 수: 1 (최근 30일)
Johnny
Johnny 2014년 2월 19일
편집: Johnny 2014년 2월 20일
=====================================================
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개)

카테고리

Help CenterFile 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!

Translated by