/** * @test */ public function shouldNotAutoCreateFenWhenExists() { // given $fen = new Fen("rnbqkbnr\\/pppppppp\\/8\\/8\\/8\\/8\\/PPPPPPPP\\/RNBQKBNR w KQkq - 0 1"); $fen2 = new Fen("rnbqkbnr\\/pppppppp\\/8\\/8\\/8\\/8\\/PPPPPPPP\\/RNBQKBNR w KQkq - 0 1"); // then $this->assertEquals($fen->getId(), $fen2->getId()); }
private function getValidFen($fen) { if (is_numeric($fen)) { return $fen; } return isset($fen) ? Fen::getIdByFen(str_replace("_", "/", $fen)) : null; }
public static function getIdByFen($fen) { $fen = new Fen($fen); return $fen->getId(); }
public function setFen($fen) { $fen = new Fen($fen); $this->setValue('fen_id', $fen->getId()); }
private function getEcoLine($eco) { $ecoCode = $eco['site']; $openingName = $eco['white']; $variation = isset($eco['black']) ? $eco['black'] : ''; $moves = $eco['moves']; if (count($moves) === 0) { return null; } $index = count($moves) - 1; $lastMove = $moves[$index]; $fenId = Fen::getIdByFen($lastMove['fen']); if ($index === 0) { $fen = $eco['fen']; } else { $fen = $moves[$index - 1]['fen']; } $fenId = isset($fen) ? Fen::getIdByFen($fen) : null; $fromSquare = $lastMove['from']; $toSquare = $lastMove['to']; $notation = $lastMove['m']; return array('eco_code' => $ecoCode, 'opening_name' => $openingName, 'variation' => $variation, 'fen_id' => $fenId, 'previous_fen_id' => $fenId, 'from_square' => $fromSquare, 'to_square' => $toSquare, 'notation' => $notation); }
/** * Append new move to the game * @param $move * @return Array */ public function appendMove($move) { if (!$this->getId()) { $this->commit(); } $move = $this->gameParser()->getParsed($move); $move['game_id'] = $this->getId(); $move['fen_id'] = Fen::getIdByFen($move['fen']); $m = new Move(); $m->setValues($move); $m->commit(); return $move; }