Are you, in fact, a pregnant lady who lives in the apartment next door to Superdeath's parents? - Commodore

Create an account  

 
External AI for MoM?

The Insecticide project has gone quite far from my point of view, I never expected it to become so large. Many bugs keep a coming, but in general we can already see an end to it (I remember my own illusion, when started, that the game is not at all that broken as MoO, hehe). There are a few important interface themes, that will increase substantially the playability - and I am looking forward to make them work.

What cannot be called a success till today, in terms of "seeing the end of the task approaching", is the in-game AI. Many crucial corrections (the number may float around 200) were made inside the code. But they were, most of the time, an attempt to avoid the most stupid AI decisions, rather than to force the AI to state long-time goals and to create plans to execute them. We are being limited from inside the code, by condensed space, by cumbersome AI data structure and - most importantly - by the simple fact that writing any new code in assembly is painfully slow.


Maybe it is time to make a step in new direction - to create an External AI for MoM. Of course, this cannot be a work of an individual (not me surely, as I am a pure amateur). There are a few people here, who, as it seems, have professional pre-requisites

(1) to write the AI in a modern programming language of their choice (WhiteMage in particular, maybe others with a good experience) and

(2) to create a connection between the program and the would-be AI external utility, so that the MoM program asks, when necessary for decisions that are externally fetched to it by the AI utility (ILSe could help here, others with a good experience).

(3) finally, I could provide addresses that represent the final AI choices in almost any matter in the game (my guess is that 98-100 % of the decision points are known to me). I would try to force the program to ask for the external input (if somebody helps me, gives me advice how to do it). I could also work on internal AI data structures to provide better information, better input for the utility if necessary.

Questions
- Is this technically possible or is it just a dream?
- Are some of you interested to put a work in and create a much better MoM, while respecting the original?
- What are the limitations? What would be necessary to do from both sides (external, internal)?
Reply

I could help, but my skills are rather limited. I have bachelor's degree in Computer Science and I'm not completely awful at math, but I barely have any programming experience outside of writing scripts. I couldn't manage this on my own, but maybe - if people helped - in time I would improve my ANSI C and Python skills.

In any case, I can test software, report bugs, write documentation (unless it requires deep knowledge of the code).

If we're going this far, why not try to rewrite from scratch ? There are even some abandoned projects we might use, like Magic Master (MoM combat system in Python). It's in Pre-Alpha stage, though. http://sourceforge.net/projects/magmap/ . At least it's made to work with the original data files, so it may be a good choice if trying to create a remake.
Reply

We're creating a cyborg! lol
Reply

Excellent idea! External AI is the way to go. Take a look at C-Evo. Superb open source game programmed by a single guy. It is already the best Civilization game I know of and many people develop their own AI’s using the “official development toolkit”. The game allows you to embed any AI and even host AI only tournaments. Up to 14 AI players on one of 3 handicap levels and you can leave the computer on all night to play a couple of thousand games and see report which AI player won the most. Moreover, the game saves every single move (not just turns) and can be reviewed step by step how each AI played. The AI does not cheat at all, does not know where to search for anything and does not get any bonuses other than humans. I wrote AI for games and other stuff in Pascal, C++, Java, and Matlab and I also know how to make AI learn and get better by playing. I have not written code in assembly since I was a student and I have not looked at the possibility of how it would be best to integrate an external AI with the current MoM code. Yet, I think that fixing the game rules and bugs is a priority. Writing (strong) AI for a game that is heavily under development and change is not a good idea. AI coding takes a long time, with new rules it becomes nearly useless. C-Evo froze rules at 1.0 and allowed a long period for AI developers to shine. I still can beat it at par or at 1 handicap level, but I usually lose at 2 (I produce everything at 125% cost, AI produce at 75%). C-Evo is fully deterministic and that allows a faster AI development. This does not mean that we should make MoM deterministic, we just have to approach the AI programming differently with probabilistic decision making rather than traditional rule based AI algorithms combined with brute force search algorithms. If someone can create the link with the game core, I would be happy to throw myself into the AI programming.
Reply

I'm in!

I'm a professional C++ programmer in technical automation.
I guess I can take care of the link to the game core.
I also have a solid background in mathematics and I know a bit about AI.

I guess we need a system that whenever the game needs to make an AI decision, that it can signal it somehow to an external program, and wait for a signal that it can continue.

We could for instance define a variable in static memory that the game sets to a non-zero request-code when it needs a decision, and the external program resets it to 0 when it is done. The game would have to wait for the variable to be reset.
Kyrub, could you insert code like that at the crucial points?
--I like ILSe
Reply

Excellent! Thank you all, borsuk, WhiteMage, ILSe (Catwalk, "cyborg" is not a bad name, although slightly out of the realm of magic). Very good start from the personnel point of view, others will hopefully join. The basics are here.

@borsuk
There's going to be a lot of work you can help with, I'm sure. Testing is priceless for me f.i., I lack patience and attention for detail. And if the AI system is open to programming (as WhiteMage probably intends), you can work on it directly. Or make an AI for your own mod.

@WhiteMage
I agree that the MoM program is not ready for an AI injection yet (as you mentioned elsewhere). But it is a signal for me that I can put most of my AI efforts aside, since there is a good chance that the AI will be renovated externally. That's why I asked.
It seems you prefer making the AI for Catnip. I'm still unsure about the longevity of its outcome. On the other hand, the general technical solution (the link between the program and a general AI structure you create) can be probably used for any version of the game. How open will the AI structure be, do you think you could externalize it for others (similar to your example of C-Evo)?

Quote:We could for instance define a variable in static memory that the game sets to a non-zero request-code when it needs a decision, and the external program resets it to 0 when it is done. The game would have to wait for the variable to be reset.
Is "static" in your phrase an opposition to the "overlayed" code? I am lost in these terms. Other than that, specifying a variable with given fonction (1 = "needing input of combat spell", 2 = "needing input of AI overland moves" etc.) is a very simple and elegant way to deal with it. Then I would make a loop in the code, waiting for that variable to become 0 (0 = "input given") to proceed. It should work!

Quote:Kyrub, could you insert code like that at the crucial points?
Since we'll stop using large areas of code... I have hangars of space.
Technically, I have one worry. Will it be fast enough? Lags during the next turn phase (or combat) can become annoying to the point of unplayability.

Does anybody know about a similar project elsewhere? An old game + external program running the AI?
Reply

kyrub Wrote:Is "static" in your phrase an opposition to the "overlayed" code? I am lost in these terms.

[TECH STUFF]
I'm distinguishing between static data, dynamic data, static code, and dynamic (overlay) code.
  • static data is what is in the segment "dseg". It is already present before the program runs and it nevers shifts in memory.
  • dynamic data is what is allocated and has a space above dseg. It may shift in memory and may be swapped out into the file COMBAT.TMP.
  • static code is what is in the segments prefixed with "seg" like seg000. It is present before the program runs and never shifts in memory.
  • dynamic code aka overlays are in segments prefixed with "ovl" like ovl050. It is loaded from WIZARDS.EXE when needed and discarded otherwise.
[/TECH STUFF]

I already have a candidate for a static variable: the AI-variables you asked me about which seem to be unused and always turn out to be zero (perhaps they were at one time used in development to insert AI choices from an external program lol)!

kyrub Wrote:Technically, I have one worry. Will it be fast enough? Lags during the next turn phase (or combat) can become annoying to the point of unplayability.

Speed won't be a problem at all. Remember that the external program is not being emulated. You won't notice any lag at all, that is, unless the AI algorithms are really timeconsuming. There is one potential problem: if the game loops until a variable changes, that may put a heavy load on the cpu. But I'll address that problem when and if it comes up. I know I can solve it in a number of ways.

EDIT: Sorry, this is not quite true. The external program can't "wait" for the variable to change. It has to continually check if the variable changes. This may cause a small lag, depending on the refresh rate we choose. We may have to tune this.
EDIT2: I'll have to think about this. I think I may be able to come up with a way the external program can know instantly that a request is pending.
--I like ILSe
Reply

Would you like a new forum section to discuss this? I still think the name should include Cyborg somehow smile

I wish to stick with Catnip and have little to contribute to this project. As I'm sure you know, I'm just a lazy know-nothing who likes messing with game rules smile

I certainly wish you well with it. And should it get anywhere (sorry for the pessimism,b it seems like a much bigger challenge than our current projects), I'd love to use it for Catnip.
Reply

Catwalk Wrote:Would you like a new forum section to discuss this? I still think the name should include Cyborg somehow
It is not me to decide. My role in this is minuscule. Somebody else should take care of it in the long-turn, probably WhiteMage, since the AI part will be the most important after we set the technical part up.

Quote:I certainly wish you well with it. And should it get anywhere (sorry for the pessimism,b it seems like a much bigger challenge than our current projects), I'd love to use it for Catnip.
With all experts around, I have big expectations from this. It's more sure than my plans with interface or graphic improvement.
Reply

kyrub Wrote:@WhiteMage
I agree that the MoM program is not ready for an AI injection yet (as you mentioned elsewhere). But it is a signal for me that I can put most of my AI efforts aside, since there is a good chance that the AI will be renovated externally. That's why I asked.
It seems you prefer making the AI for Catnip. I'm still unsure about the longevity of its outcome. On the other hand, the general technical solution (the link between the program and a general AI structure you create) can be probably used for any version of the game. How open will the AI structure be, do you think you could externalize it for others (similar to your example of C-Evo)?

Well, I would like to see how catwalk and insecticide turn out first, I may even consider b0rsuk’s version or may create my own if all of these versions are far away from the game I have in mind. I prefer not to create my own game mod.
Once I decide that there is a stable game with stable rules, which are very interesting and rule changes are unlikely then we will need a rule freeze for a long time, so I can program and test for that set of rules. Step by step observation of AI moves would make a huge difference in debugging, which is not completely mine, since the core will be the old code. The interface between game and AI should be ubiquitous and the AI might work for other versions and mods too, but will appear to be more stupid than for the intended rules.
Reply



Forum Jump: