diff --git a/src/Domain/BasicStrategy.php b/src/Domain/BasicStrategy.php new file mode 100644 index 0000000..6f6658e --- /dev/null +++ b/src/Domain/BasicStrategy.php @@ -0,0 +1,46 @@ +value(); + $dealerValue = $dealerCard->numericValue(); + + if ($hand->isSoft() && $value === 18 && $dealerValue >= 3 && $dealerValue <= 6) { + return Decision::Double; + } + + if ($hand->isSoft() && $value === 17 && $dealerValue >= 3 && $dealerValue <= 6) { + return Decision::Double; + } + + if ($value >= 17) { + return Decision::Stand; + } + + if ($value >= 13 && $value <= 16 && $dealerValue >= 2 && $dealerValue <= 6) { + return Decision::Stand; + } + + if ($value === 12 && $dealerValue >= 4 && $dealerValue <= 6) { + return Decision::Stand; + } + + if ($value === 11 && $dealerValue >= 2 && $dealerValue <= 10) { + return Decision::Double; + } + + if ($value === 10 && $dealerValue >= 2 && $dealerValue <= 9) { + return Decision::Double; + } + + if ($value === 9 && $dealerValue >= 3 && $dealerValue <= 6) { + return Decision::Double; + } + + return Decision::Hit; + } +} \ No newline at end of file diff --git a/src/Domain/Decision.php b/src/Domain/Decision.php new file mode 100644 index 0000000..048bb31 --- /dev/null +++ b/src/Domain/Decision.php @@ -0,0 +1,11 @@ +addCard(new Card('9', 'Hearts')); + $hand->addCard(new Card('7', 'Spades')); + + $dealerCard = new Card('10', 'Diamonds'); + + $this->assertSame(Decision::Hit, $strategy->decide($hand, $dealerCard)); + } + + public function testHard17ShouldStand(): void + { + $strategy = new BasicStrategy(); + + $hand = new Hand(); + $hand->addCard(new Card('King', 'Hearts')); + $hand->addCard(new Card('7', 'Spades')); + + $dealerCard = new Card('6', 'Diamonds'); + + $this->assertSame(Decision::Stand, $strategy->decide($hand, $dealerCard)); + } + public function testHard12AgainstDealer4ShouldStand(): void + { + $strategy = new BasicStrategy(); + + $hand = new Hand(); + $hand->addCard(new Card('7', 'Hearts')); + $hand->addCard(new Card('5', 'Spades')); + + $dealerCard = new Card('4', 'Diamonds'); + + $this->assertSame(Decision::Stand, $strategy->decide($hand, $dealerCard)); + } + + public function testHard13AgainstDealer2ShouldStand(): void + { + $strategy = new BasicStrategy(); + + $hand = new Hand(); + $hand->addCard(new Card('7', 'Hearts')); + $hand->addCard(new Card('6', 'Spades')); + + $dealerCard = new Card('2', 'Diamonds'); + + $this->assertSame(Decision::Stand, $strategy->decide($hand, $dealerCard)); + } + + public function testHard11AgainstDealer6ShouldDouble(): void + { + $strategy = new BasicStrategy(); + + $hand = new Hand(); + $hand->addCard(new Card('7', 'Hearts')); + $hand->addCard(new Card('4', 'Spades')); + + $dealerCard = new Card('6', 'Diamonds'); + + $this->assertSame(Decision::Double, $strategy->decide($hand, $dealerCard)); + } + + public function testHard10AgainstDealer5ShouldDouble(): void + { + $strategy = new BasicStrategy(); + + $hand = new Hand(); + $hand->addCard(new Card('6', 'Hearts')); + $hand->addCard(new Card('4', 'Spades')); + + $dealerCard = new Card('5', 'Diamonds'); + + $this->assertSame(Decision::Double, $strategy->decide($hand, $dealerCard)); + } + + public function testHard9AgainstDealer3ShouldDouble(): void + { + $strategy = new BasicStrategy(); + + $hand = new Hand(); + $hand->addCard(new Card('5', 'Hearts')); + $hand->addCard(new Card('4', 'Spades')); + + $dealerCard = new Card('3', 'Diamonds'); + + $this->assertSame(Decision::Double, $strategy->decide($hand, $dealerCard)); + } + + public function testSoft18AgainstDealer5ShouldDouble(): void + { + $strategy = new BasicStrategy(); + + $hand = new Hand(); + $hand->addCard(new Card('Ace', 'Hearts')); + $hand->addCard(new Card('7', 'Spades')); + + $dealerCard = new Card('5', 'Diamonds'); + + $this->assertSame(Decision::Double, $strategy->decide($hand, $dealerCard)); + } + + public function testSoft18AgainstDealer2ShouldStand(): void + { + $strategy = new BasicStrategy(); + + $hand = new Hand(); + $hand->addCard(new Card('Ace', 'Hearts')); + $hand->addCard(new Card('7', 'Spades')); + + $dealerCard = new Card('2', 'Diamonds'); + + $this->assertSame(Decision::Stand, $strategy->decide($hand, $dealerCard)); + } + + public function testSoft17AgainstDealer4ShouldDouble(): void + { + $strategy = new BasicStrategy(); + + $hand = new Hand(); + $hand->addCard(new Card('Ace', 'Hearts')); + $hand->addCard(new Card('6', 'Spades')); + + $dealerCard = new Card('4', 'Diamonds'); + + $this->assertSame(Decision::Double, $strategy->decide($hand, $dealerCard)); + } + + public function testSoft19ShouldAlwaysStand(): void + { + $strategy = new BasicStrategy(); + + $hand = new Hand(); + $hand->addCard(new Card('Ace', 'Hearts')); + $hand->addCard(new Card('8', 'Spades')); + + $dealerCard = new Card('6', 'Diamonds'); + + $this->assertSame(Decision::Stand, $strategy->decide($hand, $dealerCard)); + } +} \ No newline at end of file