Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to process combinations of results?

Status
Not open for further replies.

rhyno2k

IS-IT--Management
Jun 9, 2001
222
US
Hi,


I'm working on a PHP poker simulation (holdem is the game). I'm trying to figure out a way to evaluate the strength of a given hand, and am a bit stuck.

The card values are stored in arrays.

Board cards:
$Board[1], $Board[2], etc.

Player cards:
$Player[1][1] & $Player[1][2] (Player 1 - hole cards 1 & 2)
$Player[2][1] & $Player[2][2] (Player 2 - hole cards 1 & 2)
etc.

Rank & Suit in subarrays:
$Board[2][rank] = "7" (second board card is a 7)
$Player[3][2][suit] = "h" (Player 3's second card is a heart)

Assuming I'll have a function "evalStrength()", and I'll call it passing two cards as a parameter, e.g.
Code:
evalStrength($Player[1][1],$Player[1][2]);

How can I iterate through each of the combinations of cards (Player & Board) to evaluate hand strength at various stages of the deal (1 on flop, 6 on turn, and especially 21 on river)?


Thanks,
--RHYNO
 
Answered my own question here, but posting for the benefit of future readers:

Found a function in the PHP Cookbook
that will generate combinations (and permutations) of arrays.

The specific one I'm using for my array of cards is:
Code:
// determine all possible hand combinations (board + player)
	function combinations($array) {
	// initialize by adding the empty set
	$results = array(array( ));
	foreach ($array as $element)
		foreach ($results as $combination)
		array_push($results, array_merge(array($element), $combination));
	return $results;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top