|
Author
|
|
Topic: Map AI coding |  |
|
brian32 Settler
Feb 2001
|
 |
posted February 12, 2001 21:12
 |
 |
 |  |
This topic is about the code for the map AI that I'm working on. It is going to be geared toward the coding end of it, as opposed to the concepts end.The coding will be in four main sections. These can be found in more detail in the Map AI Model page. The sections are as follows: 1) Define the borders of continents/bodies of water/etc. 2) Define "hotspots" (strategic points) within each of these continents/oceans/etc. 3) Divide the contintents into sections according to the hotspots and define the borders of each section 4) Determine the size of each section, nearby sections, inlets, outlets, strategic value, etc. for each section This is obviously only a broad overview, and much more detail will be involved. I will periodically be posting code and tests on here as I make them. Any suggestions, contributions, criticisms, tips, etc. would be greatly appreciated. [This message has been edited by brian32 (edited February 12, 2001).] |
brian32 Settler
Feb 2001
|
 |
posted February 12, 2001 21:16
 |
 |
 |  |
Here is some skeleton code I made for how the continents will be assigned regions:public class Regions { protected numberOfRegions = 0; // Selects a random coordinate on the map public getArbitraryPoint() { int x = math.random(); int y = math.random(); } // Assigns the next region name to the random coordinate selected public assignRegion( int x, int y) { MapLocation.region = numberOfRegions + 1; this.numberOfRegions ++; } public floodFillRegion( int x, int y, int region ) { // // Algorithm to assign region number to all // squares around the arbitrary point selected. // } }
|
Mark_Everson Clash of Civilizations Project Lead Canton, MI, USA b.02-15-99
|
 |
posted February 12, 2001 21:42
  |
 |
 |  |
Hi Brian:I'm glad you're working on the map AI area! AI is something near and dear to my heart, and I think we can make Clash really unique in at least one way by doing a decent job with the AI. If you're interested, you can also sign up as an official team member in the Team Members thread. It's probably near the bottom of the front page at this point. I've only got one minor comment on what you have written so far. It occurs to me that using random locations to start the flood fill algorithm for continents etc. would be okay until you have most of the map identified. But using random locations to find that little one-square lake remaining to be identified could be exceptionally time-consuming. I have an idea for a fairly efficient algorithm... and it only uses things you'll need to code anyway mostly. 1. Start at some location on the map and tag it using the flood fill algorithm. I'll call this the "active" area. 2. For all boundary squares in the active area, initiate the flood fill algorithm on anything that's not marked, each in turn, giving you n additional areas. Once the active area has nothing unidentified next to it make each of these n "nearest neighbor" areas the active one. 3. Continue this process until the entire map is partitioned. I think this should be much quicker than just doing it randomly... |
LDiCesare Chieftain La Ferté sous Jouarre France Jan 2001
|
 |
posted February 13, 2001 02:09
 |
 |
 |  |
Hi all. Mark's idea sounds good to me. The random part is used for the initial seeds. Just beware not tagging twice the same point. The nearest neighbour should be implemented carefully though, because if you just use 4 or 8 adjacent squares as neighbours, you'll end up with many long vertical and horizontal borders, linked by a few 45 degrees sections. Using distance to initial seed gives more varied boundaries (Voronoi algorithm) and is probably better in terms of performance since you can go through the map only once. |
Mark_Everson Clash of Civilizations Project Lead Canton, MI, USA b.02-15-99
|
 |
posted February 13, 2001 06:41
  |
 |
 |  |
Hi Laurent:To clear up a possible misapprehension (although I may just be misunderstanding your post)... Brian is talking about the map Analysis routine for use on already-generated maps. That's completely distinct from map geration, which is what I thing you are talking about... That is why floodfill is ok. For anyone who is interested the Map Generator Discussion is here: http://apolyton.net/forums/Forum21/HTML/000141.html . The thread is quite old, but it still represents where we are on map generation. Mca's old links in the thread don't work, but we still have the source code he did, and maybe the pix somewhere too...
[This message has been edited by Mark_Everson (edited February 13, 2001).] |
Lord God Jinnai Prince Arnold, Mo 63010 Sep 1999
|
 |
posted February 13, 2001 10:42
  |
 |
 |  |
I think istead of figuring out where land/water is, you should instead figure out where the continental shelfs are and the height of the land masses in a given area and then the water level.The reason i say this is because several models depend on the continental shelf as opposed to the ocean floor and you'll need to figure out height eventually so in the long run it'll be easier IMO to do it this way. |
LDiCesare Chieftain La Ferté sous Jouarre France Jan 2001
|
 |
posted February 14, 2001 03:10
 |
 |
 |  |
Silly me. I didn't understand the topic. Now that I have read the model (I should have done that first) I put new comments: Why do you use random at all? You could use an algo like start at squre (0,0), mark as 0 , then look (0,1): if same type (land/sea) mark as neighbor, else mark as newRegion (here 1). Go on that way. When you are in (i,j) (i>0), you look at the various neighbors (3 on top, 1 on left): if all are of a different type, spawn a new region. If all are the same type and the same label, use the label. If there are several different labels for the same kind of terrain, you know that they are actually the same, so you can put whatever label for the current square, and store in a table the fact that the labels are only one region. e.g. if 0 is sea, 1 is land on the following map (don't wrap borders here to make it simpler): Left the map, then first stage labels, last, regions deduced: 00100011100 . 00122233344 00100033344 01110001001 . 01112223445 01110003443 01100001111 . 01122223333 (5=3) 01100003333 00110000101 . 00112222363 00110000303 00000110011 . 00000770033 (2=0,6=0) 00000770033 01001110000 . 08007770000 07007770000 01111100000 . 08887700000 (8=7) 07777700000
That way you flood-fill a whole map in one pass (I showed three images, but the third can be deduced from the second without going pixel-by-pixel). That is interesting also because when restricting yourself to a subpart of a map (what is known to AI x) you could have trouble generating random seeds inside it. Here you can even mark "unknown" as one or more regions. I hope this is more to the point.[This message has been edited by LDiCesare (edited February 14, 2001).] [This message has been edited by LDiCesare (edited February 14, 2001).] [This message has been edited by LDiCesare (edited February 14, 2001).] |
Mark_Everson Clash of Civilizations Project Lead Canton, MI, USA b.02-15-99
|
 |
posted February 14, 2001 21:24
  |
 |
 |  |
Yeah, your way might be more efficient, but mine wouldn't leave those messy holes in the numbering sequence  |
brian32 Settler
Feb 2001
|
 |
posted March 24, 2001 17:51
 |
 |
 |  |
Hi, everybody. Sorry for not making a post in a while.An update of what I've been working on: 1) I've been expanding my skeleton code, taking into account your suggestions. I'll post some of it for you to see in a little while. I've run into a few minor problems so far. One of those is that we need to decide on a value for path intensity to determine what is a 'hotspot' and what is not. (If you don't know what I'm talking about, please read the Map AI model). Another thing is we need to decide what the most efficient way to do the floodfill will be. That will be a little tough to determine without a way to test the methods... 2) I've also been working on creating an interface to test my code. I would like to make something similar to the applet JimC created. However, I was unable to get his source code. I am not a very experienced graphical programmer, so any help in this area would be much appreciated. As usual, I'm open to any suggestions or criticism. |
Mark_Everson Clash of Civilizations Project Lead Canton, MI, USA b.02-15-99
|
 |
posted March 24, 2001 19:28
  |
 |
 |  |
Hi Brian, thanks for the heads-up.Well, I guess there are several criteria that are important in figuring out which the most important hotspots are. I'm not sure if I mentioned it yet, but I think the best use of the algorithm would have the modification in the bullet that has "suggested by Tim Smith" on the web page. That approach spreads out "path intensity" fairly efficiently IMO. So with that said... the really important hotspots should: 1. Be the ones that divide a region into sub-regions (otherwise they can just be gotten around some way) so a bonus should be given to hotspots importance if it divides a region into two sub regions. If the hotspots doesn't satisfy that condition then it shouldn't get the bonus. 2. Have a fairly large fraction of all paths going through them. Maybe we should start with 20% or more as a rule of thumb. 3. Big continents will need more hotspots kept track of than small ones. This will aid a lot in pathfinding. So as a starting guess, you could write a function that takes the three considerations above, with some weighting between them, to figure out at what level you want to not bother with hotspots anymore. I could make something up on the spot, but given the fact that you are working with the topic directly, and can evaluate your ideas fairly quickly, I'd prefer to have you take a shot at it first . If you get stuck, let me know and I'd be happy to help out. I will try to get your Clash handle going soon. On the last set I had some trouble mailing Markos and Dan, so I'm going to wait for yours until it's clear they are getting my messages. |
brian32 Settler
Feb 2001
|
 |
posted March 24, 2001 20:03
 |
 |
 |  |
I understood most of that already, I was just curious to see if people would have input as to what those actual values (like the bonuses and percentages) and weightings should be. I realize its not very important at this point and it can only be decided by testing, but I wanted to get people thinking about it so we can have some idea of what we want when the testing starts so it goes rather quickly.It will be nice if right on the interface we could have a text box where we could put in the values of what decides hotspots. That would be much better than having to go in and change the code, then recompile, every time we want to test a new value. It shouldn't be very difficult and I will try to do it, but I'm not making any promises. Anyone else is welcome to help out. |
LDiCesare Chieftain La Ferté sous Jouarre France Jan 2001
|
 |
posted March 25, 2001 07:24
 |
 |
 |  |
Browsing the web, I found pages describing "influence mapping". That is very much like our model except it takes into account only the units. I think it could be used for a more tactical level AI: Current model can give ideal goals, strategic, long-term, importance of terain, while influence mapping can help tell current strategical strengths and weaknesses. The algorithms seem very much alike. What do you guys think? |
Mark_Everson Clash of Civilizations Project Lead Canton, MI, USA b.02-15-99
|
 |
posted March 25, 2001 09:10
  |
 |
 |  |
Agree. That has been in mind all along, but not written up . If we can do a good job on what we have planned so far, it will be, like you say, fairly straightforward to do the influence stuff. |
JimC Clash of Civilizations AI Coding Birmingham, England May 99
|
 |
posted March 28, 2001 21:04
  |
 |
 |  |
I've sent out my path intensity code now.... sorry for the delay in replying - i have my final yr project due in a couple of days time.Hope all is well  Jim |
brian32 Settler
Feb 2001
|
 |
posted March 29, 2001 13:50
 |
 |
 |  |
Nice to hear from you again, Jim. Thanks for sending that.Good luck on your project. |
brian32 Settler
Feb 2001
|
 |
posted April 11, 2001 13:24
 |
 |
 |  |
Hi, guys. I finally got back from vacation a couple of days ago, and then my internet wasn't working for some reason. Sorry... I'll get back to work on the code ASAP. I'm expecting a small demo of what I have done in a couple of days. |
Mark_Everson Clash of Civilizations Project Lead Canton, MI, USA b.02-15-99
|
 |
posted April 11, 2001 13:28
  |
 |
 |  |
Excellent Brian! We're going to need an A* adapted for isometric coordinates pretty soon also . The coord system is like in Civ2 with the x=0 column consisting of a zig-zagging column. If you don't understand what I'm saying here, let me know and I'll follow up with more detail. |
brian32 Settler
Feb 2001
|
 |
posted April 11, 2001 14:17
 |
 |
 |  |
I think I get the basic idea. Just to make sure, though, a few details would be helpful. |
Mark_Everson Clash of Civilizations Project Lead Canton, MI, USA b.02-15-99
|
 |
posted April 23, 2001 11:38
  |
 |
 |  |
Sorry Brian, this request somehow fell below my radar. I have some stuff I can send you from home on details. Also if you do a web search on isometric coordinates, and look at the numbering system for the 'layered' version you'll know what the system is we need.If you don't hear from me on this within a day or so, please email me, and that will remind me to send you the stuff. I'm looking forward to the map AI demo too! -Mark |
Mark_Everson Clash of Civilizations Project Lead Canton, MI, USA b.02-15-99
|
 |
posted April 23, 2001 21:33
  |
 |
 |  |
Brian:Here's the info on layered Iso coords: Coords are just like the one used in civ2, where x=0 goes down on the map in a jagged vertical line. So if you write coords in x/y pairs you have x,y on the tiles that looks kinda like this: code:
0/0 1/0 2/0 0/1 1/1 0/2 1/2 2/2
So the three tiles that are leftmost in the 'code' section are the x=0 jagged column. You can convert it to a Cartesian system thru a transformation. I will describe what you need to go from x,y (isometric) coords to u,v Cartesian coords. BTW, I believe these transforms are correct, but haven't proven them, or even checked them fairly exhaustively. the transformations are: u = x-y/2 and v = x+(y+1)/2 where y/2 is computed in an integer division sense so if y=3, y/2 =1 with the coords u,v you can now use the standard distance formulae for the distance between squares. What else do you need for the A*? I think distance between neighboring squares is it... Note that this leaves you with the ordinary cartesian axes u, v at a 45 degree angle to the up-down right-left directions! I'll also append here some coding/isometric tiles links. Most of these are largely concerned with graphics, but some may be of use to you. Best source on isometrics is at gamedev, they have lots of iso tutorials andhow-tos http://www.gamedev.net/reference/list.asp?categoryid=44 Article I mostly used for graphics was: http://www.gamedev.net/reference/articles/article747.asp Also Try: http://www.gamedev.net/reference/articles/article744.asp which looks like a good intro though I haven't read it Another is: http://www.voicenet.com/~krem/technical/isotiles.html http://www.geocities.com/SiliconValley/Ridge/6444/isonotes.html (some notes on a particular iso project, may be of value) Let me know what else you need.
[This message has been edited by Mark_Everson (edited April 23, 2001).] |
Mark_Everson Clash of Civilizations Project Lead Canton, MI, USA b.02-15-99
|
 |
posted May 20, 2001 19:04
  |
 |
 |  |
Brian:Is anything happening on your end? We Really need the pathfinding code for units on the map Soon. Can you tell me if you're going to be able to make any progress in the next few weeks? If not, is what you have understandable so we can use it as a base for doing the TF pathfinding? Thanks, Mark PS. BTW I just had a death in the family and will be out of touch for a while, so don't take it personally if I don't reply immediately to what you say . | |