Mini-engine progress

Yes, that's how I would feel after seeing https://nethackchallenge.com/report.html#best-overall-agent. Symbolic may be better than neural. My measuring stick is what difficulty can it play at. And can an AI play against Deity.

But you can combine, like wikipedia says. Hybrid AI may be the best possible, which is unsurprising.

With Reinforcement Learning, you can use neural networks. That gets you "Deep Reinforcement Learning".

Or, take a rule-based AI and use machine learning to make decisions: https://pythonprogramming.net/starcraft-ii-ai-python-sc2-tutorial/

With Cv4MiniEngine, there is a way to create a "learning environment" to create these sorts of AIs. Or rather, it shows you how to use the DLL (except that annoying end-turn problem...) and the DLL has performance enhancements. One would basically create a headless engine, or, a server, that a modern Python 3 AI with all your OpenCV/neural network magic could connect to.

Or, go the extra mile and just reimplement whole DLL for maximum performance (with no python calls at all). After all, you'd probably want lots and lots of training data.

Another kind of AI that I keep thinking about is solving for a near-optimal isolated empire. In theory, you could use an MILP or constraint solver (with a python interface), but even optimising for a single city may take forever. Another way is "Monte Carlo tree search", which Total War used, but I would want near-optimality, which would still take forever. The big problem with this kind of thing is huge amounts of symmetry (near-equivalent search-trees for each choice of tiles to work) and poor objective bounds (can't tell which sub-tree is better). If you use an off-the-self solver, the thing to try out may be HiGHS or MiniZinc.

*Another idea is that a sufficiently good AI could be used as hints for the player, like you would have in chess games.
Yeah, it was annoying Civ V doesn't have a headless mode. So I ended up creating a hack, and that still takes more computing power than I like. Is there a chance to use the MiniEngine on Linux? If we want to do heavy CV workload, that would help a lot...
 
With Cv4MiniEngine, there is a way to create a "learning environment" to create these sorts of AIs. Or rather, it shows you how to use the DLL (except that annoying end-turn problem...) and the DLL has performance enhancements. One would basically create a headless engine, or, a server, that a modern Python 3 AI with all your OpenCV/neural network magic could connect to.

Or, go the extra mile and just reimplement whole DLL for maximum performance (with no python calls at all). After all, you'd probably want lots and lots of training data.

After that you end up with something that has nothing to do with Civ IV anymore. Creating a independent Civilization like game from scratch with performance and LLM integration in mind would probably make more sense.

Or maybe use a similar approach as Vox Deorum with Civ IV. They use a named pipe for communication with a bridge server but otherwise keep the existing architecture.
 
Yeah, it was annoying Civ V doesn't have a headless mode. So I ended up creating a hack, and that still takes more computing power than I like. Is there a chance to use the MiniEngine on Linux? If we want to do heavy CV workload, that would help a lot...
Cv4MiniEngine does run on Linux, but more importantly, the DLL compiles on Linux. And somehow, one would build a headless engine on top of that, using applicable pieces from Cv4MiniEngine.

After that you end up with something that has nothing to do with Civ IV anymore. Creating a independent Civilization like game from scratch with performance and LLM integration in mind would probably make more sense.

Or maybe use a similar approach as Vox Deorum with Civ IV. They use a named pipe for communication with a bridge server but otherwise keep the existing architecture.
Oh, you'd just use it for training. Because, afaik, training an AI needs lots and lots of data, so you'd want a very fast engine. Then, you'd use the training data for your graphical engine. Somehow.

Well, I suppose one could make a graphical engine "fast", but as long as it calls into python game mechanics code (events, plot reveal, etc), it would not be as fast as it could be. So, you'd have a specialised engine that compiles in vanilla python code to make it run faster. But I don't know, maybe this optimisation could be built into a graphical engine. Whatever works.
 
One would basically create a headless engine, or, a server, that a modern Python 3 AI with all your OpenCV/neural network magic could connect to.

So, you'd have a specialised engine that compiles in vanilla python code to make it run faster.

This is something i struggle to understand about the LLM and web dev worlds.
Python used by the game = slow need to go. But at the same time running/training LLMs with Python or Node.js like Vox Derum is doing is good. Vox Derum is communicating with LLMs like ChatGpt through the Internet. Not sure how the latency is on that but it's probably more than a few calls into Python from the C++ gameplay code would take.
 
Last edited:
This is something i struggle to understand about the LLM and web dev worlds.
Python used by the game = slow need to go. But at the same time running/training LLMs with Python or Node.js like Vox Derum is doing is good. Vox Derum is communicating with LLMs like ChatGpt through the Internet. Not sure how the latency is on that but it's probably more than a few calls into Python from the C++ gameplay code would take.
Statements like "language X is faster than language Y" aren't that accurate. The question is always: Where is the bottleneck? If CPU is the bottleneck, then the same code in c++ most likely runs faster than python.

But the bottleneck for an LLM is the GPU, not the CPU. The python library passes the instructions to a gpu driver like nvidia cuda who will do the heavy lifting on the GPU with optimized low level code. For 99.9% of the time the python code will just wait for GPU to finish it's instructions.
 
This is something i struggle to understand about the LLM and web dev worlds.
Python used by the game = slow need to go. But at the same time running/training LLMs with Python or Node.js like Vox Derum is doing is good. Vox Derum is communicating with LLMs like ChatGpt through the Internet. Not sure how the latency is on that but it's probably more than a few calls into Python from the C++ gameplay code would take.
It is simply that Civ4 will call into python way too often and sometimes, the python code doesn't even do anything, and python is always single-threaded here. Whereas when you're writing a ML-based AI in python, most time is spent in optimised frameworks. Ideally. That better be the case!
 
You can look at this commit.

The code removed is a option from Caveman2Cosmos and it skips most graphical updates during the AI turn processing. That also works when doing a AI Autoplay and reduces the the time it takes to process turns simply because the graphics don't get updated.

@johnchen
The same can be done with Civ V but not sure how well that actually works, might need some tweaking.
 
You can look at this commit.

The code removed is a option from Caveman2Cosmos and it skips most graphical updates during the AI turn processing. That also works when doing a AI Autoplay and reduces the the time it takes to process turns simply because the graphics don't get updated.
Yeah, that sounds like what would need to be done for Cv4MiniEngine to make CvGame::update work better with the action-driven UI.
 
Hello Snowern,

I've read the whole thread. Well done, I'm blown away!
Is it still possible to use the new DLL with the original application? Or does it rely on 64, e.g. because of the new path finding algorithm?
 
Hello Snowern,

I've read the whole thread. Well done, I'm blown away!
Is it still possible to use the new DLL with the original application? Or does it rely on 64, e.g. because of the new path finding algorithm?
Certainly not readily. Even with the original DLL code, it'll need a number of modifications to get it to work with the BTS engine if compiled with a modern compiler: https://forums.civfanatics.com/thre...v4s-speed-in-large-games.688441/post-16594837

But if you manage to compile the original DLL with modern VS, I think you do get a speed up from just the compiler.

Or if you try to compile the Cv4MiniEngine DLL with the old compatible compiler, it'll probably complain about all the C++ modernisms.

The enhancements are also optional. The regular build tries to keep everything vanilla.

Really, the idea is that somebody writes up a new x64 engine with all the 3D graphics so we can have it all. It shouldn't be a crazy difficult thing to do, because we've got the game's DLL code. The only missing piece is the engine.

It's something I would probably do, but I'm sort of tied up with another engine I wanted to do since before I started this. Which is why it's very quiet here and I don't notice Github issues until weeks later.
 
Back
Top Bottom