Patch for AI #1

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

Moderator: Committer

Post Reply
Message
Author
User avatar
OndrejR
Space Dragon
Posts: 339
Joined: Thu Oct 02, 2008 11:00 pm
Location: Slovakia

Patch for AI #1

#1 Post by OndrejR »

I created patch for AI:
-fixed problem with exploring new stars with AI scouts after game load
-added new functions for PythonUniverseWrapper.cpp
-fixed TODO syntax
-moved explorable systems from ExplorationAI to AIState from TODO work, later it will be reused from ColonizationAI and others
-preparation for Fog of war
-removing some unnecessary free space
Attachments
AI_1.zip
(5.51 KiB) Downloaded 128 times

User avatar
OndrejR
Space Dragon
Posts: 339
Joined: Thu Oct 02, 2008 11:00 pm
Location: Slovakia

Re: Patch for AI #1

#2 Post by OndrejR »

Any objections why not to commit?

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

Re: Patch for AI #1

#3 Post by Geoff the Medio »

I saw this, but haven't yet looked it over. I'll get to it soon.

User avatar
pd
Graphics Lead Emeritus
Posts: 1924
Joined: Mon Mar 08, 2004 6:17 pm
Location: 52°16'N 10°31'E

Re: Patch for AI #1

#4 Post by pd »

Does this take fuel into account?

User avatar
OndrejR
Space Dragon
Posts: 339
Joined: Thu Oct 02, 2008 11:00 pm
Location: Slovakia

Re: Patch for AI #1

#5 Post by OndrejR »

pd wrote:Does this take fuel into account?
Not yet. But I intend to do it in future. This will be series of AI patches(when I have free time and motivation to do something for FO). It is always better to do a lot of patches than one huge(others can also participate) which may become absolete. But in this patch there is only solved problem after saving and loading game(then AI scouts do absolutely nothing, when game is not saved and loaded, then scout run out of fuel).

User avatar
eleazar
Design & Graphics Lead Emeritus
Posts: 3858
Joined: Sat Sep 23, 2006 7:09 pm
Location: USA — midwest

Re: Patch for AI #1

#6 Post by eleazar »

It is always better to do a lot of patches than one huge(others can also participate) which may become absolete.
generally, yes:
release early, release often.

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

Re: Patch for AI #1

#7 Post by Geoff the Medio »

Committed.

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

Re: Patch for AI #1

#8 Post by The Silent One »

pd wrote:Does this take fuel into account?
OndrejR wrote:Not yet. But I intend to do it in future.
To avoid that the AI's ships run out of fuel the AI would best be able to stack fleet actions (e.g. send scout to system A to refuel, then send to system B to explore). Since order stacking is not being supported by the main code yet, it would have to be coded within the AI code. I quickly browsed through the AI interface and everything required seems to be exposed (fleet.fuel and maxFuel, universe.leastJumpsPath).
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
OndrejR
Space Dragon
Posts: 339
Joined: Thu Oct 02, 2008 11:00 pm
Location: Slovakia

Re: Patch for AI #1

#9 Post by OndrejR »

The Silent One wrote:To avoid that the AI's ships run out of fuel the AI would best be able to stack fleet actions (e.g. send scout to system A to refuel, then send to system B to explore). Since order stacking is not being supported by the main code yet, it would have to be coded within the AI code. I quickly browsed through the AI interface and everything required seems to be exposed (fleet.fuel and maxFuel, universe.leastJumpsPath).
It's no so simple. There is also need for distance between systems and better function is ShortestPath. We don't want path with least jumps, but with least distance. And there is also problem with supply range. In the supply range there is no need to take fuel into consideration, but in out of supply area AI need this information(from fleetSupplyableSystems from PythonEmpireWrapper.cpp).

And there is also another problem - if system A leads only to system B and system B leads to only A and C, then explore B means also explore system C with same scout(these problems are resolved by graph theory). For additional info see book Graph Theory by Reinhard Diestel. In graph theory this problem is named Hamiltonian path.

Problem is also with enemy systems - system A leads to B and D, B leads to A and C, C leads to B and D. System B is enemy system and distance from A to D is large. Also another graph theory problem(Dijkstra algorithm is in boost and it is function ShortestPath, but this function doesn't solve problem because all systems are connected graph). Probably some Python graph theory library will be required.

I am trying to say that all these AI problem only seems simple. They aren't. But to solve them we must begin with simple things and later solve all difficulties.

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

Re: Patch for AI #1

#10 Post by The Silent One »

OndrejR wrote:I am trying to say that all these AI problem only seems simple. They aren't. But to solve them we must begin with simple things and later solve all difficulties.
I certainly agree that this will not be a simple task. My intention was to point out where might be a good point to start (implementing the ability to stack fleet orders), not an in-depth analysis of the galaxy map AI code.
The main trouble I ran into when writing the few bits of AI that are there now was that some methods had not been exposed to python (although Geoff helped quickly), so I wanted to check for you if the very basics are there, that's all.
OndrejR wrote:There is also need for distance between systems and better function is ShortestPath. We don't want path with least jumps, but with least distance.
As fuel usage currently equals star lane jumps, leastJumpsPath will return the most fuel-efficient path rather than ShortestPath. The latter could be used when enough fuel is at hand and speed is essential, e.g. within supply range, but if the question is if a ship can visit a star system and return to a supply point, leastJumpsPath should be the way to go.

Anyway, you seem to have insight into the involved intricacies, so I'm looking forward to what you'll create.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

mZhura
Space Kraken
Posts: 168
Joined: Sun Sep 27, 2009 10:51 am
Location: Moskow, RU

Re: Patch for AI #1

#11 Post by mZhura »

Don't you think about making fuel to be spended on ETA rather then starlanes?

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

Re: Patch for AI #1

#12 Post by Geoff the Medio »

mZhura wrote:Don't you think about making fuel to be spended on ETA rather then starlanes?
It's not clear what you're suggesting or asking, but if it was about making fuel costs depend on distance travelled, yes it was considered, but we chose instead to make fuel consumption depend on number of starlane jumps.

Post Reply