Civ2 for Java

  • Thread starter Thread starter Warpath
  • Start date Start date
W

Warpath

Guest
First of all, hello to everyone here. My first time, so excuse me if this looks screwed.
Anyway, I've written a lot of civ2 in Java. So much so that the game plays just like the real civ2, except for some things such as happiness, changing governments, pollution, etc. And of course, you can play it over the web.

But my main problem at the moment is the AI. I dunno where to start! I haven't thought about it all that much, because I'm still ironing out the MANY bugs, and finishing off combat, but it just seems like it's gonna be a pain in the ass. Any suggestions would be more than welcome.
 
geez, you've done all this by yourself? thats a fair effort. from my brief experience, programming AI is a long and painful experience. ive just finished programming some AI for a game of connect 4, and even that is very longwinded!

i'd love to see some of your work, sounds very interesting.

and remember, the AI in the real Civ2 aint that flash, programming the new AI in the upcoming civ might be a tad harder.
 
WOW!!!!

Congratulations!
goodwork.gif


I also write programs. Not in Java....but I know how you feel. If I were in your position then I would make it a human only game. Since it has to be played over the web...there should always be human players. (Although as I'm writing that, I realized that's not the case.)

So you can disregard my last statement.
biggrin.gif


Hummmmm.....AI.
I program in Visual Basic, and I would use a lot of If...Then... statements to do that. If you have one set map...then programming AI would be much easier. If it's random or dynamic....then it's like twice as hard. You could make a map and program the AI to play that map very well (Expert), ok (Normal), and poorly (Easy). Then you could release maps as you have the time. This would make the programming easier...and other people could make maps too.

Although this will even have it's drawbacks. Few (one) map to start...and you have to redo the work for each map.

But hopefully by that time there will be enough human players that you won't need AI!
smile.gif


I would love to see this too!!! If you need any help or any ideas......please ask me! I have ICQ and MSN and E-mail. And of course PM's on this site.
wink.gif


------------------
<IMG SRC="http://images.honesty.com/imagedata/h/207/85/32078598.gif" border=0> <FONT COLOR="red">I AM CANADIAN!</FONT c> <IMG SRC="http://images.honesty.com/imagedata/h/207/85/32078598.gif" border=0>
CivFanatics Moderator and Tech Support
CornEmpire Owner/Operator
 
I dont know if you would like to do this but I think I would start with a good chess ai, as there are many similarities between chess and CivII (both are turn based board games with a number of diffent units). I think that would work for a small portion of the comp ai. I don't even know where I would start on the rest. Maybe if you checked around the forum someone may have decompiled civ II?

P.S. Very impressive taking on this huge undertaking!!
 
Just remember though, that it's not anywhere near the real thing yet. And although I'd love to show yas my work, I dunno how I feel about showing an incomplete piece of work. I think I've got ur expectations up a bit too high....oops. And I might be up for some big ass copyright infringements along the way...... So I'm gonna take it easy for the moment.
Also, my webpage is down because of that stupid Code Red virus, so I can't show yas anyway, unless u grab the whole thing off me...Hey, maybe I'll do that. If you want it, email me. It's about 1.3MB at the moment.

As for only a humna player game, you can play network games over th web in Java. It got all this security crap that doesn't let you do file I/O in an applet. So at the moment, it's gonna have to be a single player, with enemy AI game. Maybe a network version later.

That single map idea sounds great for a starter though. At the moment I have 2 maps. One is of India (only 16 x 16) but repeated over 20 x 30. And I have a completely random generator, in which each individual tile has a chance of becoming any terrain type, and a 20% of having a resource. Problem is with this, is that you get really weird looking terrain...bits and pieces everywhere, which I dont like. And real maps take ages to hardcode (I've started on the world).
Anyway, I'll definitely give it a try...once I get the time.
 
I ran across a web site of a guy doing the same thing. He has the game portion done called civ evolution. He left the AI as open source code so anyone can develop it. You may want to check out his site at www.c-evo.org
 
I recently programmed a text-based game of football in Java, sort of an excuse to learn the language since hadn't programmed in it before. It has 10 offensive play options, 6 defensive, and the rules of your average pro (American)football game. For each turn (play) one side picks an offense and the other a defense, and neither knows what the other has picked until the play is run.

More than anything else I've spent a lot of time playing around with the AI. Given the relative lack of options in this simple game you'd think it wouldn't be THAT HARD to come up with an effective AI that doesn't cheat.

But it's damn awful hard. I've ended up for the moment with a competent but not particularly challenging opponent. (I win 5 out of 6 on average.)

In general though, my approach has been to look at the information used by me when calling plays, and teach the AI to store that and use it.

For example:
I wanted the AI to be aware of what I'm doing over a course of time. If I'm relying on a deep passing game then it should adjust its defense to account for that. So I wrote a class to teach it to keep a record of my recent plays and take that into account when calling a defense.

Second, I wanted the AI to be aware of it's play calling in the context of the game. If it's way behind and time is running out then it's time to start passing more. Similarly if it's ahead and time is winding down, it should not play an up tight defense but hold back and prevent the big pass play.

etc etc.

I found teaching it to think at these strategic levels is more effective than trying to predict player reaction at a lower level with long chains of IF ELSE statements.

Also, most important, make sure to leave some variability in the AI's choice of actions or it will get too predictable very fast.

Anyway, just thoughts. As I say my AI is still far from perfect..
 
That sounds like quite an undertaking !

You might want to do a search for "heuristic" on the web. I remember taking an AI course in university and basically, if I remember correctly, you make you decisions by trying all available moves and seeing which one brings you 'closer' to your goal. Heuristics are how you measure how close you are to your goal. If you want to get really fancy you can recursively check several moves ahead. But definitely, my friend, you do NOT want to even begin trying to set up massive if-then-else or case statements.

A good little sample game to try your hand at for AI practice is tic-tac-toe.

Good luck !
 
Awww...its a pity I've already started the AI using all If then Else statements.

I don't really see another quick and easy way around this....and it seems to be working Ok. I just wish applets weren't so friggin slow.

The hardest part was coming up with the frickin algorithm to work out the shortest path to a certain location. Turns out, my uni course helped me out :).

If anyone wants to check it out, it's here
http://www.trenty.2y.net/Civ2/Civ2.html

You need the Java plugin, V3 or better.
If you don't have it, it should ask you for it.
Ohh....and it takes a while to load up at the moment, so be patient.
 
These are the keys.
'e' - End turn
'n' - Next unit
'r' - road
'i' - irrigation
...i think that's it so far...forgotten if 'f' - fortress works.

MAke sure u use the keypad with numLock on.

And I know u can't change the taxRate/scienceRates, but I assure you, the tech system does work. It's just that there's a bug that after 50 or so turns, the AI has every research, and then it crashes.

And yeah you'll have a civil disorder if ur city has too many unhappy people. Except it wont tell you. It will just stop doing anything.
 
Now that I'm playing it's pretty good. But I can't change the locations of the workers in the cities. I have a size 3 city but no production because I can't change the workers!!!

But I took over a city!! There is a bug with the combat...because my hitpoints kept going up and down until he was finially dead....it was funny...but still a bug. :(

A nice substutite for when it's slow at work!!
 
The hardest part was coming up with the frickin algorithm to work out the shortest path to a certain location.
The pathfinding aspect of both turn based and RT (real time) games is quite complex to fully implement. Age of Empires II The Conquerors has finally done a pretty good job, but even it soaks up almost half the CPU instructions at any given moment. To me, the terrible pathfinding in Civ II is just sloppiness and laziness on the part of the Reynolds team. I honestly cannot see how Civ II MGE made it out of beta, or at laest past final QC. They must have been in a huge rush, and I know they faced milestone pressure, too.

america1s.jpg
 
You took over a city? WOW! I didnt think that was possible.

Haven't done much work on it for a while....so yeah, you'll definitely find a heap of differences between it and the real version. Hopefully get back into it when it gets quieter.

I haven't done the worker allocation thing yet because it's really hard to get the mouseClicks right....among other things. Notice how you can't click anywhere on the map? You have to click in the centre of the diamond. That's because I dont know how to check whether the click is inside a diamond. So i check if it's inside a box inside the diamond.

Combat should work...just unit - unit. Haven't even thought about cities yet.

As for the pathfinding....yeah it's damn slow when you have too many AI units...but I think it works pretty well....(well my version works good enough for now...it will get better.. and quicker) Based on Djikstra's algorithm if anyone has a clue about that.

Anyway I'm glad you guys like it. But I can see ur gonna get bored of it pretty quickly :crazyeyes
 
Back
Top Bottom