id = $items[0]; $game->p1 = $items[1]; $game->p2 = $items[2]; $game->p1_cookie = $items[3]; $game->p2_cookie = $items[4]; $game->moves = $items[5]; $result[$game->id] = $game; } } return $result; } function game_new() { $response = game_server('N'); return $response[0]; } function game_join($igame) { $response = game_server("J $igame"); return $response[0]; } function game_command($igame, $cookie, $command) { $response = game_server("C $igame $cookie $command"); if (is_string($response)) { return false; } $result = new Game(); $result->id = $igame; $i = 0; $result->finished = $response[$i++]; $result->moves = $response[$i++]; $result->active_player = $response[$i++]; $result->captured[false][0] = $response[$i++]; $result->captured[false][1] = $response[$i++]; for ($j = 0; $j < 12; $j++) { $result->houses[false][$j] = $response[$i++]; } $result->status = $response[$i++]; $result->error = $response[$i++]; # Inverted results $result->captured[true][0] = $result->captured[false][1]; $result->captured[true][1] = $result->captured[false][0]; for ($j = 0; $j < 6; $j++) { $result->houses[true][$j] = $result->houses[false][$j + 6]; $result->houses[true][$j + 6] = $result->houses[false][$j]; } return $result; } function game_delete($igame) { $response = game_server("J $igame"); $cookie = $response[0]; game_command($igame, $cookie, 'q'); } function redirect($location) { header("Status: 302 Redirect\r\n"); header("Location: $location\r\n\r\n"); exit(0); } function house_image($house) { if ($house > 18) { $house = 18; } $files = glob(dirname(__SCRIPT__) . "/images/$house/*.png"); $file = $files[rand(0, count($files) - 1)]; return $file; } ?>