GithubHelp home page GithubHelp logo

ks07 / aoe2-ai-fmt Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 57 KB

A python library and command line tool for formatting AoE2 AI rule files (.per)

License: MIT License

Makefile 6.50% ANTLR 16.04% Python 77.46%

aoe2-ai-fmt's Introduction

Age of Empires 2 AI Rule Formatter

This project provides a script that allows basic syntax checking and formatting of AoE2 .per files.

Note that this tool is currently a work-in-progress. Crucially, it does not yet have full compatibility with .per files built for DE or User Patch versions of the game.

This tool depends on Python >= 3.6.

It has been developed using Python 3.6 on Ubuntu for Windows (WSL), but has also been tested against Python 3.8 on Ubuntu 20.04, and Python 3.8 on Windows 10. In any case, the tool should work fine in any environment which provides the required Python version. Development requires a Linux environment.

Library Usage

The tool can be used from the command line, or can be used as a library in your python projects. To use as a library, you can install via pip.

pip install aoe2-ai-fmt

Then use the format_per function as follows.

from performat import format_per

# Define a string containing some messy per content
my_per_content='''
  (defrule (players-unit-type-count 1 scout-cavalry < 6)
    =>
  (goal 1 100) (disable-self) )
'''

# Write formatted per content to formatted_output.per
with open('formatted_output.per', 'w', encoding='utf8', newline='\r\n') as out:
    format_per(in_string=my_per_content, out_stream=out)

See format.py for an alternative usage example.

Usage From Source

Dependencies

Building the tool requires ANTLR v4.8, pipenv, and GNU Make.

Installation From Source

Clone the repository, and then use pipenv to create a python virtualenv and install the necessary dependencies within it. Specify the --dev argument if you're going to be making changes.

pipenv --python 3 install [--dev]

(Note that python 3.6 is required, but this is not enforced by the Pipfile thanks to a limitation in pipenv.)

It is then necessary to build the lexer, parser, and supporting files using antlr4. The provided Makefile can invoke this for you, provided antlr4 is in your $PATH.

make

Then, simply run the tool from the command line, from within the virtualenv:

# ./format.py <path/to/src.per> <path/to/output.per>
# If the output path is provided as '-' then the formatted script will instead be printed to STDOUT.
pipenv run ./format.py examples/multistmt.input.per -

Input files may use Windows or Unix style line endings. Output files will always be created with Windows line endings, to match the platform of the game.

Testing

A small suite of example inputs and their desired pretty printed equivalents are provided in the repo. A basic test recipe is included in the Makefile to easily run the tool against all inputs, and allow manual inspection of any differences to the desired output.

make test

A make rule exists to run pylint, with the included .pylintrc ignoring the auto-generated ANTLR4 parser files.

make lint

Limitations

As the tool is built using a parser, invalid syntax will cause the formatter to error.

The tool is built based upon the language details provided in the official documentation supplied with The Conquerors. As this document isn't a formal language specification, some assumptions had to be made, particularly regarding allowed characters in identifiers and whitespace. It is possible that files accepted by this tool will not be accepted by the game engine, or vice versa. Notably, the more advanced actions and facts available in DE and User Patch are not currently supported by the tool, but support for these is in progress.

Note that this tool does not check anything more than basic syntax. Non-existant facts or actions, incorrect numbers of arguments, undefined constants, and other similar errors will not be detected by this tool.

aoe2-ai-fmt's People

Contributors

ks07 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

aoe2-ai-fmt's Issues

Expand grammar support to cover additions in newer game editions

The tool doesn't currently support actions or facts added in UserPatch, particularly mathematical operations on goals.

Need to add support and test cases for these.

The first major test case to support is the full AoE2 HD AI that comes bundled with Definite Edition.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.