-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c3d2b0
commit 307ab18
Showing
4 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env php | ||
|
||
<?php | ||
|
||
$autoloadPath1 = __DIR__ . '/../../../autoload.php'; | ||
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php'; | ||
|
||
if (file_exists($autoloadPath1)) { | ||
require_once $autoloadPath1; | ||
} else { | ||
require_once $autoloadPath2; | ||
} | ||
|
||
Brain\Games\Progression\play(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Brain\Games\Progression; | ||
|
||
use function Brain\Engine\gameLogic; | ||
use function cli\line; | ||
use function cli\prompt; | ||
|
||
const DESCRIPTION = 'What number is missing in the progression?'; | ||
const PROGRESSION_LENGTH = 10; | ||
const RANDOM_MIN = 1; | ||
const RANDOM_MAX = 10; | ||
|
||
function generateProgression($start, $step, $progressionLength) | ||
{ | ||
$progression = []; | ||
for ($i = 0; $i < $progressionLength; $i += 1) { | ||
$progression[] = $start + $step * $i; | ||
} | ||
return $progression; | ||
} | ||
|
||
function getRandomNumber() | ||
{ | ||
return rand(RANDOM_MIN, RANDOM_MAX); | ||
} | ||
|
||
function play() | ||
{ | ||
$generateGameData = function () { | ||
$start = getRandomNumber(); | ||
$step = getRandomNumber(); | ||
$progression = generateProgression($start, $step, PROGRESSION_LENGTH); | ||
$progressionWithHiddenElement = array_slice($progression, 0); | ||
$hiddenElementIndex = rand(0, PROGRESSION_LENGTH - 1); | ||
$progressionWithHiddenElement[$hiddenElementIndex] = '..'; | ||
$question = implode(' ', $progressionWithHiddenElement); | ||
$answer = $progression[$hiddenElementIndex]; | ||
|
||
return [$question, "{$answer}"]; | ||
}; | ||
|
||
gameLogic(DESCRIPTION, $generateGameData); | ||
return; | ||
} |