// If the bot is in a game, toss them. if (!is_null($row["game"])) { info("The bot with ID '{$row['id']}' is already in game '{$row['game']}', removing from the matchmaking queue."); continue; } // Otherwise, keep them around. array_push($tmp, $row["id"]); } pg_free_result($res); // Replace the list of bots with the filtered list. $bots = $tmp; // Shuffle the array. shuffle($bots); // Take the bots two at a time and create matches for them. while (count($bots) > 1) { // Remove the two bots at the front of the array. // Taking from the front ensures any bot from the last round is prioritized $bot1 = array_shift($bots); $bot2 = array_shift($bots); // Create a game for these two bots. info("Creating game between '{$bot1}' and '{$bot2}'."); new_game($bot1, $bot2); } pg_query("SELECT 1;"); pg_query("COMMIT;"); pg_query("SELECT 1;"); // One bot may be left unmatched in each round. if (count($bots) !== 0) { info("Unable to match " . implode(" and ", $bots) . " in this round."); } }
?> .gif' alt='<?php echo $player_1; ?> '> <p><img src='i/bone/<?php echo $player_2; ?> .gif' alt='<?php echo $player_2; ?> '> </center> <?php } ?> </FIELDSET> </td> <td width=50%> <FIELDSET><LEGEND>Игрок №2</LEGEND> <center><script language=JavaScript>show_inf('<i>Тень</i>','100','100','100','');</script> </center> <br> Деньги: <b>??? зм.</b> <br> Ставка: <b><?php echo $st; ?> зм.</b> <?php if ($_POST['play'] == 1) { ?>
<?php include "config.php"; //---test database---// if (isset($_POST["update_database"])) { include "createdatabase.php"; echo "<br>database is up to date."; } elseif (isset($_POST["new_game"])) { include "newgame.php"; $gameid = new_game(); echo "new game created: " . $gameid; } elseif (isset($_POST["new_player"])) { if (isset($_POST["text_input"]) and $_POST["text_input"] > 0) { include "newplayer.php"; $name = "test_player"; $gameid = $_POST["text_input"]; $browserinfo = $_SERVER['HTTP_USER_AGENT']; $playerid = new_player($name, $gameid, $browserinfo); $_SESSION["playerid"] = $playerid; echo "game: " . $gameid . "<br>new player created: " . $playerid; } else { echo "enter gameid in text field"; } } elseif (isset($_POST["start_game"])) { if (isset($_POST["text_input"]) and $_POST["text_input"] > 0) { $_GET["game"] = $_POST["text_input"]; include "startgame.php"; $gameid = start_game($gameid); echo "game " . $gameid . " started"; } elseif (isset($_SESSION["playerid"])) { include "startgame.php";
function main($argv) { # Ensure we've been given a name and a password. if (count($argv) !== 3) { $name = readline("Enter your bot's name: "); $pass = readline("Enter your bot's password: "******"register", ["name" => $name, "password" => $pass]); # Login with the name and password. info("Logging in to the server..."); $json = api("login", ["name" => $name, "password" => $pass]); info("Logged in."); # Store the session from the login for future use. $session = $json["session"]; info("Received session '{$session}'."); while (TRUE) { # Ask to be given an opponent to play against. info("Attempting to start a new game..."); $json = api("new-game", ["session" => $session]); # If there's nobody to play against, start the loop from the top after # waiting 5 seconds. if ($json["result"] === "retry") { echo "?? " . $json["reason"] . "\n"; sleep(5); continue; } # Create an object to represent the cards we have been dealt. $cards = $json["cards"]; info("We have started a new game, and have been dealt: " . implode(", ", $cards) . "."); # Run the game AI. new_game($session, $cards); # Cleanup from our game. info("Our role in this game is over, but we need to be sure the server has ended the game before we start a new one."); info("If we try to start a new game without the old one being done, the server will reject our request."); while (TRUE) { info("Waiting for our game to be over..."); $json = api("status", ["session" => $session]); if (is_null($json["game"])) { break; } sleep(1); } info("The server has ended our game."); } }