From aab2663d5347ff66bdbc10fc114ddf69a64b8dc3 Mon Sep 17 00:00:00 2001 From: gkdev Date: Mon, 4 Sep 2023 00:53:02 +0300 Subject: [PATCH] feat: implement game progression --- Makefile | 5 +++- bin/brain-progression | 9 ++++++++ src/Games/ProgressionGame.php | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 bin/brain-progression create mode 100644 src/Games/ProgressionGame.php diff --git a/Makefile b/Makefile index 212ec4f..4d5b133 100644 --- a/Makefile +++ b/Makefile @@ -23,4 +23,7 @@ brain-calc: ./bin/brain-calc brain-gcd: - ./bin/brain-gcd \ No newline at end of file + ./bin/brain-gcd + +brain-progression: + ./bin/brain-progression \ No newline at end of file diff --git a/bin/brain-progression b/bin/brain-progression new file mode 100755 index 0000000..1221cc2 --- /dev/null +++ b/bin/brain-progression @@ -0,0 +1,9 @@ +#!/usr/bin/env php + questionHandler(); + + return $module; +}; + +/** + * Returns a question and its expected answer. + * + * - 0: The question (string) + * - 1: The expected answer (string) + * + * @return array{ + * 0: string, + * 1: string + * } + * @throws Exception + */ +function questionHandler(): array +{ + $lengthProgression = 10; + $step = random_int(2, 10); + $shift = random_int(1, 10); + $progression = range($shift, $shift + (($lengthProgression - 1) * $step), $step); + $guessIndex = random_int(0, 8); + $expectedAnswer = $progression[$guessIndex]; + $progression[$guessIndex] = '..'; + $question = implode(' ', $progression); + return [$question, $expectedAnswer]; +}