Example #1
0
function newGame()
{
    start();
    echo "<div class='title'> " . getNumber() . " </div>";
    echo "<div class='sub-title'>Quedan por salir - " . getRest() . "</div>";
    drawBoard();
    fillTable(18);
    showTable();
}
Example #2
0
    }
    return "{$result}</table>";
}
function error()
{
    echo "<h1>Invalid chess board</h1>";
    die;
}
$json = array();
$result = 'OK';
$board = array();
$rows = preg_split('/\\//', $input, -1, PREG_SPLIT_NO_EMPTY);
if (count($rows) === 8) {
    for ($i = 0; $i < count($rows); $i++) {
        $board[$i] = preg_split('/\\-/', $rows[$i], -1);
        if (count($board[$i]) === 8) {
            countPieces($board[$i]);
        } else {
            error();
        }
    }
} else {
    error();
}
echo drawBoard($board);
if (count($json) > 0) {
    ksort($json);
    echo json_encode($json);
} else {
    echo "{}";
}
Example #3
0
    if ($blackScore + $whiteScore >= 8 * 8) {
        break;
    }
    // 置けるか判定
    $nextMyPuttable = isPuttable($board, $turn);
    $nextEnemyPuttable = isPuttable($board, getEnemyConst($turn));
    // 次に両方が置けなければ終了
    if (!$nextMyPuttable && !$nextEnemyPuttable) {
        break;
    } elseif (!$nextEnemyPuttable) {
    } else {
        $turn = getEnemyConst($turn);
    }
}
// 最終画面の描画
drawBoard($board);
echoConsole("ゲーム終了。");
if ($blackScore > $whiteScore) {
    echoConsole("黒の勝ち!\n");
} elseif ($blackScore < $whiteScore) {
    echoConsole("白の勝ち!\n");
} else {
    echoConsole("引き分けでした\n");
}
/**
 * 黒と白の数を取得
 * @param array $board 
 * @return array [黒, 白]
 */
function getScore($board)
{
Example #4
0
    if (strpos) {
    }
}
for ($mainCharIndex = 0; $mainCharIndex < strlen($mainWord); $mainCharIndex++) {
    $currentMainChar = $mainWord[$mainCharIndex];
    for ($wordIndex = 0; $wordIndex < count($validWords); $wordIndex++) {
        $currentWord = $validWords[$wordIndex];
        $offset = 0;
        $foundWordIndex = strpos($currentWord, $currentMainChar, $offset);
        // var_dump($wordsCount);
        while ($foundWordIndex !== false) {
            if (checkForValidiy($currentWord, $foundWordIndex)) {
                unset($wordsCount[$currentWord]);
                //unset($wordsCount[array_keys($wordsCount)[$wordIndex]]);
                $table = importWord($mainCharIndex, $currentWord, $foundWordIndex);
                $result = drawBoard($table, $boardLength);
                $wordsCount = calculateJson($wordsCount);
                $result .= json_encode($wordsCount);
                die($result);
            }
            $offset = $foundWordIndex + 1;
            $foundWordIndex = strpos($currentWord, $currentMainChar, $offset);
        }
    }
}
# FUNCTIONS
// sort first longest words
function sortWordsByKey(&$array)
{
    uksort($array, function ($a, $b) {
        if (strlen($a) === strlen($b)) {