예제 #1
0
//*************************** Starting game **************
$still_playing = true;
$wins_left = $wins;
$computer_squars = [];
$player_squars = [];
$av_squares = [0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8];
build_board($board);
while ($still_playing) {
    fwrite(STDOUT, "Pick a square: ");
    $square = (int) fgets(STDIN) - 1;
    $player_squars[] = $square;
    unset($av_squares[$square]);
    $board[$square] = $X;
    build_board($board);
    $not_over = check_if_over($computer_squars, $player_squars, $wins);
    if ($not_over === true) {
        $comp_pick = comp_logic($computer_squars, $player_squars, $wins, $av_squares, $wins_left);
        $computer_squars[] = $comp_pick;
        unset($av_squares[$comp_pick]);
        $board[$comp_pick] = $O;
        build_board($board);
        $not_over = check_if_over($computer_squars, $player_squars, $wins);
    }
    if ($not_over !== true) {
        echo $not_over . PHP_EOL;
        $still_playing = false;
    }
    // if($result === false) {
    // 	$still_playing = $result;
    // }
}
예제 #2
0
function build_board($boards, $is_cat = false)
{
    global $settings, $context, $user_info, $smcFunc, $boardurl, $boarddir, $modSettings, $board;
    $response = array();
    foreach ($boards as $id => $tt_board) {
        if (empty($tt_board['id'])) {
            continue;
        }
        $new_post = false;
        if ($tt_board['new'] || $tt_board['children_new']) {
            $new_post = true;
            $logo_url = $settings['images_url'] . '/' . $context['theme_variant_url'] . 'on' . ($tt_board['new'] ? '' : '2') . '.png';
        } elseif ($tt_board['redirect']) {
            $logo_url = $settings['images_url'] . '/' . $context['theme_variant_url'] . 'redirect.png';
        } else {
            $logo_url = $settings['images_url'] . '/' . $context['theme_variant_url'] . 'off.png';
        }
        $logo_dir = str_replace($boardurl, $boarddir, $logo_url);
        if (!file_exists($logo_dir) && file_exists(preg_replace('/png$/', 'gif', $logo_dir))) {
            $logo_url = preg_replace('/png$/', 'gif', $logo_url);
        }
        $is_link_forum = isset($tt_board['redirect']) && !empty($tt_board['redirect']);
        if (!$is_cat && !$user_info['is_guest']) {
            $can_subscribe = allowedTo('mark_notify', $tt_board['id']);
            $request = $smcFunc['db_query']('', '
                SELECT sent
                FROM {db_prefix}log_notify
                WHERE id_board = {int:current_board}
                    AND id_member = {int:current_member}
                LIMIT 1', array('current_board' => $tt_board['id'], 'current_member' => $user_info['id']));
            $is_subscribed = $smcFunc['db_num_rows']($request) != 0;
            $smcFunc['db_free_result']($request);
            $board = $tt_board['id'];
            loadBoard();
            loadPermissions();
            $can_post_new = (allowedTo('post_new') || $modSettings['postmod_active'] && allowedTo('post_unapproved_topics')) && !$is_link_forum;
            $mobiquo_can_post = true;
            if (isset($modSettings['boards_disable_new_topic']) && !empty($modSettings['boards_disable_new_topic'])) {
                $dis_new_topic_boards = explode(',', $modSettings['boards_disable_new_topic']);
                $mobiquo_can_post = !in_array($tt_board['id'], $dis_new_topic_boards);
            }
            $can_post = $can_post_new && $mobiquo_can_post ? true : false;
        } else {
            $can_subscribe = false;
            $is_subscribed = false;
            $can_post = false;
        }
        $tp_board_id = $is_cat ? preg_replace('/c/', '', $tt_board['id']) : $tt_board['id'];
        $logo_url = ($tp_logo_url = tp_get_forum_icon($tp_board_id, $is_link_forum ? 'link' : ($is_cat ? 'category' : 'forum'), false, $new_post)) ? $tp_logo_url : $logo_url;
        $xmlrpc_forum = array('forum_id' => new xmlrpcval($tt_board['id'], 'string'), 'forum_name' => new xmlrpcval(basic_clean($tt_board['name']), 'base64'), 'parent_id' => new xmlrpcval($tt_board['id_parent'] ? $tt_board['id_parent'] : 'c' . $tt_board['id_cat'], 'string'), 'logo_url' => new xmlrpcval($logo_url, 'string'), 'new_post' => new xmlrpcval($new_post, 'boolean'), 'url' => new xmlrpcval($tt_board['redirect'], 'string'), 'sub_only' => new xmlrpcval($is_cat, 'boolean'), 'can_subscribe' => new xmlrpcval($can_subscribe, 'boolean'), 'is_subscribed' => new xmlrpcval($is_subscribed, 'boolean'), 'is_protected' => new xmlrpcval(false, 'boolean'), 'can_post' => new xmlrpcval($can_post, 'boolean'));
        if ($_GET['return_description']) {
            $xmlrpc_forum['description'] = new xmlrpcval(basic_clean($tt_board['description']), 'base64');
        }
        if (isset($_GET['forum_id']) && (!empty($_GET['forum_id']) || $_GET['forum_id'] === 0)) {
            $xmlrpc_forum['has_child'] = new xmlrpcval($tt_board['has_child'], 'boolean');
        }
        if (isset($tt_board['boards']) && !empty($tt_board['boards'])) {
            $xmlrpc_forum['child'] = new xmlrpcval(build_board($tt_board['boards']), 'array');
        }
        $response[] = new xmlrpcval($xmlrpc_forum, 'struct');
    }
    return $response;
}