function savePromotion() { global $mysql; global $movesArray, $FENarray, $curTurn; $num_moves = count($FENarray) - 1; // subtract one for initpos // when we run the promotion script, the color to be promoted // is the oppposite of the color who's turn it is $piece = $_POST['promotion']; if ('white' == $curTurn) { $piece = strtolower($piece); } // save the promoted piece in the movesArray $movesArray[$num_moves]['promo'] = $piece; // seperate the FEN board from the rest of the FEN $FEN = $FENarray[$num_moves]; $FENbits = trim(substr($FEN, strpos($FEN, ' '))); $xFEN = expandFEN(substr($FEN, 0, strpos($FEN, ' '))); // insert the promoted piece sqr2idx($movesArray[$num_moves]['toSq'], $idx); FENplace($xFEN, $idx, $movesArray[$num_moves]['promo']); // and repack the FEN $FENhead = packFEN($xFEN); $FEN = $FENhead . ' ' . $FENbits; // and save the new and improved FEN to the history $query = "\n\t\tSELECT MAX(h_time)\n\t\tFROM " . T_HISTORY . "\n\t\tWHERE h_game_id = '{$_SESSION['game_id']}'\n\t"; $result = $mysql->fetch_value($query, __LINE__, __FILE__); $query = "\n\t\tUPDATE " . T_HISTORY . "\n\t\tSET h_fen = '{$FEN}'\n\t\tWHERE h_game_id = '{$_SESSION['game_id']}'\n\t\t\tAND h_time = '{$result}'\n\t"; $mysql->query($query, __LINE__, __FILE__); updateTimestamp(); }
function til2idx($til, &$idx) { if (2 != strlen($til)) { die('til not two characters long: ' . $til); } til2colrow($til, $col, $row); colrow2sqr($col, $row, $sqr); sqr2idx($sqr, $idx); return $idx; }