|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cysha\Casino\Holdem\Game\Parameters; |
|
4
|
|
|
|
|
5
|
|
|
use Cysha\Casino\Game\Chips; |
|
6
|
|
|
use Cysha\Casino\Game\Contracts\GameParameters; |
|
7
|
|
|
use Cysha\Casino\Holdem\Exceptions\GameParametersException; |
|
8
|
|
|
use Ramsey\Uuid\Uuid; |
|
9
|
|
|
|
|
10
|
|
|
class DefaultParameters implements GameParameters |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Uuid |
|
14
|
|
|
*/ |
|
15
|
|
|
private $gameId; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Chips |
|
19
|
|
|
*/ |
|
20
|
|
|
private $smallBlind; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var Chips |
|
24
|
|
|
*/ |
|
25
|
|
|
private $bigBlind; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var int |
|
29
|
|
|
*/ |
|
30
|
|
|
private $tableSize = 9; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct(Uuid $gameId, Chips $bigBlind, Chips $smallBlind = null, int $tableSize = 9) |
|
33
|
|
|
{ |
|
34
|
|
|
if ($tableSize < 2) { |
|
35
|
|
|
throw GameParametersException::invalidArgument(sprintf('Invalid tableSize given, minimum of 2 expected, received %d', $tableSize)); |
|
36
|
|
|
} |
|
37
|
|
|
if ($bigBlind < $smallBlind) { |
|
38
|
|
|
throw GameParametersException::invalidArgument(sprintf('Invalid Blinds given, bigBlind should be >= smallBlind, received %d/%d ', $smallBlind->amount(), $bigBlind->amount())); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// if the small blind amount, manages to be zero, switch it to null |
|
42
|
|
|
if ($smallBlind !== null && $smallBlind->amount() === 0) { |
|
43
|
|
|
$smallBlind = null; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$this->gameId = $gameId; |
|
47
|
|
|
$this->bigBlind = $bigBlind; |
|
48
|
|
|
$this->smallBlind = $smallBlind; |
|
49
|
|
|
$this->tableSize = $tableSize; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return Uuid |
|
54
|
|
|
*/ |
|
55
|
|
|
public function gameId(): Uuid |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->gameId; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return Chips |
|
62
|
|
|
*/ |
|
63
|
|
|
public function bigBlind(): Chips |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->bigBlind; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return Chips |
|
70
|
|
|
*/ |
|
71
|
|
|
public function smallBlind(): Chips |
|
72
|
|
|
{ |
|
73
|
|
|
if ($this->smallBlind === null) { |
|
74
|
|
|
$bigBlindAmount = floor($this->bigBlind()->amount() / 2); |
|
75
|
|
|
$this->smallBlind = Chips::fromAmount($bigBlindAmount); |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->smallBlind; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return int |
|
83
|
|
|
*/ |
|
84
|
|
|
public function tableSize(): int |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->tableSize; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..