CAR Mod: Civ AcceleratoR

You surprise me.

Here's a list:

CVDeal.cpp
CvGame.cpp
CvInfo.cpp
CvInfo.h
CvPlayer.cpp
CvPlayerAI.cpp
CvPlayerAI.h
CvTeam.cpp
CvTeamAI.cpp
CvTeamAI.h
CvUnit.cpp
CvUnitAI.cpp

These are for v0.2. future versions will change. So if would help if you could find out by searching all files in the source with 'Sanguo' keyword.



Edit: I guess I should ask you first! stmartin, can I include your DLL (properly credited, of course) in the mod in my sig?
 
However, it's pretty safe to say nothing significant is missed. Because in our test runs, after 90 turns, the score distribution, tech progress and map reveal situations in both CAR and non-CAR game are almost identical.

My emphasis. So they aren't identical which means there are gameplay changes, right? Someone noted that the Aggressive AI -2 attitude change was uncommented which could affect the game. Was this intentional? It would be very good to have a verified UG version of CAR for BBAI and BULL, if I may be so selfish. :)

For one thing, it's not save game compatible. :)

This is a problem for many users that want to try it out on existing games. I looked through the code, and it looks like the caches that are saved could just be cleared during a read. Sure, you'd get a minor performance hit when loading a saved game to rebuild the caches (no different from non-CAR loading), but having saved game compatibility is worth more I think than a fractional second extra load time.

If someone knows a way to make winmerge ignore all the spacing and tabs I'd be glad to here that btw.

Edit : Options... : Compare : Whitespace : Ignore all

hopefully, you or someone could make civ 4 somehow became multi-core supported.

Making the game multithreaded would be a huge undertaking and require rewriting almost the entire DLL. All of the AI algorithms would need to be redesigned to run in parallel. It would be truly awesome, though.
 
Making the game multithreaded would be a huge undertaking and require rewriting almost the entire DLL. All of the AI algorithms would need to be redesigned to run in parallel. It would be truly awesome, though.

Wow, I didn't even realize this way possible, I though the processes were determined by the .exe and not up to us. I would support such an undertaking under one condition, that Civ 5 was not under development. Making it multithreaded would be so much work that it would be a waste to finish it in time for Civ5 to come out and be multithreaded by default...
 
I don't know enough about windows multithreading to know if a DLL can spawn threads, but I would expect so. However, maybe I wasn't clear on how huge of a project it would be. I know of no game that uses parallel processing for any part of it, let alone just the AI. Notice how games freeze up whenever loading new maps when even making the UI remain responsive while the game loads would be quite trivial.
 
I don't know enough about windows multithreading to know if a DLL can spawn threads, but I would expect so. However, maybe I wasn't clear on how huge of a project it would be. I know of no game that uses parallel processing for any part of it, let alone just the AI. Notice how games freeze up whenever loading new maps when even making the UI remain responsive while the game loads would be quite trivial.

One can always dream... can't he?

Civ5 better have multithreading support. In fact, if that was the only feature it added, and everything else was the same as Civ4, I'd still buy it.
 
On aggressive AI the old -2 attitude towards human players has been uncommented, I'm not sure if this was intentional but that is one unexpected gameplay change.

Thank! It's not intentional and it's a good catch.

Edit: I guess I should ask you first! stmartin, can I include your DLL (properly credited, of course) in the mod in my sig?

Sure you can, before you played the Mod in my sig.;)

My emphasis. So they aren't identical which means there are gameplay changes, right? Someone noted that the Aggressive AI -2 attitude change was uncommented which could affect the game. Was this intentional? It would be very good to have a verified UG version of CAR for BBAI and BULL, if I may be so selfish. :)



This is a problem for many users that want to try it out on existing games. I looked through the code, and it looks like the caches that are saved could just be cleared during a read. Sure, you'd get a minor performance hit when loading a saved game to rebuild the caches (no different from non-CAR loading), but having saved game compatibility is worth more I think than a fractional second extra load time.


If there are game play changes, like the one jdog caught, it's not intentional, so I want to say CAR is unaltered gameplay, however, it needs some more time to confirm. EF, can you take a look at CAR source code and help confirm it?:D

About save game compatibility, I think you made a good point, I'll see how to do it.
 
I seriously doubt any games will have multithreading support any time soon. You have to rethink the AI algorithms to work in parallel, and this also increases the communications overhead. Plus, there's no way amateur coders would be able to work in that code which would seriously hurt the modding community.
 
If there are game play changes, like the one jdog caught, it's not intentional, so I want to say CAR is unaltered gameplay, however, it needs some more time to confirm. EF, can you take a look at CAR source code and help confirm it?:D

Certainly, and I have started it already. The real trick is to verify that the cache values are cleared in every case that is necessary.

In the case of attitudes, that's probably pretty straight-forward. The plot danger is more what concerns me only because I have never looked at that code and so I can only imagine how complicated it is. I glanced at it today and saw that you removed the check for bTestMoves. I'll need to see if there some instances where the value passed in is false, and thus the return value is different. What exactly does this do?

About save game compatibility, I think you made a good point, I'll see how to do it.

I think as long as you initialize the caches as empty/zero so their values are recalculated the next time through, that should be sufficient.
 
I seriously doubt any games will have multithreading support any time soon. You have to rethink the AI algorithms to work in parallel, and this also increases the communications overhead. Plus, there's no way amateur coders would be able to work in that code which would seriously hurt the modding community.

You only need one thread for the AI (or physics or whatever) and one for the graphics, that is close to becoming standard these days and keeps the AI sufficiently simple. I certain expect to see this on a regular basis going forward.

For CIV it would be enough to have the AI be able to think about its turn while the player is making his own turn. I would expect that little of an AI move depends on what is being done in one turn (but then I also do not think the AI is anywhere near as smart as it could be, but that is a general problem, while graphic routines have advanced significanty the AI has very little).
 
Certainly, and I have started it already. The real trick is to verify that the cache values are cleared in every case that is necessary.

In the case of attitudes, that's probably pretty straight-forward. The plot danger is more what concerns me only because I have never looked at that code and so I can only imagine how complicated it is. I glanced at it today and saw that you removed the check for bTestMoves. I'll need to see if there some instances where the value passed in is false, and thus the return value is different. What exactly does this do?

I think the original AI use bTestMoves to save turn time, and since it's now cached, it doesn't matter if to consider bTestMoves every time. Remove the check of bTestMoves will slightly alter the AI, in the right direction, I think.
 
I seriously doubt any games will have multithreading support any time soon. You have to rethink the AI algorithms to work in parallel, and this also increases the communications overhead. Plus, there's no way amateur coders would be able to work in that code which would seriously hurt the modding community.

i'm a huge fan of Supreme Commander and it supports multithreading very very well...
 
View Post
Making the game multithreaded would be a huge undertaking and require rewriting almost the entire DLL. All of the AI algorithms would need to be redesigned to run in parallel. It would be truly awesome, though.

Man, almost makes me want to be good at C++ and do that, it would be well worth my effort...if it worked:lol:


Are the changes in this mod labeled (with comments) in the .cpp files
 
i'm a huge fan of Supreme Commander and it supports multithreading very very well...

Let me qualify my statement. Having one thread for the interface and a second thread for all the game logic would be pretty easy, and I wish more games would do it. Does SC go beyond this and have parallel processing in its AI?

Keep in mind that every game that uses a 3D graphics card by definition is multithreaded: one for the CPU and one for the GPU (maybe more, but at least one).
 
Are the changes in this mod labeled (with comments) in the .cpp files

Yes, but do yourself a huge favor and install the free WinMerge program. You can place the sources folder next to the CvGameCoreDLL folder that is installed in the BTS folder automatically, select both, right-click, and select WinMerge. You'll then be shown a side-by-side comparison of all files contained therein and be able to easily navigate among all the highlighted changes.
 
Not looking at the function right now, but PlotDanger is one I have played with before. bTestMoves was used (IIRC, which I often don't) to check a larger range and see if danger items can move into range of the unit. So with a 2 move Horseman sitting 2 Plains tiles away from you, bTestMoves will say you are in danger, but without it you'll say you are fine.
 
Not looking at the function right now, but PlotDanger is one I have played with before. bTestMoves was used (IIRC, which I often don't) to check a larger range and see if danger items can move into range of the unit. So with a 2 move Horseman sitting 2 Plains tiles away from you, bTestMoves will say you are in danger, but without it you'll say you are fine.

In CAR I removed the check to bTestMoves, not to set it to always false, but to always true.
 
When does the plot danger cache get reset? My guess is that you invalidate every plots cache for player X at the start of X's turn. For multiplayer games using simultaneous moves, do all the AIs move after all the human players?

It would really help us assess these changes if you wrote up a very brief high-level design of the different caches and when they are invalidated.

For example:

Attitude Cache

  • Stores a single value per player pair (bidirectional).
  • Initialized to MAX_INT
  • Invalidated whenever certain information about a player (X) is changed. Each pair involving player X is reset in both directions.
    • Religion
    • Civics
    • Trades
    • ...
This information will help us and be very important for modders that add new XML elements. For example, Afforess is adding attitude modifiers for civics (a player running Slavery suffers a -2 from anyone running Emancipation), and thus the cache must be invalidated when someone changes civics (as noted above, this may already be in there, but it was just an example).
 
@EF

I'll do it when I find time. For the time being search 'AI_invalidatePlotDangerCache', it will list all relevant places.

EDIT: ah, I should add this: search for 'invalidatePlayerDangerCache' too, since this function actually got called more.
 
Waiting for Civ 5 might takes years, but making this game multi-core supported might take less time then making the whole . .. .. .. .ing game. I doubt that Sid Meier's will make Civ 5 look like Civ 4 all over again, he made civ revolution fancy, so he might make it something like that or better. I also hope the next Civ game got cheats, since civ 3 don't. I also wish I could just select a group of people and when I am at war, I hit this button that make the AI automate that group and go on either attack the nearest city, or go around and pillage the lands without me controlling every single troop.

I like civilization 4 and the only problem I do get on most mod is the heavy lag, and I do not have tolerate long wait periods per turn, it makes me feel bored, and i end up quiting the game when i suffer so much lag. If it's possible to make a multi-core supported mod and released the source, it will be way much more better to play the game and hardly suffer any lag. This help make this game playable for today's State-of-the-art computer that can run Crysis on very high with little to no lag what so ever.

also whoever said that most game does not have multi-core support... must have lived under the rock in a long time. Valve's game like Team Fortress 2, Left 4 Dead, and all other games that run the source engine have multi-core support. Crysis also have multi-core support, even prototype, assassin's creed, and many other games.
 
search 'AI_invalidatePlotDangerCache', [and] 'invalidatePlayerDangerCache'.

Thanks, I'll start there.

Valve's game like Team Fortress 2, Left 4 Dead, and all other games that run the source engine have multi-core support.

They have multicore rendering, yes, but I already said that I'm not talking about the UI/graphics. I am talking about the artificial intelligence, and I seriously doubt that L4D or any other FPS runs its AI routines in parallel. I've looked at the modding APIs for Source SDK, and they have no provisions for multithreading.
 
Back
Top Bottom