Jump to content

PetraBot_Template: build your own Petra-based bot in one command (R28)


Recommended Posts

Hi everyone,

I’d like to share a small tool I made for anyone who wants to build their own AI for 0 A.D.

GitHub: https://github.com/lilypoppybooks/PetraBot_Template

The problem

Starting a new bot from Petra usually begins with a tedious step: copy Petra, then rename it everywhere. Since R28 introduced JavaScript modules, you also have to fix about a hundred import paths. Miss a single one and your bot silently loads the original Petra code, or two derived bots overwrite each other in the game’s file system.

 

The solution

PetraBot_Template is an exact copy of Petra from Release 28, isolated in its own namespace, with no change in behavior. It comes with a small Python script that clones it under a new name:

python3 clone_bot.py Alpha     # creates PetraBot_Alpha.zip

The script renames everything (mod, AI folder, imports) and keeps the license and credits intact. You get an independent, working bot ready to install, and several clones can play against each other in the same game.

I've tested it over roughly 10 hours of games: I tested both land and naval maps across different game settings, repeatedly comparing the Petra bot, the PetraBot_Template, and the derived Petra. The result is that PetraBot_Template works and behaves exactly like Petra.

Why?

To make developing Petra-based bots easier. Instead of spending time on renaming, developers can focus on what matters: new ideas and new strategies. And since every bot starts from the same reliable base, it becomes simple to compare them fairly and to share results.

 

Three gaps I see in Petra

Petra is stable, but in my opinion three areas leave room for improvement:

  1. Naval strategy. Petra’s naval manager mostly handles trade, fishing, coastal defense and transport. The comment at the top of navalManager.js even lists sea scouting as an “ultimately” goal. On island maps, war fleets that take the initiative, sea control and coordinated landings would make a big difference.                                                                                   
  2. Politics, dialogue and intimidation. Petra already handles tributes and alliance requests, but its diplomacy is reactive and its messages don’t form a real dialogue. Imagine a bot with a diplomatic personality, one that can intimidate (demand a tribute and actually attack if refused), remember betrayals, or make calculated alliances.                                                               
  3. Exploration and strategy. Petra mostly picks its strategy from its own situation and reacts more than it anticipates. Early scouting, adapting to what was seen, choosing targets from gathered information and switching plans mid-game are all open fields.

Each of these could be a project on its own, and the template makes it easy to start one.

Links

GitHub: https://github.com/lilypoppybooks/PetraBot_Template

License: GPL-2.0-or-later, same as Petra. All credit for Petra goes to Wildfire Games and the Petra contributors. This project is not an official Wildfire Games project.

If you build a bot from it, please share it here! I’d love to see clones play against each other and compare approaches. Feedback and suggestions are very welcome.

petrabot_cycle.svg

petrabot_cycle(1).png

Edited by lilypoppy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...