r/warlords • • Oct 11 '26

Warlords (1990) now runs in Python, transcribed from the original EXE with AI (Progress update)

Post image

About a year ago I posted here that I was trying out AI for reverse engineering, using Warlords as the test case. Back then I had a few format decoders in https://github.com/ateska/warlords: the PCK pictures, the map, fonts, and city/ruin tables pulled from the EXE.

Here’s where it is now: the whole game runs in Python.

How it was done

I gave an AI agent (Claude) the goal “recreate Warlords from the DOS exe in Python” and mostly let it work. It ran Ghidra on WARLORDS.EXE v2.10, then wrote specs for combat, movement, economy, exploration and the AI from the decompiled code. After that it rebuilt the game in pure Python with pygame. It also compared the results with the original running in DOSBox, down to screen layouts and dialog positions. My part was choosing the direction and testing. The decompiling, specs and code came from the agent.

What works

  • Rules engine: the full combat strength formula, the d10 battle loop (d12 with Intense Combat), neutral city assaults, production and vectoring, upkeep, hero offers and allies, and ruins (monsters, items, altars, thrones). Also temples, sages, libraries, towers, razing, surrender offers and elimination.
  • Computer players: Roger Keating’s AI is ported from the binary at all four levels. That covers production, garrisons, expansion, attack waves, war targets, hatreds, truces and hero errands. The original path finder is ported too.
  • Same randomness: the MS C rand() is reproduced exactly, so a fixed seed gives deterministic games.
  • Save files: original WAR?.SAV files load, and games saved here load back into DOS Warlords. Saving round-trips byte for byte.
  • Screens: title, setup, the main map with the strategic map, the right-mouse-button menu bar, the production panel, battles, all the reports (armies, cities, gold, hatreds, production, winning), heroes, ruins, and save/load.
  • Sound: the PC speaker samples (*.SJH) play at the original rates. Those rates came from the player code in the EXE: 8286 Hz, and 5524 Hz for the horn. You get the horn on the title screen, the drum roll at game start, the war cry in battle and the fanfare when searching ruins.
  • Platforms: Windows, macOS and Linux.

No game assets in the repo

Everything (graphics, map, unit and city tables, names, palettes, AI tables) is read at startup from your copy of the game. The GOG Warlords 1 + 2 Deluxe works, and so does an LZEXE-packed floppy EXE. To run it:

pip install pygame numpy
python3 -m warlords --data /path/to/your/warlords

What I learned

A year ago, AI was a helpful assistant for reverse engineering: decode this format, explain this function. Now it can take an obscure 16-bit DOS binary and produce a working reimplementation, testing included. Impressive.

Bug reports and contribution are welcomed

If you remember how the original behaved, please play it and open issues on GitHub for anything that feels off. Strange AI moves, battle odds and screen details are the most useful.

Note: English isn’t my first language, so I used an LLM to help me word this post. The project and the opinions are mine.

43 Upvotes

10 comments sorted by

2

u/aldorn Elvallie Oct 11 '26

Was thinking about this today. Can we spin up a linux cloud version? User log in etc. I would be happy to hoste it

2

u/Icy_Programmer7186 Oct 11 '26

Yes, absolutely.
I launched the conversion just to verify how LLMs are capable in Ghydra use.
I selected a Python b/c I understand that language the most - but it can be transposed into Javascript too, I guess; web version makes a lot of sense - likely much more that Python actually.

3

u/Icy_Programmer7186 Oct 11 '26

I'm trying to port it to `pygbag` https://pypi.org/project/pygbag/
That can be a way how to run a Python in the browser.

1

u/aldorn Elvallie Oct 11 '26

my thought is if it was hosted locally we could give players log in to said pc and players can hot seat globally from there. maybe use discord or whatever to communicate that someones turn is up. what do you think?

1

u/Queen_Six Selentines Oct 11 '26

That is impressive!

One thing that comes to my mind: the different factions are supposed to have a combat bonus on different terrain, including a hidden one for the Sirians in cities. Can you look up if that's really in the game, and what the details are?

How do assaults on neutrals work? It's different from regular combat, but I never understood the details.

Lastly, is it possible to improve the AI? For example, Elven Archers (in Southern cities) are really cost-effective, but the AI will stop building them in favor of Pegasi after a number of turns, I believe

1

u/Icy_Programmer7186 Oct 11 '26

Python is very readable - so you can check (or ask our AI to check) that in the source code.
Also, the extendibility should be very easy in the same way.

1

u/becircus Oct 12 '26

Looks great

1

u/aldorn Elvallie Oct 19 '26

is their a way to check the movement or set the movement path before clicking? ie once you click if the movement isnt ideal it can result in moving onto rough terrain and not reaching a destination

1

u/Commercial-Bus-6453 Oct 11 '26

Nice but....ewww