Skip to content

Commit

Permalink
Wording
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Dec 23, 2024
1 parent ce7aadc commit 4cf7677
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
18 changes: 9 additions & 9 deletions src/SanSignal.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class SanSignal extends SanPlay
public array $time = [];

/**
* The normalized signal in the frequency domain.
* The normalized signal in the spectrum domain.
*
* @var array
*/
public array $freq = [];
public array $spectrum = [];

/**
* Time components of the signal.
Expand All @@ -39,11 +39,11 @@ class SanSignal extends SanPlay
public array $timeComponent = [];

/**
* Frequency components of the signal.
* Spectrum components of the signal.
*
* @var array
*/
public array $freqComponent = [];
public array $spectrumComponent = [];

/**
* @param \Chess\Function\AbstractFunction $function
Expand All @@ -58,8 +58,8 @@ public function __construct(
parent::__construct($movetext, $board);

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

foreach ($this->sanMovetext->moves as $val) {
Expand All @@ -74,9 +74,9 @@ public function __construct(
$items[] = $item[Color::W] - $item[Color::B];
}
$this->result[] = $items;
$freqComponent = $this->normalize(-1, 1, $items);
$this->freqComponent[] = $freqComponent;
$this->freq[] = round(array_sum($freqComponent), 2);
$spectrumComponent = $this->normalize(-1, 1, $items);
$this->spectrumComponent[] = $spectrumComponent;
$this->spectrum[] = round(array_sum($spectrumComponent), 2);
$items = [];
}
}
Expand Down
80 changes: 40 additions & 40 deletions tests/unit/SanSignalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function e4_d5_exd5_Qxd5()
$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 ];
$expectedFreq = [ 0.0, 0.73, -0.45, -2.24, -0.46 ];
$expectedSpectrum = [ 0.0, 0.73, -0.45, -2.24, -0.46 ];

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

/**
Expand All @@ -45,13 +45,13 @@ public function e4_d5_exd5_Qxd5()
public function A59()
{
$expectedTime = [ 0.0, 2.5, 0.78, 1.0, 1.32, 1.4, 1.7, 3.53, 3.04, 2.78, 0.0, 1.86, 0.19, 0.89, -2.17, 3.41, 2.05, 2.23 ];
$expectedFreq = [ 0.0, 1.62, 0.5, 1.12, 2.35, 1.23, 1.7, 2.2, 0.7, 3.67, 3.88, 1.2, -0.95, -0.55, -0.72, 0.3, 0.29, 0.3 ];
$expectedSpectrum = [ 0.0, 1.62, 0.5, 1.12, 2.35, 1.23, 1.7, 2.2, 0.7, 3.67, 3.88, 1.2, -0.95, -0.55, -0.72, 0.3, 0.29, 0.3 ];

$A59 = file_get_contents(self::DATA_FOLDER.'/sample/A59.pgn');
$sanSignal = new SanSignal(self::$function, $A59, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -60,13 +60,13 @@ public function A59()
public function a3()
{
$expectedTime = [ 0.0, 2.0 ];
$expectedFreq = [ 0.0, 2.0 ];
$expectedSpectrum = [ 0.0, 2.0 ];

$movetext = '1.a3';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -75,13 +75,13 @@ public function a3()
public function a4()
{
$expectedTime = [ 0.0, 2.0 ];
$expectedFreq = [ 0.0, 1.5 ];
$expectedSpectrum = [ 0.0, 1.5 ];

$movetext = '1.a4';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -90,13 +90,13 @@ public function a4()
public function b4()
{
$expectedTime = [ 0.0, 1.0 ];
$expectedFreq = [ 0.0, 1.0 ];
$expectedSpectrum = [ 0.0, 1.0 ];

$movetext = '1.b4';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -105,13 +105,13 @@ public function b4()
public function c4()
{
$expectedTime = [ 0.0, 1.0 ];
$expectedFreq = [ 0.0, 0.67 ];
$expectedSpectrum = [ 0.0, 0.67 ];

$movetext = '1.c4';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -120,13 +120,13 @@ public function c4()
public function d4()
{
$expectedTime = [ 0.0, 3.0 ];
$expectedFreq = [ 0.0, 1.62 ];
$expectedSpectrum = [ 0.0, 1.62 ];

$movetext = '1.d4';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -135,13 +135,13 @@ public function d4()
public function e4()
{
$expectedTime = [ 0.0, 2.0 ];
$expectedFreq = [ 0.0, 0.73 ];
$expectedSpectrum = [ 0.0, 0.73 ];

$movetext = '1.e4';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -150,13 +150,13 @@ public function e4()
public function f4()
{
$expectedTime = [ 0.0, 2.0 ];
$expectedFreq = [ 0.0, 0.64 ];
$expectedSpectrum = [ 0.0, 0.64 ];

$movetext = '1.f4';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -165,13 +165,13 @@ public function f4()
public function g4()
{
$expectedTime = [ 0.0, 1.0 ];
$expectedFreq = [ 0.0, 0.91 ];
$expectedSpectrum = [ 0.0, 0.91 ];

$movetext = '1.g4';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -180,13 +180,13 @@ public function g4()
public function h4()
{
$expectedTime = [ 0.0, 2.0 ];
$expectedFreq = [ 0.0, 1.6 ];
$expectedSpectrum = [ 0.0, 1.6 ];

$movetext = '1.h4';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -195,13 +195,13 @@ public function h4()
public function a4_h5()
{
$expectedTime = [ 0.0, 2.0, -1.0 ];
$expectedFreq = [ 0.0, 1.5, -1.0 ];
$expectedSpectrum = [ 0.0, 1.5, -1.0 ];

$movetext = '1.a4 h5';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -210,13 +210,13 @@ public function a4_h5()
public function a4_a5()
{
$expectedTime = [ 0.0, 2.0, 0.0 ];
$expectedFreq = [ 0.0, 1.5, 0.0 ];
$expectedSpectrum = [ 0.0, 1.5, 0.0 ];

$movetext = '1.a4 a5';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -225,13 +225,13 @@ public function a4_a5()
public function a4_e5()
{
$expectedTime = [ 0.0, 2.0, -2.0 ];
$expectedFreq = [ 0.0, 1.5, -0.62 ];
$expectedSpectrum = [ 0.0, 1.5, -0.62 ];

$movetext = '1.a4 e5';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -240,13 +240,13 @@ public function a4_e5()
public function h4_e5()
{
$expectedTime = [ 0.0, 2.0, -3.0 ];
$expectedFreq = [ 0.0, 1.6, -0.63 ];
$expectedSpectrum = [ 0.0, 1.6, -0.63 ];

$movetext = '1.h4 e5';
$sanSignal = new SanSignal(self::$function, $movetext, new Board());

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -255,15 +255,15 @@ public function h4_e5()
public function a5()
{
$expectedTime = [ 0.0, 4.0 ];
$expectedFreq = [ 0.0, 4.0 ];
$expectedSpectrum = [ 0.0, 4.0 ];

$fen = '7k/8/8/8/P7/8/8/7K w - -';
$movetext = '1.a5';
$board = FenToBoardFactory::create($fen);
$sanSignal = new SanSignal(self::$function, $movetext, $board);

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -272,15 +272,15 @@ public function a5()
public function a6()
{
$expectedTime = [ 0.0, 5.0 ];
$expectedFreq = [ 0.0, 5.0 ];
$expectedSpectrum = [ 0.0, 5.0 ];

$fen = '7k/8/8/P7/8/8/8/7K w - -';
$movetext = '1.a6';
$board = FenToBoardFactory::create($fen);
$sanSignal = new SanSignal(self::$function, $movetext, $board);

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -289,15 +289,15 @@ public function a6()
public function a7()
{
$expectedTime = [ 0.0, 3.0 ];
$expectedFreq = [ 0.0, 3.0 ];
$expectedSpectrum = [ 0.0, 3.0 ];

$fen = '4k3/8/P7/8/8/8/8/4K3 w - -';
$movetext = '1.a7';
$board = FenToBoardFactory::create($fen);
$sanSignal = new SanSignal(self::$function, $movetext, $board);

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -306,15 +306,15 @@ public function a7()
public function b5()
{
$expectedTime = [ 0.0, 4.0 ];
$expectedFreq = [ 0.0, 1.33 ];
$expectedSpectrum = [ 0.0, 1.33 ];

$fen = '7k/8/8/8/1P6/8/8/7K w - -';
$movetext = '1.b5';
$board = FenToBoardFactory::create($fen);
$sanSignal = new SanSignal(self::$function, $movetext, $board);

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}

/**
Expand All @@ -323,14 +323,14 @@ public function b5()
public function h7()
{
$expectedTime = [ 0.0, 4.0 ];
$expectedFreq = [ 0.0, 3.2 ];
$expectedSpectrum = [ 0.0, 3.2 ];

$fen = '4k3/8/7P/8/8/8/8/4K3 w - -';
$movetext = '1.h7';
$board = FenToBoardFactory::create($fen);
$sanSignal = new SanSignal(self::$function, $movetext, $board);

$this->assertEquals($expectedTime, $sanSignal->time);
$this->assertEquals($expectedFreq, $sanSignal->freq);
$this->assertEquals($expectedSpectrum, $sanSignal->spectrum);
}
}

0 comments on commit 4cf7677

Please sign in to comment.