@@ -228,7 +228,7 @@ |
||
| 228 | 228 | |
| 229 | 229 | return new static( |
| 230 | 230 | self::HIGH_CARD, |
| 231 | - $cardValues->map(function (Card $card) { |
|
| 231 | + $cardValues->map(function(Card $card) { |
|
| 232 | 232 | return $card->value(); |
| 233 | 233 | })->toArray(), |
| 234 | 234 | $cards, |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | public function all() |
| 10 | 10 | { |
| 11 | 11 | return $this |
| 12 | - ->map(function (Action $action) { |
|
| 12 | + ->map(function(Action $action) { |
|
| 13 | 13 | return $action->toString(); |
| 14 | 14 | }) |
| 15 | 15 | ->toArray(); |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | public function hasAction(int $actionValue): bool |
| 24 | 24 | { |
| 25 | 25 | $count = $this |
| 26 | - ->filter(function (Action $action) use ($actionValue) { |
|
| 26 | + ->filter(function(Action $action) use ($actionValue) { |
|
| 27 | 27 | return $action->action() === $actionValue; |
| 28 | 28 | }) |
| 29 | 29 | ->count(); |
@@ -103,7 +103,7 @@ |
||
| 103 | 103 | public function __toString() |
| 104 | 104 | { |
| 105 | 105 | $players = $this->players() |
| 106 | - ->map(function (Player $player) { |
|
| 106 | + ->map(function(Player $player) { |
|
| 107 | 107 | return $player->name(); |
| 108 | 108 | }) |
| 109 | 109 | ->implode(', '); |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function setup(PlayerCollection $players): self |
| 26 | 26 | { |
| 27 | - $collection = $players->map(function (Player $player, $seatNumber) { |
|
| 27 | + $collection = $players->map(function(Player $player, $seatNumber) { |
|
| 28 | 28 | // everyone is still left to act |
| 29 | 29 | return [ |
| 30 | 30 | 'seat' => $seatNumber, |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | public function resetActions(): self |
| 60 | 60 | { |
| 61 | 61 | $collection = $this |
| 62 | - ->transform(function ($array) { |
|
| 62 | + ->transform(function($array) { |
|
| 63 | 63 | if ($array['action'] !== self::ALL_IN) { |
| 64 | 64 | $array['action'] = self::STILL_TO_ACT; |
| 65 | 65 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | public function sortBySeats(): self |
| 78 | 78 | { |
| 79 | 79 | $collection = $this |
| 80 | - ->sortBy(function ($array) { |
|
| 80 | + ->sortBy(function($array) { |
|
| 81 | 81 | return $array['seat']; |
| 82 | 82 | }, SORT_NUMERIC) |
| 83 | 83 | ->values(); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | // var_dump($this); |
| 112 | 112 | $result = $this |
| 113 | - ->filter(function ($array) use ($player) { |
|
| 113 | + ->filter(function($array) use ($player) { |
|
| 114 | 114 | return $array['player'] === $player; |
| 115 | 115 | }) |
| 116 | 116 | ; |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | return self::make($this->values()->toArray()); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $new = $this->sortBy(function ($value) use ($seatNumber) { |
|
| 145 | + $new = $this->sortBy(function($value) use ($seatNumber) { |
|
| 146 | 146 | if ($value['seat'] < $seatNumber) { |
| 147 | 147 | return ($value['seat'] + 1) * 10; |
| 148 | 148 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | public function removePlayer(Player $player): self |
| 160 | 160 | { |
| 161 | 161 | $collection = $this |
| 162 | - ->reject(function ($array) use ($player) { |
|
| 162 | + ->reject(function($array) use ($player) { |
|
| 163 | 163 | return $array['player'] === $player->name(); |
| 164 | 164 | }); |
| 165 | 165 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | public function getNextPlayer() |
| 173 | 173 | { |
| 174 | 174 | return $this |
| 175 | - ->reject(function ($value) { |
|
| 175 | + ->reject(function($value) { |
|
| 176 | 176 | return in_array($value['action'], [self::ACTIONED, self::AGGRESSIVELY_ACTIONED, self::ALL_IN]); |
| 177 | 177 | }) |
| 178 | 178 | ->first() |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | public function total(): Chips |
| 14 | 14 | { |
| 15 | - return Chips::fromAmount($this->sum(function (ChipPot $chipPot) { |
|
| 15 | + return Chips::fromAmount($this->sum(function(ChipPot $chipPot) { |
|
| 16 | 16 | return $chipPot->total()->amount(); |
| 17 | 17 | })); |
| 18 | 18 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function remove(ChipPot $removeChipPot) |
| 26 | 26 | { |
| 27 | - return $this->reject(function (ChipPot $chipPot) use ($removeChipPot) { |
|
| 27 | + return $this->reject(function(ChipPot $chipPot) use ($removeChipPot) { |
|
| 28 | 28 | return $chipPot->equals($removeChipPot); |
| 29 | 29 | })->values(); |
| 30 | 30 | } |
@@ -187,13 +187,13 @@ |
||
| 187 | 187 | |
| 188 | 188 | // deal to the player after the button first |
| 189 | 189 | $players |
| 190 | - ->each(function (PlayerContract $player) use ($hands) { |
|
| 190 | + ->each(function(PlayerContract $player) use ($hands) { |
|
| 191 | 191 | $hands->push(Hand::create(CardCollection::make([ |
| 192 | 192 | $this->dealCard(), |
| 193 | 193 | ]), $player)); |
| 194 | 194 | }) |
| 195 | - ->each(function (PlayerContract $player) use ($hands) { |
|
| 196 | - $hands->map(function (Hand $hand) use ($player, $hands) { |
|
| 195 | + ->each(function(PlayerContract $player) use ($hands) { |
|
| 196 | + $hands->map(function(Hand $hand) use ($player, $hands) { |
|
| 197 | 197 | if ($hand->player()->equals($player) === false) { |
| 198 | 198 | return false; |
| 199 | 199 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | public function findSeat(PlayerContract $findPlayer): int |
| 143 | 143 | { |
| 144 | 144 | return $this->players() |
| 145 | - ->filter(function (PlayerContract $player) use ($findPlayer) { |
|
| 145 | + ->filter(function(PlayerContract $player) use ($findPlayer) { |
|
| 146 | 146 | return $player->equals($findPlayer); |
| 147 | 147 | }) |
| 148 | 148 | ->keys() |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | public function findPlayerByName($playerName): PlayerContract |
| 158 | 158 | { |
| 159 | 159 | return $this->players() |
| 160 | - ->filter(function (PlayerContract $player) use ($playerName) { |
|
| 160 | + ->filter(function(PlayerContract $player) use ($playerName) { |
|
| 161 | 161 | return $player->name() === $playerName; |
| 162 | 162 | }) |
| 163 | 163 | ->first(); |
@@ -374,7 +374,7 @@ |
||
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
| 377 | - * @return PlayerContract|false |
|
| 377 | + * @return PlayerContract |
|
| 378 | 378 | */ |
| 379 | 379 | public function whosTurnIsIt() |
| 380 | 380 | { |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | { |
| 205 | 205 | $this->chipPots() |
| 206 | 206 | ->reverse() |
| 207 | - ->each(function (ChipPot $chipPot) { |
|
| 207 | + ->each(function(ChipPot $chipPot) { |
|
| 208 | 208 | // if only 1 player participated to pot, he wins it no arguments |
| 209 | 209 | if ($chipPot->players()->count() === 1) { |
| 210 | 210 | $potTotal = $chipPot->chips()->total(); |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | // split the pot between the number of players |
| 239 | 239 | $splitTotal = Chips::fromAmount(($potTotal->amount() / $evaluate->count())); |
| 240 | - $evaluate->each(function (CardResults $result) use ($splitTotal) { |
|
| 240 | + $evaluate->each(function(CardResults $result) use ($splitTotal) { |
|
| 241 | 241 | $result->hand()->player()->chipStack()->add($splitTotal); |
| 242 | 242 | }); |
| 243 | 243 | |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | { |
| 381 | 381 | $nextPlayer = $this->leftToAct()->getNextPlayer(); |
| 382 | 382 | |
| 383 | - return $this->players()->filter(function (PlayerContract $player) use ($nextPlayer) { |
|
| 383 | + return $this->players()->filter(function(PlayerContract $player) use ($nextPlayer) { |
|
| 384 | 384 | return $player->name() === $nextPlayer['player']; |
| 385 | 385 | })->first() ?? false; |
| 386 | 386 | } |
@@ -390,13 +390,13 @@ discard block |
||
| 390 | 390 | */ |
| 391 | 391 | public function collectChipTotal(): ChipPotCollection |
| 392 | 392 | { |
| 393 | - $allInActionsThisRound = $this->leftToAct()->filter(function (array $value) { |
|
| 393 | + $allInActionsThisRound = $this->leftToAct()->filter(function(array $value) { |
|
| 394 | 394 | return $value['action'] === LeftToAct::ALL_IN; |
| 395 | 395 | }); |
| 396 | 396 | |
| 397 | 397 | if ($allInActionsThisRound->count() > 1) { |
| 398 | 398 | $orderedBetStacks = $this->betStacks() |
| 399 | - ->reject(function (Chips $chips, $playerName) { |
|
| 399 | + ->reject(function(Chips $chips, $playerName) { |
|
| 400 | 400 | $foldedPlayer = $this->foldedPlayers()->findByName($playerName); |
| 401 | 401 | if ($foldedPlayer) { |
| 402 | 402 | return true; |
@@ -406,8 +406,8 @@ discard block |
||
| 406 | 406 | }) |
| 407 | 407 | ->sortByChipAmount(); |
| 408 | 408 | |
| 409 | - $orderedBetStacks->each(function (Chips $playerChips, $playerName) use ($orderedBetStacks) { |
|
| 410 | - $remainingStacks = $orderedBetStacks->filter(function (Chips $chips) { |
|
| 409 | + $orderedBetStacks->each(function(Chips $playerChips, $playerName) use ($orderedBetStacks) { |
|
| 410 | + $remainingStacks = $orderedBetStacks->filter(function(Chips $chips) { |
|
| 411 | 411 | return $chips->amount() !== 0; |
| 412 | 412 | }); |
| 413 | 413 | |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | $player = $this->players()->findByName($playerName); |
| 418 | 418 | $allInAmount = Chips::fromAmount($orderedBetStacks->findByPlayer($player)->amount()); |
| 419 | 419 | |
| 420 | - $remainingStacks->each(function (Chips $chips, $playerName) use ($allInAmount, $orderedBetStacks) { |
|
| 420 | + $remainingStacks->each(function(Chips $chips, $playerName) use ($allInAmount, $orderedBetStacks) { |
|
| 421 | 421 | $player = $this->players()->findByName($playerName); |
| 422 | 422 | |
| 423 | 423 | $stackChips = Chips::fromAmount($allInAmount->amount()); |
@@ -434,14 +434,14 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | // sort the pots so we get rid of any empty ones |
| 436 | 436 | $this->chipPots = $this->chipPots |
| 437 | - ->filter(function (ChipPot $chipPot) { |
|
| 437 | + ->filter(function(ChipPot $chipPot) { |
|
| 438 | 438 | return $chipPot->total()->amount() !== 0; |
| 439 | 439 | }) |
| 440 | 440 | ->values(); |
| 441 | 441 | |
| 442 | 442 | // grab anyone that folded |
| 443 | 443 | $this->betStacks() |
| 444 | - ->filter(function (Chips $chips, $playerName) { |
|
| 444 | + ->filter(function(Chips $chips, $playerName) { |
|
| 445 | 445 | $foldedPlayer = $this->foldedPlayers()->findByName($playerName); |
| 446 | 446 | if ($foldedPlayer && $chips->amount() > 0) { |
| 447 | 447 | return true; |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | |
| 450 | 450 | return false; |
| 451 | 451 | }) |
| 452 | - ->each(function (Chips $chips, $playerName) use ($orderedBetStacks) { |
|
| 452 | + ->each(function(Chips $chips, $playerName) use ($orderedBetStacks) { |
|
| 453 | 453 | $player = $this->players()->findByName($playerName); |
| 454 | 454 | |
| 455 | 455 | $stackChips = Chips::fromAmount($chips->amount()); |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | $orderedBetStacks->put($playerName, Chips::fromAmount($chips->amount())); |
| 460 | 460 | }); |
| 461 | 461 | } else { |
| 462 | - $this->betStacks()->each(function (Chips $chips, $playerName) { |
|
| 462 | + $this->betStacks()->each(function(Chips $chips, $playerName) { |
|
| 463 | 463 | $this->currentPot()->addChips($chips, $this->players()->findByName($playerName)); |
| 464 | 464 | }); |
| 465 | 465 | } |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | */ |
| 632 | 632 | private function highestBet(): Chips |
| 633 | 633 | { |
| 634 | - return Chips::fromAmount($this->betStacks()->max(function (Chips $chips) { |
|
| 634 | + return Chips::fromAmount($this->betStacks()->max(function(Chips $chips) { |
|
| 635 | 635 | return $chips->amount(); |
| 636 | 636 | }) ?? 0); |
| 637 | 637 | } |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | */ |
| 659 | 659 | private function resetBetStacks() |
| 660 | 660 | { |
| 661 | - $this->players()->each(function (PlayerContract $player) { |
|
| 661 | + $this->players()->each(function(PlayerContract $player) { |
|
| 662 | 662 | $this->betStacks->put($player->name(), Chips::zero()); |
| 663 | 663 | }); |
| 664 | 664 | } |
@@ -74,22 +74,22 @@ discard block |
||
| 74 | 74 | { |
| 75 | 75 | $playerHands = $playerHands |
| 76 | 76 | // evaluate hands |
| 77 | - ->map(function (Hand $hand) use ($board) { |
|
| 77 | + ->map(function(Hand $hand) use ($board) { |
|
| 78 | 78 | return static::evaluate($board, $hand); |
| 79 | 79 | }) |
| 80 | 80 | |
| 81 | 81 | // sort the hands by their hand rank |
| 82 | - ->sortByDesc(function (SevenCardResult $result) { |
|
| 82 | + ->sortByDesc(function(SevenCardResult $result) { |
|
| 83 | 83 | return [$result->rank(), $result->value()]; |
| 84 | 84 | }) |
| 85 | 85 | |
| 86 | 86 | // group by the hand rank |
| 87 | - ->groupBy(function (SevenCardResult $result) { |
|
| 87 | + ->groupBy(function(SevenCardResult $result) { |
|
| 88 | 88 | return $result->rank(); |
| 89 | 89 | }) |
| 90 | 90 | |
| 91 | 91 | // sort the collection by the count |
| 92 | - ->sortByDesc(function (Collection $collection) { |
|
| 92 | + ->sortByDesc(function(Collection $collection) { |
|
| 93 | 93 | return $collection->count(); |
| 94 | 94 | }) |
| 95 | 95 | ; |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | // if all hands in the first collection are equal |
| 98 | 98 | $handsAreEqual = $playerHands |
| 99 | 99 | ->first() |
| 100 | - ->groupBy(function (SevenCardResult $result) { |
|
| 100 | + ->groupBy(function(SevenCardResult $result) { |
|
| 101 | 101 | return array_sum($result->value()); |
| 102 | 102 | }) |
| 103 | 103 | ; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | // make sure that TJQKA exist in hand |
| 123 | 123 | $royalFlushHand = $cards |
| 124 | 124 | ->switchAceValue() |
| 125 | - ->filter(function (Card $card) { |
|
| 125 | + ->filter(function(Card $card) { |
|
| 126 | 126 | return $card->isFaceCard() || $card->value() === 10; |
| 127 | 127 | }); |
| 128 | 128 | |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | { |
| 201 | 201 | $groupedBySuit = $cards |
| 202 | 202 | ->switchAceValue() |
| 203 | - ->groupBy(function (Card $card) { |
|
| 203 | + ->groupBy(function(Card $card) { |
|
| 204 | 204 | return $card->suit()->name(); |
| 205 | 205 | }) |
| 206 | - ->sortByDesc(function ($group) { |
|
| 206 | + ->sortByDesc(function($group) { |
|
| 207 | 207 | return count($group); |
| 208 | 208 | }); |
| 209 | 209 | if ($groupedBySuit->first()->count() < 5) { |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | return false; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - $uniqueCards = $cards->map(function (Card $card) { |
|
| 371 | + $uniqueCards = $cards->map(function(Card $card) { |
|
| 372 | 372 | return $card->value(); |
| 373 | 373 | })->unique(); |
| 374 | 374 | if ($cards->count() !== $uniqueCards->count()) { |
@@ -394,13 +394,13 @@ discard block |
||
| 394 | 394 | private static function nNumberOfCardsInSet(CardCollection $cards, int $numberOfCardsOfType) |
| 395 | 395 | { |
| 396 | 396 | $judgedHand = $cards |
| 397 | - ->groupBy(function (Card $card) { |
|
| 397 | + ->groupBy(function(Card $card) { |
|
| 398 | 398 | return $card->value(); |
| 399 | 399 | }) |
| 400 | - ->filter(function (CardCollection $group) use ($numberOfCardsOfType) { |
|
| 400 | + ->filter(function(CardCollection $group) use ($numberOfCardsOfType) { |
|
| 401 | 401 | return $group->count() === $numberOfCardsOfType; |
| 402 | 402 | }) |
| 403 | - ->sortBy(function (CardCollection $group) { |
|
| 403 | + ->sortBy(function(CardCollection $group) { |
|
| 404 | 404 | return $group->count(); |
| 405 | 405 | }) |
| 406 | 406 | ->values() |