Exemplo n.º 1
0
        } elseif ($from == 'RIGHT') {
            $x--;
        }
    } elseif ($type == 10) {
        $x--;
    } elseif ($type == 11) {
        $x++;
    }
    return $x . ' ' . $y;
}
fscanf(STDIN, "%d %d", $W, $H);
$PLACE = array();
for ($i = 0; $i < $H; $i++) {
    $LINE = stream_get_line(STDIN, 200, "\n");
    // represents a line in the grid and contains W integers. Each integer represents one room of a given type.
    $PLACE[] = explode(' ', $LINE);
    //$PLACE[y][x]
}
fscanf(STDIN, "%d", $EX);
// game loop
while (TRUE) {
    fscanf(STDIN, "%d %d %s", $XI, $YI, $POS);
    error_log(var_export($XI . ' ' . $YI, true));
    error_log(var_export($POS, true));
    $type = $PLACE[$YI][$XI];
    error_log(var_export('type = ' . $type, true));
    // Write an action using echo(). DON'T FORGET THE TRAILING \n
    // To debug (equivalent to var_dump): error_log(var_export($var, true));
    echo move_to($XI, $YI, $type, $POS) . "\n";
    //echo("0 0\n"); // One line containing the X Y coordinates of the room in which you believe Indy will be on the next turn.
}
Exemplo n.º 2
0
function move_fleet($mission)
{
    global $uid;
    $fid = $_GET["fid"];
    $targetId = $_GET["targetId"];
    $targetType = $_GET["targetType"];
    // planet || system
    $fleet = new fleet($fid);
    // validation
    if ($uid != $fleet->uid) {
        if ($fleet->milminister == 1) {
            $sth = mysql_query("select a.milminister from users u left join alliance a on u.alliance = a.id where u.id = " . $uid);
            if (!$sth) {
                show_svg_message("ERR::GET MoD");
                return false;
            }
            list($its_mod) = mysql_fetch_row($sth);
            if ($its_mod != $uid) {
                show_svg_message("You can not command that fleet");
                return false;
            }
        } else {
            show_svg_message("You can not command that fleet");
            return false;
        }
    }
    if ($targetType == "system") {
        $destination_system = $targetId;
        $destination_planet = 0;
        $destination_name = get_systemname($targetId);
    } else {
        $sth = mysql_query("select sid, name, uid from planets where id = '{$targetId}'");
        if (!$sth || !mysql_num_rows($sth)) {
            return 0;
        }
        $dest_data = mysql_fetch_row($sth);
        $destination_system = $dest_data[0];
        $destination_name = $dest_data[1];
        $destination_planet = $targetId;
        $destination_planet_uid = $dest_data[2];
    }
    $max_warp = get_max_warp($uid);
    $route = move_to($fleet->sid, $destination_system, $max_warp);
    if (is_array($route)) {
        $fleet_mode = "defensive";
        // gucken ob der zielplanet ein feindlicher ist
        if ($destination_planet != 0 && $destination_planet_uid != 0) {
            if (get_uids_relation($uid, $destination_planet_uid) == "enemy") {
                $fleet_mode = "aggressive";
            }
        }
        set_mission($fid, $mission, $destination_system, $destination_planet);
        $its_mission = get_mission_by_mission_id($mission, $fleet_mode);
        set_route($route, $fid);
        $true_eta = get_true_ETA_by_fid($fid);
        $request .= "<SR_REQUEST oid=\"" . $fid . "\" type=\"FLEET_ROUTE\">";
        $request .= "<SR_ROUTE_INFO eta=\"" . $true_eta . "\" targetName=\"" . $destination_name . "\" sid=\"" . $fleet->sid . "\" mission=\"" . $mission . "\" missionName=\"" . $its_mission[0] . "\" missionSymbol=\"" . $its_mission[2] . "\" />";
        // general info
        if ($fleet->sid == $destination_system) {
            if ($destination_planet == 0 || $fleet->pid == 0) {
                if ($destination_planet == 0) {
                    $target_planet = $fleet->pid;
                    $target_system = $destination_system;
                } else {
                    $target_planet = $destination_planet;
                    $target_system = $fleet->sid;
                }
                $request .= "<SR_ROUTE_SYSTEM_TO_PLANET jumpNumber=\"0\" pid=\"" . $target_planet . "\" sid=\"" . $target_system . "\"/>";
            } else {
                $request .= "<SR_ROUTE_PLANET_TO_PLANET jumpNumber=\"0\" pid1=\"" . $fleet->pid . "\" pid2=\"" . $destination_planet . "\" sid=\"" . $fleet->sid . "\"/>";
            }
        } else {
            // wenn die flotte nicht schon überm stern hängt, muss sie erst dahin fliegen um das system zu verlassen
            $a = 0;
            if ($fleet->pid != 0) {
                $request .= "<SR_ROUTE_SYSTEM_TO_PLANET jumpNumber=\"" . $a++ . "\" pid=\"" . $fleet->pid . "\" sid=\"" . $fleet->sid . "\"/>";
            }
            for ($i = 0; $i < sizeof($route); $i++) {
                $request .= "<SR_ROUTE_SYSTEM jumpNumber=\"" . ($i + $a) . "\" sid=\"" . $route[$i] . "\"/>";
            }
            // wenn die flotte nicht zum einem anderen stern fliegt, sondern zu einem planeten, kommt noch ein inter-planetärer flug hinzu
            if ($destination_planet != 0) {
                $request .= "<SR_ROUTE_SYSTEM_TO_PLANET jumpNumber=\"" . ++$i . "\" pid=\"" . $destination_planet . "\" sid=\"" . $destination_system . "\"/>";
            }
        }
        $request .= "</SR_REQUEST>";
        echo $request;
        return true;
    } else {
        show_svg_message("Sir! Our fleet '" . get_fleet_name($_GET["fid"]) . "' can't carry out your command. The targets destination has an insuperable gap that exceeds our warp technolgy of " . $max_warp . " parsec.");
        return false;
    }
}