Archived
1
0
Fork 0

Formatting fixes and cleanup.

This commit is contained in:
Henrik Hautakoski 2023-01-31 07:34:02 +01:00
parent a1e14a3e60
commit 51fb71e469
41 changed files with 394 additions and 392 deletions

View file

@ -42,7 +42,7 @@ class GameBoardState
/**
* Set the state of a cell.
*/
public function set(int $pos, bool $pressed = true) : self
public function set(int $pos, bool $pressed = true): self
{
if ($this->hasGameEnded()) {
return $this;
@ -62,7 +62,7 @@ class GameBoardState
/**
* Toggle pressed state of a cell.
*/
public function toggle(int $pos) : self
public function toggle(int $pos): self
{
return $this->set($pos, !$this->isPressed($pos));
}
@ -70,7 +70,7 @@ class GameBoardState
/**
* Check if a cell is pressed or not.
*/
public function isPressed(int $pos) : bool
public function isPressed(int $pos): bool
{
return isset($this->state[$pos]);
}
@ -78,7 +78,7 @@ class GameBoardState
/**
* Check if a cell is part of a winning row/column.
*/
public function isWin(int $pos) : bool
public function isWin(int $pos): bool
{
return isset($this->state[$pos]) && $this->state[$pos] == self::STATE_WIN;
}
@ -86,7 +86,7 @@ class GameBoardState
/**
* Get the sate of the cells.
*/
public function getState() : array
public function getState(): array
{
return $this->state;
}
@ -94,7 +94,7 @@ class GameBoardState
/**
* Get the size of the board.
*/
public function getSize() : int
public function getSize(): int
{
return $this->width * $this->height;
}
@ -102,7 +102,7 @@ class GameBoardState
/**
* Clear the board.
*/
public function clear() : self
public function clear(): self
{
$this->state = [];
$this->winning = 0;
@ -110,7 +110,7 @@ class GameBoardState
}
// TODO: Rename
public function getNumWinRows() : int
public function getNumWinRows(): int
{
return $this->winning;
}
@ -118,13 +118,13 @@ class GameBoardState
/**
* Check if the board only has winning cards
*/
public function hasGameEnded() : bool
public function hasGameEnded(): bool
{
if (count($this->state) < $this->width * $this->height) {
return false;
}
foreach($this->state as $pos) {
foreach ($this->state as $pos) {
if ($pos !== self::STATE_WIN) {
return false;
}
@ -135,14 +135,14 @@ class GameBoardState
/**
* Check if the board is full and all positions is in a given state.
*/
public function isFull($state) : bool
public function isFull($state): bool
{
// Board not filled, impossible to have all positions set.
if (count($this->state) < $this->width * $this->height) {
return false;
}
foreach($this->state as $pos) {
foreach ($this->state as $pos) {
if ($pos !== $state) {
return false;
}
@ -153,15 +153,15 @@ class GameBoardState
/**
*
*/
protected function update() : void
protected function update(): void
{
foreach($this->state as $pos => $_) {
foreach ($this->state as $pos => $_) {
$this->state[$pos] = self::STATE_PRESSED;
}
$patterns = $this->checkWinningState();
foreach($patterns as $cards) {
foreach($cards as $pos) {
foreach ($patterns as $cards) {
foreach ($cards as $pos) {
$this->state[$pos] = self::STATE_WIN;
}
}
@ -171,12 +171,12 @@ class GameBoardState
/**
* Check if the board is in a winning state.
*/
protected function checkWinningState() : array
protected function checkWinningState(): array
{
$win = [];
// Rows
for($y=0; $y < $this->height; $y++) {
for ($y = 0; $y < $this->height; $y++) {
$c = $this->checkRow($y);
if (count($c)) {
$win[] = $c;
@ -184,7 +184,7 @@ class GameBoardState
}
// Columns
for($x=0; $x < $this->width; $x++) {
for ($x = 0; $x < $this->width; $x++) {
$c = $this->checkCol($x);
if (count($c)) {
$win[] = $c;
@ -197,12 +197,12 @@ class GameBoardState
/**
* Check if a row is in a winning state (all cells pressed)
*/
protected function checkRow($y) : array
protected function checkRow($y): array
{
$cards = [];
$y = $y * $this->width;
for($x = 0; $x < $this->width; $x++) {
for ($x = 0; $x < $this->width; $x++) {
$pos = $x + $y;
if (!$this->isPressed($pos)) {
return [];
@ -216,11 +216,11 @@ class GameBoardState
/**
* Check if a column is in a winning state (all cells pressed)
*/
protected function checkCol($x) : array
protected function checkCol($x): array
{
$cards = [];
for($y = 0; $y < $this->height; $y++) {
for ($y = 0; $y < $this->height; $y++) {
$pos = $x + ($y * $this->width);
if (!$this->isPressed($pos)) {
return [];