Opened 13 years ago

Closed 10 years ago

#973 closed enhancement (fixed)

[PATCH] Add naval / water map support to AIs

Reported by: alexhultman Owned by: mimo
Priority: Should Have Milestone: Alpha 17
Component: AI Keywords:
Cc: wraitii Patch:

Description (last modified by historic_bruno)

The AI should build a dock, train a boat and then attack when it feels like it has a strong army.

Attachments (2)

naval-manager.diff (6.4 KB ) - added by Darth_Malloc 10 years ago.
petra-navalManager.diff (824 bytes ) - added by Darth_Malloc 10 years ago.

Download all attachments as: .zip

Change History (41)

comment:1 by historic_bruno, 13 years ago

Milestone: Alpha 8Backlog

This is a more general problem with the AIs and not specific to Jubot: they assume that every point is reachable from every other point. That means they fail in lots of situations, but especially water maps where resource and enemy targets can be unreachable by land units. The easier part of the problem seems like providing the AIs information about which parts of the map are reachable (and by what types of units), and the harder part is the logic to actually handle docks, boats, trading, and invasions.

comment:2 by historic_bruno, 12 years ago

Component: Core engineUI & Simulation
Summary: JuBot doesn't get that it takes a boat to attack another islandAdd naval / water map support to AIs
Type: defectenhancement

comment:3 by Darth_Malloc, 11 years ago

Owner: set to Darth_Malloc
Status: newassigned

in reply to:  3 comment:4 by historic_bruno, 11 years ago

Replying to Darth_Malloc:

Any progress on this?

comment:5 by Darth_Malloc, 11 years ago

I am working on getting qubot to build docks. Will have code to post on the weekend. Sorry about the back-to-work button. Got a bit lost in the code and was not sure about asking for help.

comment:6 by fabio, 11 years ago

Cc: wraitii added

Is wraitii also working on this on aegis? Also is qbot planned to be removed?

comment:7 by wraitii, 11 years ago

I am working on this on Aegis. It looks fairly good. I plan to remove qBot in A15 if all goes well.

comment:8 by fabio, 11 years ago

Milestone: BacklogAlpha 15

comment:9 by Darth_Malloc, 11 years ago

Which part of this task are you doing far aegis? I was going to improve the common to allow naval functionality. Should I ignore qbot, or go ahead editing it as planned?

in reply to:  9 ; comment:10 by historic_bruno, 11 years ago

Replying to Darth_Malloc:

Which part of this task are you doing far aegis? I was going to improve the common to allow naval functionality. Should I ignore qbot, or go ahead editing it as planned?

All AIs except Aegis are deprecated now. You really shouldn't do any work on qBot if it can be avoided. For Aegis, as I understand, a major rewrite is in progress for A15 or later, so it may simply be a bad time to do AI work, unless you want to write a new AI. (though perhaps wraitii can do the work on Github or something, and then you can collaborate and avoid wasted effort)

in reply to:  10 comment:11 by Darth_Malloc, 11 years ago

That sounds like a good plan. In the mean time, I will focus on correcting the pathfinding algorithm for naval units so that they are able to "come about" in a realistic manner, since I think that this issue will be an important consideration in developing the AI naval strategies. I should tell you that I will be traveling from the 25th to the 30th, and while I will work on it before then, I may not post anything until after my trip.

Replying to historic_bruno:

Replying to Darth_Malloc:

Which part of this task are you doing far aegis? I was going to improve the common to allow naval functionality. Should I ignore qbot, or go ahead editing it as planned?

All AIs except Aegis are deprecated now. You really shouldn't do any work on qBot if it can be avoided. For Aegis, as I understand, a major rewrite is in progress for A15 or later, so it may simply be a bad time to do AI work, unless you want to write a new AI. (though perhaps wraitii can do the work on Github or something, and then you can collaborate and avoid wasted effort)

comment:12 by wraitii, 11 years ago

Darth_Malloc: sounds good. I know my AI code well enough that working on AI-naval side will probably be easier, but anything that the AI would not act upon directly is out of my scope right now.

comment:13 by Darth_Malloc, 11 years ago

Fair enough. I have no training in AI programming, but I feel capable of learning as I go, and would like to do so. Any thoughts on how we ought to divide the task?

comment:14 by wraitii, 11 years ago

Well I've started working on "transport plans" which would basically handle AI transportation over water… There is some code for placing docks but it could be refined. It'd need code for naval fighting and stuffs like that if you're interested.

in reply to:  14 comment:15 by Darth_Malloc, 11 years ago

That sounds good. I was already working on a few ideas to improve the process for placing docks, one of which would a function by which the terrain pathfinder would isolate coastal ocean tiles (adjacent to shore) to make it easier to select dock spaces. Do you think this would help. I would be very keen to work on the naval combat functionality, as well as the fishing behaviour. AI work is still new to me, and for the next little while things will be a bit hectic with travelling and graduate school, so things may be a bit slow, but I will do my best.

Replying to wraitii:

Well I've started working on "transport plans" which would basically handle AI transportation over water… There is some code for placing docks but it could be refined. It'd need code for naval fighting and stuffs like that if you're interested.

comment:16 by wraitii, 11 years ago

Work will slow down for me too once I get back to school so that's probably not an issue. Current dock placement by the AI is similar to this but I guess it could always be improved. I'd certainly be interested by what you come up for fishing and naval fighting. I'd recommend you start by a conceptual idea, so that I can tell you how easy it'd be to do with the current architecture/how to hook it up more easily.

in reply to:  16 comment:17 by Darth_Malloc, 11 years ago

Sorry about the silence at my end. I am back now. In terms of fishing behaviour, I would add a seeking function for fishing ships. It would basically be a modified version of TerrainAnalysis.prototype.findClosestPassablePoint insofar as it would use a spiral algorithm to search a location that corresponds to the location of a resource entity that is of the fish type, with the loop terminating when a fish resource is located. The ship will repeat this whenever it is idle, i.e., when it is first created, and when it has polished off the current fish resource. An aggressive AI would venture ever further as long as there were still fish resources, while a cautious one would limit its reach. Still trying to come up with some good plans for naval combat behaviour.

Replying to wraitii:

Work will slow down for me too once I get back to school so that's probably not an issue. Current dock placement by the AI is similar to this but I guess it could always be improved. I'd certainly be interested by what you come up for fishing and naval fighting. I'd recommend you start by a conceptual idea, so that I can tell you how easy it'd be to do with the current architecture/how to hook it up more easily.

comment:18 by wraitii, 11 years ago

Darth_Malloc: FYI currently AIs can see in the FOW so you could just go to the fish directly, but it's good if you have a good solution to avoid that cheating. We'll have to make sure it's reasonaby fast.

You can check what I added for naval support in the "Further AI Development" thread in the development forum.

in reply to:  18 comment:19 by Darth_Malloc, 11 years ago

I think that what you have done on the the transport functionality looks good. I am doing some coding on the fishing behaviour, though I am a noob when it comes to AI, so I am not fully certain that I am doing it correctly. My thinking, however, is this: when a new dock is built, it should get a queue of fishing spots from closest to farthest. Fishing ships should have a homePort attribute with the ID of the dock that created them, and they should follow the queue of that particular dock. I will try to come up with a way to implement LOS and FOW, and if I succeed, then the queue would be restricted to that which is visible to the AI, updating as the map is explored.

Replying to wraitii:

Darth_Malloc: FYI currently AIs can see in the FOW so you could just go to the fish directly, but it's good if you have a good solution to avoid that cheating. We'll have to make sure it's reasonaby fast.

You can check what I added for naval support in the "Further AI Development" thread in the development forum.

comment:20 by historic_bruno, 10 years ago

Description: modified (diff)
Milestone: Alpha 15Backlog

Any progress on this, any patch or git fork we can see that shows even the least active development?

by Darth_Malloc, 10 years ago

Attachment: naval-manager.diff added

in reply to:  20 comment:21 by Darth_Malloc, 10 years ago

Description: modified (diff)
Keywords: review patch added
Milestone: BacklogAlpha 16

Replying to historic_bruno:

Any progress on this, any patch or git fork we can see that shows even the least active development?

Sorry for the delay. Things have been quite hectic at school. I have made some changes to naval-manager so that it should account for the naval options of all existing civilizations. The only snag that I have hit is that I am unsure of a quick way to determine if an entity (namely a dock or a fishing spot) is in the boundaries of a particular region. If someone would be willing to clarify this, I would then be able to enhance the naval-manager to determine accessibleSeas, and to implement the algorithm that I have been planning to coordinate fishing.

comment:22 by historic_bruno, 10 years ago

Thanks for the update :) We just have to make sure that someone hasn't abandoned a ticket and neglected to update it, as that prevents others from picking up the task.

You might try stopping by IRC, perhaps one of the devs can help you, or wraitii might be there as well. For Aegis specific questions, wraitii will definitely be the one to ask, he may be too busy to read the Trac emails.

comment:23 by historic_bruno, 10 years ago

Description: modified (diff)
Summary: Add naval / water map support to AIs[PATCH] Add naval / water map support to AIs

in reply to:  22 comment:24 by Darth_Malloc, 10 years ago

Replying to historic_bruno:

Thanks for the update :) We just have to make sure that someone hasn't abandoned a ticket and neglected to update it, as that prevents others from picking up the task.

You might try stopping by IRC, perhaps one of the devs can help you, or wraitii might be there as well. For Aegis specific questions, wraitii will definitely be the one to ask, he may be too busy to read the Trac emails.

I hope that my additions to the code will be of help. Please let me know if what I have done can be used, and if any changes to it are necessary. In the meantime I will try to contact wraitii.

comment:25 by wraitii, 10 years ago

Darth_Malloc: it's been a while since I last used my naval manager, but I think calling "this.accessibleSeas.indexOf(gameState.ai.accessibility.getAccessValue(YourUnit.position()))" should do the trick. It's somewhat buggy if things are too close to the shore though as it sometimes return a land index (which is a general issue with the naval manager but shouldn't affect fishing too much).

comment:26 by sanderd17, 10 years ago

Keywords: review removed
Milestone: Alpha 16Alpha 17

Taking it off the review queue, as it's clearly not complete now.

in reply to:  26 comment:27 by Darth_Malloc, 10 years ago

Replying to sanderd17:

Taking it off the review queue, as it's clearly not complete now.

Sorry about that. Am on it now. Thesis work was pressing. I think that it might help if someone would be able to create a hierarchy map with documentation for the AI, similar to the one that already exists for the source code. It would then be quicker to find one's way around the code.

comment:28 by Gabriel, 10 years ago

it's possible to get somewhat like builds being used by the players of the game it would be really useful, because we could use that info to make the AI of the game more adaptive instead of hard coding a bunch of cases, it's only an idea Gabriel.

Last edited 10 years ago by Gabriel (previous) (diff)

in reply to:  28 comment:29 by Darth_Malloc, 10 years ago

I am not sure that I am interpreting you correctly, but I was referring to something a little different. What I meant was more along the lines of a documentation for the AI script similar to that which already exists for the source code. That would make it easier to navigate the script.

Replying to nanoxas:

it's possible to get somewhat like builds being used by the players of the game it would be really useful, because we could use that info to make the AI of the game more adaptive instead of hard coding a bunch of cases, it's only an idea Gabriel.

comment:30 by Darth_Malloc, 10 years ago

Code for AI fishing behaviour in the works right now...

comment:31 by mimo, 10 years ago

Darth_Malloc: I'm not sure what are the plans now on adding more features to Aegis. You should first discuss with wraitii before doing more developments. In the last months, I've developped Petra which is based on Aegis, but contains many improvments and new features. In particular, in my private version (I'm waiting for the A16 release to commit it), it has fishing and island colonization, so a big part of naval support is already there (fighting over seas is still missing, but in progress). If you think that you have more time now to work on this subject, we should try to coordinate a bit what each of us is doing.

comment:32 by Darth_Malloc, 10 years ago

I agree with you there. I will have even more time during the summer when my grad thesis is all done, and and that time I would be interested to see what you have done of Petra, and if there is any way that I might help.

by Darth_Malloc, 10 years ago

Attachment: petra-navalManager.diff added

comment:33 by Darth_Malloc, 10 years ago

Added a bit to the petrabot naval manager. Will do more over the next few days. Should I do anything for Aegis, or has it been abandoned completely?

comment:34 by mimo, 10 years ago

Good if you now have more time to work on it.

Concerning Aegis, I think the best is to not do anything about it for the time being: naval support did not worked on it, and I think that once we have something satisfactory in Petra, implementing it in Aegis if needed would only require copying the Petra navalManager and transportPlan files plus some minimal changes in the Aegis steering.

Concerning your work on petra, do you already have some plans of what you want to add, and how ?

in reply to:  34 comment:35 by Darth_Malloc, 10 years ago

Replying to mimo:

Good if you now have more time to work on it.

Concerning Aegis, I think the best is to not do anything about it for the time being: naval support did not worked on it, and I think that once we have something satisfactory in Petra, implementing it in Aegis if needed would only require copying the Petra navalManager and transportPlan files plus some minimal changes in the Aegis steering.

Concerning your work on petra, do you already have some plans of what you want to add, and how ?

Over the next little while, I will work on getting the naval manager to locate fishing spots in accessible seas, and planning the order in which it will gather from them. On that note, I am wondering if there is a function to quickly check the distance between two entities. Regarding my last update, I hope to do better next time, so I was wondering if you could tell me if there were any problems that would prevent it from working with the existing code.

comment:36 by mimo, 10 years ago

But have you played recently on naval maps ? fishing is already implemented, and works quite nicely. But it is done in the worker.js (because the code was almost identical to the hunting one), only the management of the number of fishing ships in done in the navalmanager.

What is missing though is to have some ways to say that some fishing zones are dangereous (nearby an enemy tower or fortress for example). But as it is something of general use which is needed for all gatherers, and also for attack troops when landing, I was thinking of implementing a dangerMap which would locate all these dangerous locations. That's something which would be quite useful if you are interested ?

If you prefer to stay with naval warfare, what is missing is the use of ship for fighting (either to clean a bit the landing-zone before landing its troops, or to fight against enemy ships). Only transport is implemented now. That's also something which would be nice to work on..

comment:37 by Darth_Malloc, 10 years ago

I would definitely be interested in working on the fishing dangerMaps and naval warfare, and would like to try getting the ai to try some cunning methods, like attacking fishing ships just to lure out the enemy navy and then decimate it.

I will stay with naval warfare for now, but would also be interested in working on land combat at a slightly later point.

comment:38 by mimo, 10 years ago

Component: UI & SimulationAI
Keywords: patch removed
Owner: changed from Darth_Malloc to mimo
Status: assignednew

Closing as the AI has now naval map support. There is still some work to do to improve it, but it should be done through dedicated tickets.

comment:39 by mimo, 10 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.