Skip to content

Commit

Permalink
Spectrum domain components
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Dec 23, 2024
1 parent b8c3685 commit 30bcd85
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/SanSignal.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class SanSignal extends SanPlay
*/
public array $spectrum = [];

/**
* Spectrum domain components.
*
* @var array
*/
public array $spectrumComponent = [];

/**
* @param \Chess\Function\AbstractFunction $function
* @param string $movetext
Expand All @@ -44,6 +51,7 @@ public function __construct(
parent::__construct($movetext, $board);

$this->result[] = array_fill(0, count($function->names()), 0);
$this->spectrumComponent[] = array_fill(0, count($function->names()), 0);
$this->spectrum[] = 0;

foreach ($this->sanMovetext->moves as $val) {
Expand All @@ -59,8 +67,9 @@ public function __construct(
$resultItems[] = $resultItem[Color::W] - $resultItem[Color::B];
}
$this->result[] = $resultItems;
$spectrumItem = $this->normalize(-1, 1, $resultItems);
$this->spectrum[] = round(array_sum($spectrumItem), 2);
$spectrumComponent = $this->normalize(-1, 1, $resultItems);
$this->spectrumComponent[] = $this->normalize(-1, 1, $resultItems);
$this->spectrum[] = round(array_sum($spectrumComponent), 2);
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/SanSignalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ public static function setUpBeforeClass(): void
*/
public function e4_d5_exd5_Qxd5()
{
$expectedCenter = [ 0, 1.0, 0.09, 0.65, -1.0 ];
$expectedCenter = [ 0.0, 1.0, 0.09, 0.65, -1.0 ];
$expectedConnectivity = [ 0.0, -1.0, -1.0, -1.0, 1.0 ];
$expectedSpace = [ 0.0, 1.0, 0.25, 0.50, -1.0 ];
$expectedTime = [ 0.0, 2.0, -1.66, -0.18, -5.0 ];
$expectedSpectrum = [ 0.0, 0.73, -0.45, -2.24, -0.46 ];
$expectedSpectrumComponent = [
[ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ],
[ 0.0, 1.0, -1.0, 0.65, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.08, ],
[ 0.0, 0.55, -1.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ],
[ 0.13, 1.0, -1.0, 0.5, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.13, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, ],
[ 0.0, -1.0, 1.0, -0.24, -0.07, -0.02, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.11, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.02, ],
];

$movetext = '1.e4 d5 2.exd5 Qxd5';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());
Expand All @@ -37,6 +44,7 @@ public function e4_d5_exd5_Qxd5()
$this->assertEquals($expectedSpace, $sanSignal->balance[3]);
$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
$this->assertEquals($expectedSpectrumComponent, $sanSignal->spectrumComponent);
}

/**
Expand Down

0 comments on commit 30bcd85

Please sign in to comment.