Skip to content

Commit

Permalink
Fixed the lines of squares
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Jan 31, 2025
1 parent efbf5f0 commit d223dfc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Variant/Classical/PGN/Square.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ public function isDiagonalLine(array $line): bool
*/
public function isStraightLine(array $line): bool
{
return $this->hasConsecutiveFiles($line) || $this->hasConsecutiveRanks($line, 1);
if ($this->hasConsecutiveFiles($line)) {
return !$this->hasConsecutiveRanks($line, -1) && !$this->hasConsecutiveRanks($line, 1);
}

return $this->hasConsecutiveRanks($line, -1) xor $this->hasConsecutiveRanks($line, 1);
}

/**
Expand Down
26 changes: 25 additions & 1 deletion tests/unit/Variant/Classical/PGN/SquareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ public function is_diagonal_line_b4_c3_d6()
$this->assertFalse(self::$square->isDiagonalLine(['b4', 'c3', 'd6']));
}

/**
* @test
*/
public function is_straight_line_b4_c3_d2()
{
$this->assertFalse(self::$square->isStraightLine(['b4', 'c3', 'd2']));
}

/**
* @test
*/
Expand All @@ -196,7 +204,7 @@ public function is_straight_line_c7_e7_d7()
*/
public function is_straight_line_c7_c6_c5()
{
$this->assertFalse(self::$square->isStraightLine(['c7', 'c6', 'c5']));
$this->assertTrue(self::$square->isStraightLine(['c7', 'c6', 'c5']));
}

/**
Expand All @@ -206,4 +214,20 @@ public function is_straight_line_c5_c6_c7()
{
$this->assertTrue(self::$square->isStraightLine(['c5', 'c6', 'c7']));
}

/**
* @test
*/
public function is_diagonal_line_c5_c6_c7()
{
$this->assertFalse(self::$square->isDiagonalLine(['c5', 'c6', 'c7']));
}

/**
* @test
*/
public function is_diagonal_line_c7_d7_e7()
{
$this->assertFalse(self::$square->isDiagonalLine(['c7', 'd7', 'e7']));
}
}

0 comments on commit d223dfc

Please sign in to comment.