Exploration AI

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Exploration AI

#1 Post by The Silent One »

I'd like to propose a slight change to the AI code that will allow the AI player to explore multiple systems if it has more than one fleet. I've simply introduced a variable that keeps track of how many fleets have already been sent to explore. All changed lines have been marked with (#!).

Code: Select all

 # get stationary fleets

    fleetIDs = getEmpireStationaryFleetIDs(empireID)
    print "fleetIDs: " + str(fleetIDs)

    # order stationary fleets to explore
    fleets_sent = 0 #! keeps track of number of fleets that have been sent to explore

    for fleet_id in fleetIDs:

        fleet = universe.getFleet(fleet_id)
        if (fleet == None): continue

        startSystemID = fleet.systemID
        if (startSystemID == universe.invalidObjectID): continue

        systemIDs = getExplorableSystemIDs(startSystemID, empireID)

        if (len(systemIDs) > fleets_sent): #!

            destinationID = systemIDs[fleets_sent] #! 

            fo.issueFleetMoveOrder(fleet_id, destinationID)
            fleets_sent = fleets_sent + 1 #!
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Exploration AI

#2 Post by Geoff the Medio »

It would be better to keep a set or list of all systems to which fleets have been sent. When picking a system for each fleet to explore, you'd get the list of explorable systems, then iterate through it and check if each system has already had a fleet sent. If the system being considered has had a fleet sent, then you'd go to the next system in the list until you find one that hasn't had a fleet sent, and would then send the fleet there (and record this fact).

The reason the startSystemID is a parameter to getExplorableSystemIDs is because it's possible (not now, but eventually) for an empire's ships to be located in separate subsections of the empire which aren't connected by any known starlanes. Also, we might later update getExplorableSystemIDs to take into account that a ship in the start system would have to pass through undesirable systems (eg. enemy-occupied) to get somewhere, which makes some systems not explorable, even if they're technically starlane-connected. In either case, the number of ships sent in one subsection shouldn't affect the picking of systems from the list for the other subsection(s). Granted, for now your suggestion would work fine... but my suggestion here isn't that much more complicated.

User avatar
The Silent One
Graphics
Posts: 1129
Joined: Tue Jul 01, 2003 8:27 pm

Re: Exploration AI

#3 Post by The Silent One »

Geoff the Medio wrote:It would be better to keep a set or list of all systems to which fleets have been sent.
That sounds reasonable. However, there is one thing that troubles me: what if a fleet is given an exploration order - this is recorded in a list (let's say, systems_being_explored) - and then is destroyed before it can finish its mission? Since the AI still believes a fleet is en route, it would never again send a fleet to explore the system. To avoid this, if a fleet is destroyed that was sent to explore a system, its destination must be removed from the list.

Also, on exploration systems should be removed from systems_being_explored, so that the list really only holds systems that are being explored, and not also systems that have been explored; so that if a system, for some reason whatsoever (event, veiling tech, ...), becomes unexplored again, the AI will send ships.

systems_being_explored should be a field of every AI client and initialized with the AI constructor.

Code: Select all

 # get stationary fleets

    fleetIDs = getEmpireStationaryFleetIDs(empireID)

    print "fleetIDs: " + str(fleetIDs)

    # order stationary fleets to explore
    for fleet_id in fleetIDs:

        fleet = universe.getFleet(fleet_id)
        if (fleet == None): continue

        startSystemID = fleet.systemID
        if (startSystemID == universe.invalidObjectID): continue

        systemIDs = getExplorableSystemIDs(startSystemID, empireID)

       # iterate through systemIDs and remove systems that are being explored
        for ID in systemIDs:
          if (ID in systems_being_explored):
            systemIDs.remove(ID)

        if (len(systemIDs) > 0):
            destinationID = systemIDs[0]  # could be removed
            fo.issueFleetMoveOrder(fleet_id, destinationID)
            systems_being_explored.append(destinationID)
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
Flatline
Space Squid
Posts: 64
Joined: Tue Jan 29, 2008 2:06 pm
Location: Oxford (UK)

Re: Exploration AI

#4 Post by Flatline »

But shouldn't the AI periodically visit already visited systems to see "what's going on" (i.e. if it has been colonized, if other races are amassing forces there...)?
The only difference between a suicide and a martyrdom is press coverage.
- Chuck Palahniuk (Survivor)

Ubuntu 7.10/Windows Vista/Windows XP (VMWare)/Windows NT 4 (VMWare) on Intel Centrino Duo [email protected] with NVidia GeForce GO 7600

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Exploration AI

#5 Post by Geoff the Medio »

Flatline wrote:But shouldn't the AI periodically visit already visited systems to see "what's going on" (i.e. if it has been colonized, if other races are amassing forces there...)?
Yes, but:
1) This is just a make-it-a-bit-better discussion, not a build-a-perfect-AI discussion... The AI should really also build ships and research stuff, but that's a bigger chunk of work than a relatively small tweak to improve the existing exploration script.

2) The current visibility model is a bit limited, and you can always see what's going on in any system you've explored, even if you have no ships or planets there this turn. So, there's no need to go back just to check things out... This will presumably change, but the simplest solution used in earlier releases remains as of now.

User avatar
Flatline
Space Squid
Posts: 64
Joined: Tue Jan 29, 2008 2:06 pm
Location: Oxford (UK)

Re: Exploration AI

#6 Post by Flatline »

Ah ok sorry, I misunderstood your post and thought it was more a "generic" discussion, not one tailored to this "temporary" AI :)
The only difference between a suicide and a martyrdom is press coverage.
- Chuck Palahniuk (Survivor)

Ubuntu 7.10/Windows Vista/Windows XP (VMWare)/Windows NT 4 (VMWare) on Intel Centrino Duo [email protected] with NVidia GeForce GO 7600

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Exploration AI

#7 Post by Geoff the Medio »

Flatline wrote:Ah ok sorry, I misunderstood your post and thought it was more a "generic" discussion, not one tailored to this "temporary" AI :)
There are other threads on that topic.

Post Reply