Created
August 19, 2015 15:21
-
-
Save GuillaumeLeclerc/f8d0d219aa07ebce8205 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $nbPlayer = 4; | |
$nbDice = 6; | |
$scores = array_fill(0, $nbPlayer, $nbDice); | |
$return = "\n"; | |
for($round = 1; count(array_filter($scores, function($score) { return $score == 0 ;})) == 0; $round++) { | |
echo $return,"Round ",$round,$return,$return; | |
$dices = array_map(function($score) { | |
return array_map(function($i) { | |
return mt_rand(0,6); | |
}, array_fill(0, $score, 0)); | |
},$scores); | |
foreach ($dices as $playerNumber => $dice) { | |
echo "Player ",$playerNumber,": ", join($dice, ","), $return; | |
$scores[$playerNumber] -= count(array_filter($dice, function($d) { return $d == 6; })); | |
$scores[($playerNumber) % $nbPlayer] += count(array_filter($dice, function($d) { return $d == 1;})); | |
} | |
} | |
$winners = array(); | |
foreach($scores as $pn => $score) { | |
if ($score == 0) $winners[] = $pn; | |
} | |
echo "The winners are : ", join($winners, ","); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment