Commit 69331b49 authored by Adrian Kosmaczewski's avatar Adrian Kosmaczewski

Updated PHP version

parent 0888dd47
composer.phar
vendor
# Created by https://www.gitignore.io/api/phpstorm
# Edit at https://www.gitignore.io/?templates=phpstorm
# Created by https://www.toptal.com/developers/gitignore/api/phpunit,phpstorm+all
# Edit at https://www.toptal.com/developers/gitignore?templates=phpunit,phpstorm+all
### PhpStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
### PhpStorm+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
......@@ -33,6 +35,9 @@
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
......@@ -72,41 +77,21 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### PhpStorm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
.idea/**/sonarlint/
# SonarQube Plugin
.idea/**/sonarIssues.xml
# Markdown Navigator plugin
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator/
# End of https://www.gitignore.io/api/phpstorm
### PhpStorm+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
# Created by https://www.gitignore.io/api/composer
# Edit at https://www.gitignore.io/?templates=composer
.idea/
### Composer ###
composer.phar
/vendor/
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
# End of https://www.gitignore.io/api/composer
*.iml
modules.xml
.idea/misc.xml
*.ipr
# Created by https://www.gitignore.io/api/phpunit
# Edit at https://www.gitignore.io/?templates=phpunit
# Sonarlint plugin
.idea/sonarlint
### PHPUnit ###
# Covers PHPUnit
......@@ -117,8 +102,9 @@ composer.phar
# PHPUnit
/app/phpunit.xml
/phpunit.xml
# Build data
/build/
# End of https://www.gitignore.io/api/phpunit
# End of https://www.toptal.com/developers/gitignore/api/phpunit,phpstorm+all
......@@ -34,7 +34,7 @@
<path value="$PROJECT_DIR$/vendor/phpunit/php-code-coverage" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.2" />
<component name="PhpProjectSharedConfiguration" php_language_level="7.4" />
<component name="PhpUnit">
<phpunit_settings>
<PhpUnitSettings custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" />
......
......@@ -8,7 +8,7 @@ abstract class Cell
const Dead = 0;
const Alive = 1;
static function tableDescription(int $cell): string
static function cellToString(int $cell): string
{
if ($cell == Cell::Alive) {
return " x |";
......
......@@ -14,6 +14,14 @@ class Coord
$this->y = $y;
}
public static function fromString(string $str): Coord
{
$parts = explode(":", $str);
$a = intval($parts[0]);
$b = intval($parts[1]);
return new Coord($a, $b);
}
public function getX(): int
{
return $this->x;
......@@ -28,12 +36,4 @@ class Coord
{
return sprintf("%d:%d", $this->x, $this->y);
}
public static function createFromString(string $str): Coord
{
$parts = explode(":", $str);
$a = intval($parts[0]);
$b = intval($parts[1]);
return new Coord($a, $b);
}
}
......@@ -25,61 +25,61 @@ class World
}
}
public static function blinker(Coord $coord): array
public static function blinker(Coord $origin): array
{
$alive = array(
new Coord($coord->getX(), $coord->getY()),
new Coord($coord->getX() + 1, $coord->getY()),
new Coord($coord->getX() + 2, $coord->getY())
new Coord($origin->getX(), $origin->getY()),
new Coord($origin->getX() + 1, $origin->getY()),
new Coord($origin->getX() + 2, $origin->getY())
);
return $alive;
}
public static function beacon(Coord $coord): array
public static function beacon(Coord $origin): array
{
$alive = array(
new Coord($coord->getX(), $coord->getY()),
new Coord($coord->getX() + 1, $coord->getY()),
new Coord($coord->getX(), $coord->getY() + 1),
new Coord($coord->getX() + 1, $coord->getY() + 1),
new Coord($coord->getX() + 2, $coord->getY() + 2),
new Coord($coord->getX() + 3, $coord->getY() + 2),
new Coord($coord->getX() + 2, $coord->getY() + 3),
new Coord($coord->getX() + 3, $coord->getY() + 3)
new Coord($origin->getX(), $origin->getY()),
new Coord($origin->getX() + 1, $origin->getY()),
new Coord($origin->getX(), $origin->getY() + 1),
new Coord($origin->getX() + 1, $origin->getY() + 1),
new Coord($origin->getX() + 2, $origin->getY() + 2),
new Coord($origin->getX() + 3, $origin->getY() + 2),
new Coord($origin->getX() + 2, $origin->getY() + 3),
new Coord($origin->getX() + 3, $origin->getY() + 3)
);
return $alive;
}
public static function glider(Coord $coord): array
public static function glider(Coord $origin): array
{
$alive = array(
new Coord($coord->getX() + 2, $coord->getY() + 2),
new Coord($coord->getX() + 1, $coord->getY() + 2),
new Coord($coord->getX(), $coord->getY() + 2),
new Coord($coord->getX() + 2, $coord->getY() + 1),
new Coord($coord->getX() + 1, $coord->getY())
new Coord($origin->getX() + 2, $origin->getY() + 2),
new Coord($origin->getX() + 1, $origin->getY() + 2),
new Coord($origin->getX(), $origin->getY() + 2),
new Coord($origin->getX() + 2, $origin->getY() + 1),
new Coord($origin->getX() + 1, $origin->getY())
);
return $alive;
}
public static function block(Coord $coord): array
public static function block(Coord $origin): array
{
$alive = array(
new Coord($coord->getX(), $coord->getY()),
new Coord($coord->getX() + 1, $coord->getY()),
new Coord($coord->getX(), $coord->getY() + 1),
new Coord($coord->getX() + 1, $coord->getY() + 1)
new Coord($origin->getX(), $origin->getY()),
new Coord($origin->getX() + 1, $origin->getY()),
new Coord($origin->getX(), $origin->getY() + 1),
new Coord($origin->getX() + 1, $origin->getY() + 1)
);
return $alive;
}
public static function tub(Coord $coord): array
public static function tub(Coord $origin): array
{
$alive = array(
new Coord($coord->getX() + 1, $coord->getY()),
new Coord($coord->getX(), $coord->getY() + 1),
new Coord($coord->getX() + 2, $coord->getY() + 1),
new Coord($coord->getX() + 1, $coord->getY() + 2)
new Coord($origin->getX() + 1, $origin->getY()),
new Coord($origin->getX(), $origin->getY() + 1),
new Coord($origin->getX() + 2, $origin->getY() + 1),
new Coord($origin->getX() + 1, $origin->getY() + 2)
);
return $alive;
}
......@@ -89,7 +89,7 @@ class World
$alive = array();
$range = range(-1, 1);
foreach ($this->cells as $str => $cell) {
$coord = Coord::createFromString($str);
$coord = Coord::fromString($str);
$count = 0;
foreach ($range as $a) {
......@@ -106,13 +106,13 @@ class World
switch ($cell) {
case Cell::Alive:
if ($count == 2 || $count == 3) {
array_push($alive, Coord::createFromString($str));
array_push($alive, Coord::fromString($str));
}
break;
case Cell::Dead:
if ($count == 3) {
array_push($alive, Coord::createFromString($str));
array_push($alive, Coord::fromString($str));
}
break;
}
......@@ -143,7 +143,7 @@ class World
for ($b = 0; $b < $this->size; ++$b) {
$coord = new Coord($b, $a);
$cell = $this->cells[strval($coord)];
$str .= Cell::tableDescription($cell);
$str .= Cell::cellToString($cell);
}
$str .= "\n";
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment