}
     if (!$_POST['hold2']) {
         replace_card(2, $userid);
     }
     if (!$_POST['hold3']) {
         replace_card(3, $userid);
     }
     if (!$_POST['hold4']) {
         replace_card(4, $userid);
     }
     if (!$_POST['hold5']) {
         replace_card(5, $userid);
     }
     $cards = show_cards($userid, 2);
     print "{$cards}<br />";
     $scoreArray = calc_score($userid);
     $winMultiplier = find_winnings($scoreArray[1], $scoreArray[2]);
     $bet = $bb['betAmount'];
     $totalwin = $bet * $winMultiplier;
     if ($totalwin != 0) {
         print "With your {$scoreArray[0]}, you won {$winMultiplier}x your original bet of \$" . number_format($bet) . ". <br /><br />";
         print "<b>\$" . number_format($totalwin) . " has been added to your wallet.</b>";
         $db->query("UPDATE users SET money=money+{$totalwin} WHERE userid='{$userid}'");
         $db->query("UPDATE videopoker_stats SET houseProfit=houseProfit-{$totalwin}");
     } else {
         print "<b>With your {$scoreArray[0]}, you lost your original bet of \$" . number_format($bet) . ".</b> <br /><br />";
         print "(Need pair of jacks or better to win)";
     }
     $db->query("DELETE FROM videopoker WHERE userid='{$userid}'");
 } else {
     print $error;
Exemplo n.º 2
0
function farm($result, $village)
{
    global $server;
    global $account;
    global $farm_lo, $farm_hi;
    global $village_x, $village_y;
    $url = "http://{$server}/a2b.php";
    $max_clubs = $farm_hi;
    $min_clubs = $farm_lo;
    $troops = get_troops($result);
    $curr_clubs = 0;
    $curr_axes = 0;
    $curr_tks = 0;
    if (isset($troops[1])) {
        $curr_clubs = $troops[1];
    }
    if (isset($troops[3])) {
        $curr_axes = $troops[3];
    }
    if (isset($troops[6])) {
        $curr_tks = $troops[6];
    }
    if ($curr_clubs < $min_clubs && $curr_axes < $min_clubs && $curr_tks < $min_clubs) {
        return false;
    }
    echo "{$curr_clubs} clubs, {$curr_axes} axes, {$curr_tks} tks availabe.\n";
    // Get a target
    $sql = "SELECT x, y, `raid`, `score`, `player` FROM `targets` WHERE account = {$account} and `village` = {$village} and `invalid` = 0 and NOW() > `timestamp` order by (sqrt((x - {$village_x}) * (x - {$village_x}) + (y - {$village_y}) * (y - {$village_y}))) / IF(avg_score=0, 1, avg_score) limit 1";
    echo $sql . "\n";
    $res = mysql_query($sql);
    if (!$res) {
        die(mysql_error());
    }
    $row = mysql_fetch_row($res);
    if (!$row) {
        echo "Warning: too many clubs. {$village} \n";
        return false;
    }
    $target_x = $row[0];
    $target_y = $row[1];
    $raid = $row[2];
    $score_str = $row[3];
    $player = $row[4];
    $score = calc_score($score_str);
    echo "Average score:  {$score} \n";
    $old_min_clubs = $min_clubs;
    if ($raid > 1) {
        $min_clubs = $min_clubs * $raid;
        $max_clubs = $max_clubs * $raid;
    }
    echo "Want to raid : (" . $row[0] . " , " . $row[1] . ")\n";
    if ($curr_clubs < $min_clubs && $curr_axes < $min_clubs && $curr_tks < $min_clubs) {
        echo "no enough troops. {$min_clubs} \n";
        return false;
    }
    $clubs = '';
    $axes = '';
    $tks = '';
    if ($curr_clubs >= $min_clubs) {
        if ($curr_clubs <= $max_clubs) {
            $clubs = $curr_clubs;
        } else {
            $clubs = $min_clubs + round(($max_clubs - $min_clubs) * $score * $score / 10000);
            if ($curr_clubs - $clubs < $old_min_clubs) {
                $clubs = $curr_clubs;
            }
        }
    } else {
        if ($curr_axes >= $min_clubs) {
            if ($curr_axes <= $max_clubs) {
                $axes = $curr_axes;
            } else {
                $axes = $min_clubs + round(($max_clubs - $min_clubs) * $score * $score / 10000);
                if ($curr_axes - $axes < $old_min_clubs) {
                    $axes = $curr_axes;
                }
            }
        } else {
            if ($curr_tks >= $min_clubs) {
                if ($curr_tks <= $max_clubs) {
                    $tks = $curr_tks;
                } else {
                    $tks = $min_clubs + round(($max_clubs - $min_clubs) * $score * $score / 10000);
                    if ($curr_axes - $tks < $old_min_clubs) {
                        $tks = $curr_tks;
                    }
                }
            }
        }
    }
    $distance = sqrt(($target_x - $village_x) * ($target_x - $village_x) + ($target_y - $village_y) * ($target_y - $village_y));
    echo "distance: {$distance}\n";
    $second_cost = round($distance / 5 * 3600);
    echo "second_cost: {$second_cost}\n";
    $second_cost = max($second_cost, 198 * 60);
    $next_raid_interval = rand($second_cost, 2 * $second_cost);
    echo "next_raid_interval: {$next_raid_interval}\n";
    // Update the target
    $sql = "update `targets` set `timestamp` = FROM_UNIXTIME(unix_timestamp(now()) + {$next_raid_interval}) where account = {$account} and x = " . $target_x . " and y = " . $target_y;
    mysql_query($sql);
    if (attack_func($target_x, $target_y, $clubs, $axes, $tks, '', '', '', $result, $player)) {
        return $curr_clubs - intval($clubs) >= $old_min_clubs || $curr_axes - intval($axes) >= $old_min_clubs || $curr_tks - intval($tks) >= $old_min_clubs;
    }
    return true;
}
Exemplo n.º 3
0
 } else {
     for ($i = 0; $i < 5; $i++) {
         $dice[$i] = $_POST["d" . $i . "_val"];
     }
     if (array_key_exists('_roll', $_POST)) {
         $_SESSION['_valid'] = true;
         $_SESSION['turn_num'] = $_SESSION['turn_num'] + 1;
         printf("turn number = %d", $_SESSION['turn_num']);
     } else {
         if (array_key_exists('_select', $_POST)) {
             //make selection
             if ($_SESSION['_valid']) {
                 $_SESSION['turn_num'] = 0;
                 calc_score($_POST['selection']);
                 if ($_SESSION['_bonus']) {
                     calc_score('yahtzeebonus');
                     $_SESSION['bonus'] = false;
                 }
                 $_SESSION["_valid"] = false;
                 $_SESSION['rounds'] = array_key_exists('rounds', $_SESSION) ? $_SESSION['rounds'] + 1 : 1;
                 printf("rounds completed: %d", $_SESSION['rounds']);
             }
         } else {
             //new game
             $key = $_SESSION['key'];
             foreach (array_keys($_SESSION) as $key) {
                 unset($_SESSION[$key]);
             }
             $_SESSION['key'] = $key;
         }
     }
Exemplo n.º 4
0
function read_report($id, $title)
{
    global $server;
    global $user;
    global $report_str;
    global $account;
    // x_world will be get at 0:30
    // run at hostjava.net
    $tblname = "x_world_" . str_replace(".", "_", $server) . "_" . date('ymd', time() - 3600 * 4);
    $url = "http://{$server}/berichte.php?id={$id}";
    echo $url . "\n";
    $ch = my_curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    $result = curl_exec($ch);
    curl_close($ch);
    // <td colspan="10"><a href=spieler.php?uid=6431>Hömeless</a> 所有の <a href=karte.php?d=298467&c=80>新しい村</a></td>
    if (!preg_match_all('#<a href="?spieler\\.php\\?uid=[0-9]+"?>([^<]+)</a>#', $result, $matches, PREG_SET_ORDER)) {
        record_report($id, "【プレイヤー不明】{$title}");
        return;
    }
    if (count($matches) < 3) {
        record_report($id, "【プレイヤー不足】{$title}");
        return;
    }
    // attacked !
    if ($matches[1][1] != $user) {
        // echo "attacked.\n";
        record_report($id, "【防衛】{$title}");
        return;
    }
    $player = $matches[2][1];
    if (!preg_match_all('#<a href="karte\\.php\\?d=([0-9]+)#', $result, $matches, PREG_SET_ORDER)) {
        record_report($id, "【村不明】{$title}");
        return;
    }
    if (count($matches) < 2) {
        record_report($id, "【村不足】{$title}");
        return;
    }
    $village_id = $matches[1][1];
    $sql = "select x, y from {$tblname} where id = {$village_id}";
    $res = mysql_query($sql);
    if (!$res) {
        record_report($id, "【X-WORLD】{$title} {$village_id} {$tblname}");
        return;
    }
    $row = mysql_fetch_row($res);
    if (!$res) {
        record_report($id, "【X-WORLD-2】{$title} {$village_id}");
        return;
    }
    $x = $row[0];
    $y = $row[1];
    // $soldiers = get_report_line($result, '兵士');
    $soldiers = get_report_line($result, $report_str[0]);
    if (!$soldiers) {
        record_report($id, "【兵士情報不明】{$title}");
        return;
    }
    // $died = get_report_line($result, '死傷');
    $died = get_report_line($result, $report_str[1]);
    // $captured = get_report_line($result, '捕虜');
    $captured = get_report_line($result, $report_str[2]);
    if (!$died && !$captured) {
        record_report($id, "【死傷捕虜不明】{$title}");
        return;
    }
    if (!$died) {
        $died = $captured;
    } else {
        if ($captured) {
            if (count($died) != count($captured)) {
                record_report($id, "【死傷捕虜数合わない】{$title}");
                return;
            }
            for ($i = 0; $i < count($died); $i++) {
                $died[$i] += $captured[$i];
            }
        }
    }
    $died_total = array_sum($died);
    if ($captured) {
        $died_total -= array_sum($captured);
    }
    if (array_sum($soldiers) == array_sum($died)) {
        // remove this one from raid list?
        $sql = "update targets set invalid = 1, invalid_msg = '全滅' where x = {$x} and y = {$y}";
        if (!mysql_query($sql)) {
            die(mysql_error());
        }
        record_report($id, "【全滅】{$title} ({$x},{$y})");
        return;
    }
    // <img class="res" src="img/un/r/1.gif">44
    // <img class="res" src="img/un/r/2.gif">44
    // <img class="res" src="img/un/r/3.gif">44
    // <img class="res" src="img/un/r/4.gif">49
    // <img class="r1" src="img/x.gif" alt="木材" title="木材" />871
    if (!preg_match_all('#<img class="r[1-4]" src="img/x.gif" alt="[^"]+" title="[^"]+" />([0-9]+)#', $result, $matches, PREG_SET_ORDER)) {
        echo "FAILED: can not read report well {$id} resources \n";
        record_report($id, "【資源未知】{$title}");
        return;
    }
    $total = 0;
    foreach ($matches as $match) {
        $total += $match[1];
    }
    $max_raid = ($soldiers[0] - $died[0]) * 60 + ($soldiers[2] - $died[2]) * 50 + ($soldiers[5] - $died[5]) * 80;
    $score = round($total * 100 / $max_raid);
    echo "DEBUG: {$total}, {$max_raid} " . "\n";
    $sql = "select score from targets where x = {$x} and y = {$y}";
    $res = mysql_query($sql);
    if (!$res) {
        die(mysql_error());
    }
    $row = mysql_fetch_row($res);
    if (!$row) {
        record_report($id, "【ファーム対象外】{$title}");
        return;
    }
    $old_score = $row[0];
    if (strlen($old_score) == 0) {
        $scores = array();
    } else {
        $scores = explode('|', $old_score);
    }
    array_push($scores, $score);
    if (count($scores) > 10) {
        array_shift($scores);
    }
    $new_score = implode('|', $scores);
    $avg_score = calc_score($new_score);
    if ($died_total > 0) {
        echo "{$died_total} died.\n";
        $sql = "update targets set `timestamp` = date_add(now(),  interval 2 day), `score` = '{$new_score}', `avg_score` = {$avg_score}, invalid_msg = '死傷' where account = {$account} and x = {$x} and y = {$y}";
    } else {
        if ($total == $max_raid) {
            echo "reraid...({$x},{$y}) {$total}\n";
            $sql = "update targets set `timestamp` = date_sub(now(),  interval 3 day), `score` = '{$new_score}', `avg_score` = {$avg_score} where account = {$account} and x = {$x} and y = {$y}";
        } else {
            if ($total == 0 && count($scores) >= 3 && $scores[count($scores) - 2] == 0 && $scores[count($scores) - 3] == 0) {
                echo "raid nothing 3 times ... ({$x},{$y}) \n";
                $sql = "update targets set invalid = 1, invalid_msg = 'ゼロ3回', `score` = '{$new_score}', `avg_score` = {$avg_score} where account = {$account} and x = {$x} and y = {$y}";
            } else {
                if ($total == 0) {
                    echo "raid nothing ... ({$x},{$y}) \n";
                    $sql = "update targets set `timestamp` = date_add(now(),  interval 1 day), `score` = '{$new_score}', `avg_score` = {$avg_score} where account = {$account} and x = {$x} and y = {$y}";
                } else {
                    $sql = "update targets set `timestamp` = `timestamp`, `score` = '{$new_score}', `avg_score` = {$avg_score} where account = {$account} and x = {$x} and y = {$y}";
                }
            }
        }
    }
    if (!mysql_query($sql)) {
        die(mysql_error());
    }
    // <td class="c">0</td>
    // <td>1</td>
    if ($died_total > 0) {
        record_report($id, "【死傷】{$title} (" . array_sum($died) . ")");
    } else {
        if ($total == 0) {
            echo "raid zero.\n";
            record_report($id, "【無駄】{$title}");
        }
    }
}
Exemplo n.º 5
0
    } else {
        $row["tricks2"]++;
    }
} else {
    // Figure out which bot is bot2 in this round.
    if ($row["bot2"] === $row["id2"]) {
        $row["tricks2"]++;
    } else {
        $row["tricks1"]++;
    }
}
// If the game is over, shut it game down.
if ($row["round"] >= 13) {
    // Calculate the score by comparing the bids to the tricks.
    $score1 = calc_score($row["bid1"], $row["tricks1"]);
    $score2 = calc_score($row["bid2"], $row["tricks2"]);
    // Record the scores.
    $res = pg_query_params('UPDATE games SET score1=$1, score2=$2, tricks1=$3, tricks2=$4, finished=now() WHERE id=$5;', [$score1, $score2, $row["tricks1"], $row["tricks2"], $bot["game"]]);
    if ($res === FALSE || pg_affected_rows($res) !== 1) {
        panic("Failed to update the database to record the final scores of game {$bot['game']}.");
    }
    pg_free_result($res);
    // Free up the bots.
    $res = pg_query_params('UPDATE bots SET game=NULL, game_timeout=NULL, cards=NULL WHERE id=$1 OR id=$2;', [$row["bot1"], $row["bot2"]]);
    if ($res === FALSE || pg_affected_rows($res) !== 2) {
        panic("Failed to update the database to release bots {$row['bot1']} and {$row['bot2']} from game {$bot['game']}.");
    }
    pg_free_result($res);
} else {
    // Increment the round counter.
    $row["round"]++;