From 4ce8107d010489fd13aa4794723bfbff7391b1e3 Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Thu, 29 Feb 2024 14:24:49 +0100 Subject: [PATCH 1/2] Add State of Tic-Tac-Toe Exercise --- config.json | 8 + .../.docs/instructions.md | 101 +++++ .../state-of-tic-tac-toe/.meta/config.json | 19 + .../state-of-tic-tac-toe/.meta/example.php | 65 +++ .../state-of-tic-tac-toe/.meta/tests.toml | 101 +++++ .../state-of-tic-tac-toe/StateOfTicTacToe.php | 33 ++ .../StateOfTicTacToeTest.php | 381 ++++++++++++++++++ 7 files changed, 708 insertions(+) create mode 100644 exercises/practice/state-of-tic-tac-toe/.docs/instructions.md create mode 100644 exercises/practice/state-of-tic-tac-toe/.meta/config.json create mode 100644 exercises/practice/state-of-tic-tac-toe/.meta/example.php create mode 100644 exercises/practice/state-of-tic-tac-toe/.meta/tests.toml create mode 100644 exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.php create mode 100644 exercises/practice/state-of-tic-tac-toe/StateOfTicTacToeTest.php diff --git a/config.json b/config.json index 5c32a837..648d32df 100644 --- a/config.json +++ b/config.json @@ -1244,6 +1244,14 @@ "prerequisites": [], "difficulty": 6 }, + { + "slug": "state-of-tic-tac-toe", + "name": "State of Tic-Tac-Toe", + "uuid": "64ea517d-88ec-46db-b723-004681255580", + "practices": [], + "prerequisites": [], + "difficulty": 5 + }, { "slug": "food-chain", "name": "Food Chain", diff --git a/exercises/practice/state-of-tic-tac-toe/.docs/instructions.md b/exercises/practice/state-of-tic-tac-toe/.docs/instructions.md new file mode 100644 index 00000000..f525d358 --- /dev/null +++ b/exercises/practice/state-of-tic-tac-toe/.docs/instructions.md @@ -0,0 +1,101 @@ +# Instructions + +In this exercise, you're going to implement a program that determines the state of a [tic-tac-toe][] game. +(_You may also know the game as "noughts and crosses" or "Xs and Os"._) + +The games is played on a 3×3 grid. +Players take turns to place `X`s and `O`s on the grid. +The game ends when one player has won by placing three of marks in a row, column, or along a diagonal of the grid, or when the entire grid is filled up. + +In this exercise, we will assume that `X` starts. + +It's your job to determine which state a given game is in. + +There are 3 potential game states: + +- The game is **ongoing**. +- The game ended in a **draw**. +- The game ended in a **win**. + +If the given board is invalid, throw an appropriate error. + +If a board meets the following conditions, it is invalid: + +- The given board cannot be reached when turns are taken in the correct order (remember that `X` starts). +- The game was played after it already ended. + +## Examples + +### Ongoing game + +```text + | | + X | | +___|___|___ + | | + | X | O +___|___|___ + | | + O | X | + | | +``` + +### Draw + +```text + | | + X | O | X +___|___|___ + | | + X | X | O +___|___|___ + | | + O | X | O + | | +``` + +### Win + +```text + | | + X | X | X +___|___|___ + | | + | O | O +___|___|___ + | | + | | + | | +``` + +### Invalid + +#### Wrong turn order + +```text + | | + O | O | X +___|___|___ + | | + | | +___|___|___ + | | + | | + | | +``` + +#### Continued playing after win + +```text + | | + X | X | X +___|___|___ + | | + O | O | O +___|___|___ + | | + | | + | | +``` + +[tic-tac-toe]: https://en.wikipedia.org/wiki/Tic-tac-toe diff --git a/exercises/practice/state-of-tic-tac-toe/.meta/config.json b/exercises/practice/state-of-tic-tac-toe/.meta/config.json new file mode 100644 index 00000000..7b0e3c6a --- /dev/null +++ b/exercises/practice/state-of-tic-tac-toe/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "tomasnorre" + ], + "files": { + "solution": [ + "StateOfTicTacToe.php" + ], + "test": [ + "StateOfTicTacToeTest.php" + ], + "example": [ + ".meta/example.php" + ] + }, + "blurb": "Determine the game state of a match of Tic-Tac-Toe.", + "source": "Created by Sascha Mann for the Julia track of the Exercism Research Experiment.", + "source_url": "https://github.com/exercism/research_experiment_1/tree/julia-dev/exercises/julia-1-a" +} diff --git a/exercises/practice/state-of-tic-tac-toe/.meta/example.php b/exercises/practice/state-of-tic-tac-toe/.meta/example.php new file mode 100644 index 00000000..7d9a0631 --- /dev/null +++ b/exercises/practice/state-of-tic-tac-toe/.meta/example.php @@ -0,0 +1,65 @@ + Finished game where X won via left column victory" + +[96c30df5-ae23-4cf6-bf09-5ef056dddea1] +description = "Won games -> Finished game where X won via middle column victory" + +[0d7a4b0a-2afd-4a75-8389-5fb88ab05eda] +description = "Won games -> Finished game where X won via right column victory" + +[bd1007c0-ec5d-4c60-bb9f-1a4f22177d51] +description = "Won games -> Finished game where O won via left column victory" + +[c032f800-5735-4354-b1b9-46f14d4ee955] +description = "Won games -> Finished game where O won via middle column victory" + +[662c8902-c94a-4c4c-9d9c-e8ca513db2b4] +description = "Won games -> Finished game where O won via right column victory" + +[2d62121f-7e3a-44a0-9032-0d73e3494941] +description = "Won games -> Finished game where X won via top row victory" + +[108a5e82-cc61-409f-aece-d7a18c1beceb] +description = "Won games -> Finished game where X won via middle row victory" +include = false + +[346527db-4db9-4a96-b262-d7023dc022b0] +description = "Won games -> Finished game where X won via middle row victory" +reimplements = "108a5e82-cc61-409f-aece-d7a18c1beceb" + +[a013c583-75f8-4ab2-8d68-57688ff04574] +description = "Won games -> Finished game where X won via bottom row victory" + +[2c08e7d7-7d00-487f-9442-e7398c8f1727] +description = "Won games -> Finished game where O won via top row victory" + +[bb1d6c62-3e3f-4d1a-9766-f8803c8ed70f] +description = "Won games -> Finished game where O won via middle row victory" + +[6ef641e9-12ec-44f5-a21c-660ea93907af] +description = "Won games -> Finished game where O won via bottom row victory" + +[ab145b7b-26a7-426c-ab71-bf418cd07f81] +description = "Won games -> Finished game where X won via falling diagonal victory" + +[7450caab-08f5-4f03-a74b-99b98c4b7a4b] +description = "Won games -> Finished game where X won via rising diagonal victory" + +[c2a652ee-2f93-48aa-a710-a70cd2edce61] +description = "Won games -> Finished game where O won via falling diagonal victory" + +[5b20ceea-494d-4f0c-a986-b99efc163bcf] +description = "Won games -> Finished game where O won via rising diagonal victory" + +[035a49b9-dc35-47d3-9d7c-de197161b9d4] +description = "Won games -> Finished game where X won via a row and a column victory" + +[e5dfdeb0-d2bf-4b5a-b307-e673f69d4a53] +description = "Won games -> Finished game where X won via two diagonal victories" + +[b42ed767-194c-4364-b36e-efbfb3de8788] +description = "Drawn games -> Draw" + +[227a76b2-0fef-4e16-a4bd-8f9d7e4c3b13] +description = "Drawn games -> Another draw" + +[4d93f15c-0c40-43d6-b966-418b040012a9] +description = "Ongoing games -> Ongoing game: one move in" + +[c407ae32-4c44-4989-b124-2890cf531f19] +description = "Ongoing games -> Ongoing game: two moves in" + +[199b7a8d-e2b6-4526-a85e-78b416e7a8a9] +description = "Ongoing games -> Ongoing game: five moves in" + +[1670145b-1e3d-4269-a7eb-53cd327b302e] +description = "Invalid boards -> Invalid board: X went twice" + +[47c048e8-b404-4bcf-9e51-8acbb3253f3b] +description = "Invalid boards -> Invalid board: O started" + +[b1dc8b13-46c4-47db-a96d-aa90eedc4e8d] +description = "Invalid boards -> Invalid board" +include = false + +[6c1920f2-ab5c-4648-a0c9-997414dda5eb] +description = "Invalid boards -> Invalid board: X won and O kept playing" +reimplements = "b1dc8b13-46c4-47db-a96d-aa90eedc4e8d" + +[4801cda2-f5b7-4c36-8317-3cdd167ac22c] +description = "Invalid boards -> Invalid board: players kept playing after a win" diff --git a/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.php b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.php new file mode 100644 index 00000000..0cdfe44c --- /dev/null +++ b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.php @@ -0,0 +1,33 @@ +. + * + * To disable strict typing, comment out the directive below. + */ + +declare(strict_types=1); + +class StateOfTicTacToe +{ + public static function gameState(array $board): string + { + throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__)); + } +} diff --git a/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToeTest.php b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToeTest.php new file mode 100644 index 00000000..5297a398 --- /dev/null +++ b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToeTest.php @@ -0,0 +1,381 @@ +stateOfTicTacToe = new StateOfTicTacToe(); + } + + /** + * uuid: fe8e9fa9-37af-4d7e-aa24-2f4b8517161a + */ + public function testWonGamesFinishedGameWhereXWonViaLeftColumnVictory(): void + { + $board = [ + "XOO", + "X ", + "X " + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 96c30df5-ae23-4cf6-bf09-5ef056dddea1 + */ + public function testWonGameFinishedGameWhereXWonViaMiddleColumnVictory(): void + { + $board = [ + "OXO", + " X ", + " X " + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 0d7a4b0a-2afd-4a75-8389-5fb88ab05eda + */ + public function testWonGameFinishedGameWhereXWonViaRightColumnVictory(): void + { + $board = [ + "OOX", + " X", + " X" + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: bd1007c0-ec5d-4c60-bb9f-1a4f22177d51 + */ + public function testWonGamesFinishedGameWhereOWonViaLeftColumnVictory(): void + { + $board = [ + "OXX", + "OX ", + "O " + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: c032f800-5735-4354-b1b9-46f14d4ee955 + */ + public function testWonGameFinishedGameWhereOWonViaMiddleColumnVictory(): void + { + $board = [ + "XOX", + " OX", + " O " + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 662c8902-c94a-4c4c-9d9c-e8ca513db2b4 + */ + public function testWonGameFinishedGameWhereOWonViaRightColumnVictory(): void + { + $board = [ + "XXO", + " XO", + " O" + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 2d62121f-7e3a-44a0-9032-0d73e3494941 + */ + public function testWonGameFinishedWhereXWonViaTopRowVictory(): void + { + $board = [ + "XXX", + "XOO", + "O " + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 346527db-4db9-4a96-b262-d7023dc022b0 + */ + public function testWonGameFinishedWhereXWonViaMiddleRowVictory(): void + { + $board = [ + "O ", + "XXX", + " O " + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: a013c583-75f8-4ab2-8d68-57688ff04574 + */ + public function testWonGameFinishedWhereXWonViaBottomRowVictory(): void + { + $board = [ + " OO", + "O X", + "XXX" + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 2c08e7d7-7d00-487f-9442-e7398c8f1727 + */ + public function testWonGameFinishedWhereOWonViaTopRowVictory(): void + { + $board = [ + "OOO", + "XXO", + "XX " + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: bb1d6c62-3e3f-4d1a-9766-f8803c8ed70f + */ + public function testWonGameFinishedWhereOWonViaMiddleRowVictory(): void + { + $board = [ + "XX ", + "OOO", + "X " + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 6ef641e9-12ec-44f5-a21c-660ea93907af + */ + public function testWonGameFinishedWhereOWonViaBottomRowVictory(): void + { + $board = [ + "XOX", + " XX", + "OOO" + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: ab145b7b-26a7-426c-ab71-bf418cd07f81 + */ + public function testWonGameFinishedWhereXWonViaFallingDiagonalVictory(): void + { + $board = [ + "XOO", + " X ", + " X" + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 7450caab-08f5-4f03-a74b-99b98c4b7a4b + */ + public function testWonGameFinishedWhereXWonViaRisingDiagonalVictory(): void + { + $board = [ + "O X", + "OX ", + "X " + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: c2a652ee-2f93-48aa-a710-a70cd2edce61 + */ + public function testWonGameFinishedWhereOWonViaFallingDiagonalVictory(): void + { + $board = [ + "OXX", + "OOX", + "X O" + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 5b20ceea-494d-4f0c-a986-b99efc163bcf + */ + public function testWonGameFinishedWhereOWonViaRisingDiagonalVictory(): void + { + $board = [ + " O", + " OX", + "OXX" + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 035a49b9-dc35-47d3-9d7c-de197161b9d4 + */ + public function testWonGameFinishedGameWhereXWonViaARowAndAColumnVictory(): void + { + $board = [ + "XXX", + "XOO", + "XOO" + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: e5dfdeb0-d2bf-4b5a-b307-e673f69d4a53 + */ + public function testWonGameFinishedGameWhereXWonViaTwoDiagonalVictories(): void + { + $board = [ + "XOX", + "OXO", + "XOX" + ]; + $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: b42ed767-194c-4364-b36e-efbfb3de8788 + */ + public function testDrawGame(): void + { + $board = [ + "XOX", + "XXO", + "OXO" + ]; + $this->assertEquals('draw', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 227a76b2-0fef-4e16-a4bd-8f9d7e4c3b13 + */ + public function testAnotherDrawGame(): void + { + $board = [ + "XXO", + "OXX", + "XOO" + ]; + $this->assertEquals('draw', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 4d93f15c-0c40-43d6-b966-418b040012a9 + */ + public function testOngoingGameOneMoveIn(): void + { + $board = [ + " ", + "X ", + " " + ]; + $this->assertEquals('ongoing', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: c407ae32-4c44-4989-b124-2890cf531f19 + */ + public function testOngoingGameTwoMovesIn(): void + { + $board = [ + "O ", + " X ", + " " + ]; + $this->assertEquals('ongoing', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 199b7a8d-e2b6-4526-a85e-78b416e7a8a9 + */ + public function testOngoingGameFiveMovesIn(): void + { + $board = [ + "X ", + " XO", + "OX " + ]; + $this->assertEquals('ongoing', $this->stateOfTicTacToe->gameState($board)); + } + + /** + * uuid: 1670145b-1e3d-4269-a7eb-53cd327b302e + */ + public function testInvalidBoardsXWentTwice(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage("Wrong turn order: X went twice"); + + $board = [ + "XX ", + " ", + " " + ]; + $this->stateOfTicTacToe->gameState($board); + } + + /** + * uuid: 47c048e8-b404-4bcf-9e51-8acbb3253f3b + */ + public function testInvalidBoardOStarted(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage("Wrong turn order: O started"); + + $board = [ + "OOX", + " ", + " " + ]; + $this->stateOfTicTacToe->gameState($board); + } + + /** + * uuid: 6c1920f2-ab5c-4648-a0c9-997414dda5eb + */ + public function testInvalidBoard(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage("Impossible board: game should have ended after the game was won"); + + $board = [ + "XXX", + "OOO", + " " + ]; + $this->stateOfTicTacToe->gameState($board); + } + + /** + * uuid: 4801cda2-f5b7-4c36-8317-3cdd167ac22c + */ + public function testInvalidBoardPlayersKeptPlayingAfterAWin(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage("Impossible board: game should have ended after the game was won"); + + $board = [ + "XXX", + "OOO", + "XOX" + ]; + $this->stateOfTicTacToe->gameState($board); + } +} From 0f5c86dd9cf18b70e9a9a414468c4d850b57d87a Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Fri, 1 Mar 2024 09:51:11 +0100 Subject: [PATCH 2/2] Update to enum and remove static --- .../state-of-tic-tac-toe/.meta/example.php | 31 +++++++------ .../state-of-tic-tac-toe/StateOfTicTacToe.php | 9 +++- .../StateOfTicTacToeTest.php | 46 +++++++++---------- 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/exercises/practice/state-of-tic-tac-toe/.meta/example.php b/exercises/practice/state-of-tic-tac-toe/.meta/example.php index 7d9a0631..7f6f4122 100644 --- a/exercises/practice/state-of-tic-tac-toe/.meta/example.php +++ b/exercises/practice/state-of-tic-tac-toe/.meta/example.php @@ -2,16 +2,19 @@ declare(strict_types=1); -class StateOfTicTacToe +enum State { - const WIN = "win"; - const ONGOING = "ongoing"; - const DRAW = "draw"; + case Win; + case Ongoing; + case Draw; +} - public static function gameState(array $board): string +class StateOfTicTacToe +{ + public function gameState(array $board): State { - $xCount = self::countPlayer($board, 'X'); - $oCount = self::countPlayer($board, 'O'); + $xCount = $this->countPlayer($board, 'X'); + $oCount = $this->countPlayer($board, 'O'); if ($xCount < $oCount) { throw new \RuntimeException("Wrong turn order: O started"); @@ -21,25 +24,25 @@ public static function gameState(array $board): string throw new \RuntimeException("Wrong turn order: X went twice"); } - $xWon = self::hasWon($board, 'X'); - $oWon = self::hasWon($board, 'O'); + $xWon = $this->hasWon($board, 'X'); + $oWon = $this->hasWon($board, 'O'); if ($xWon && $oWon) { throw new \RuntimeException("Impossible board: game should have ended after the game was won"); } if ($xWon || $oWon) { - return self::WIN; + return State::Win; } if ($xCount + $oCount === 9) { - return self::DRAW; + return State::Draw; } - return self::ONGOING; + return State::Ongoing; } - private static function countPlayer(array $board, string $player): int + private function countPlayer(array $board, string $player): int { $count = 0; foreach ($board as $row) { @@ -52,7 +55,7 @@ private static function countPlayer(array $board, string $player): int return $count; } - private static function hasWon(array $board, string $player): bool + private function hasWon(array $board, string $player): bool { for ($i = 0; $i < 3; $i++) { if (($board[$i][0] === $player && $board[$i][1] === $player && $board[$i][2] === $player) || ($board[0][$i] === $player && $board[1][$i] === $player && $board[2][$i] === $player)) { diff --git a/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.php b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.php index 0cdfe44c..821493d8 100644 --- a/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.php +++ b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.php @@ -24,9 +24,16 @@ declare(strict_types=1); +enum State +{ + case Win; + case Ongoing; + case Draw; +} + class StateOfTicTacToe { - public static function gameState(array $board): string + public function gameState(array $board): State { throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__)); } diff --git a/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToeTest.php b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToeTest.php index 5297a398..718a166a 100644 --- a/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToeTest.php +++ b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToeTest.php @@ -26,7 +26,7 @@ public function testWonGamesFinishedGameWhereXWonViaLeftColumnVictory(): void "X ", "X " ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -39,7 +39,7 @@ public function testWonGameFinishedGameWhereXWonViaMiddleColumnVictory(): void " X ", " X " ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -52,7 +52,7 @@ public function testWonGameFinishedGameWhereXWonViaRightColumnVictory(): void " X", " X" ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -65,7 +65,7 @@ public function testWonGamesFinishedGameWhereOWonViaLeftColumnVictory(): void "OX ", "O " ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -78,7 +78,7 @@ public function testWonGameFinishedGameWhereOWonViaMiddleColumnVictory(): void " OX", " O " ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -91,7 +91,7 @@ public function testWonGameFinishedGameWhereOWonViaRightColumnVictory(): void " XO", " O" ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -104,7 +104,7 @@ public function testWonGameFinishedWhereXWonViaTopRowVictory(): void "XOO", "O " ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -117,7 +117,7 @@ public function testWonGameFinishedWhereXWonViaMiddleRowVictory(): void "XXX", " O " ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -130,7 +130,7 @@ public function testWonGameFinishedWhereXWonViaBottomRowVictory(): void "O X", "XXX" ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -143,7 +143,7 @@ public function testWonGameFinishedWhereOWonViaTopRowVictory(): void "XXO", "XX " ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -156,7 +156,7 @@ public function testWonGameFinishedWhereOWonViaMiddleRowVictory(): void "OOO", "X " ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -169,7 +169,7 @@ public function testWonGameFinishedWhereOWonViaBottomRowVictory(): void " XX", "OOO" ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -182,7 +182,7 @@ public function testWonGameFinishedWhereXWonViaFallingDiagonalVictory(): void " X ", " X" ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -195,7 +195,7 @@ public function testWonGameFinishedWhereXWonViaRisingDiagonalVictory(): void "OX ", "X " ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -208,7 +208,7 @@ public function testWonGameFinishedWhereOWonViaFallingDiagonalVictory(): void "OOX", "X O" ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -221,7 +221,7 @@ public function testWonGameFinishedWhereOWonViaRisingDiagonalVictory(): void " OX", "OXX" ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -234,7 +234,7 @@ public function testWonGameFinishedGameWhereXWonViaARowAndAColumnVictory(): void "XOO", "XOO" ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -247,7 +247,7 @@ public function testWonGameFinishedGameWhereXWonViaTwoDiagonalVictories(): void "OXO", "XOX" ]; - $this->assertEquals('win', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Win, $this->stateOfTicTacToe->gameState($board)); } /** @@ -260,7 +260,7 @@ public function testDrawGame(): void "XXO", "OXO" ]; - $this->assertEquals('draw', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Draw, $this->stateOfTicTacToe->gameState($board)); } /** @@ -273,7 +273,7 @@ public function testAnotherDrawGame(): void "OXX", "XOO" ]; - $this->assertEquals('draw', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Draw, $this->stateOfTicTacToe->gameState($board)); } /** @@ -286,7 +286,7 @@ public function testOngoingGameOneMoveIn(): void "X ", " " ]; - $this->assertEquals('ongoing', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Ongoing, $this->stateOfTicTacToe->gameState($board)); } /** @@ -299,7 +299,7 @@ public function testOngoingGameTwoMovesIn(): void " X ", " " ]; - $this->assertEquals('ongoing', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Ongoing, $this->stateOfTicTacToe->gameState($board)); } /** @@ -312,7 +312,7 @@ public function testOngoingGameFiveMovesIn(): void " XO", "OX " ]; - $this->assertEquals('ongoing', $this->stateOfTicTacToe->gameState($board)); + $this->assertEquals(State::Ongoing, $this->stateOfTicTacToe->gameState($board)); } /**