Skip to content

JOTworks/AgeOfPython

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Age Of Python

Script your AOE2 AI in limited python instead of defrules

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Supported Python
  5. Roadmap
  6. Contributing

About The Project

CURRENTLY IN ALPHA ... Functional, but missing features, and limmited error handling

You can write in Python, and it will compile your code into AOE2Script. No more defrules, all commands look like normal functions.

Another main feature is that it Scrapes from https://airef.github.io/ So there is autocomplete and infromation on commands and parameter types.

the purpose of this project is to improve redablility and reusiblility so you can write and debug AIs faster and better It includes functions, loops, nested if statements, Arrays ect.

(back to top)

Getting Started

Prerequisites

For now you will need to know how to code in both python and aoe2script.

Installation

_Clone this into the folder C:\Program Files (x86)\Steam\steamapps\common\AoE2DE\resources_common\ai\ _

  1. Clone the repo

    git clone https://github.com/JOTworks/AgeOfPython.git
  2. install python and all the dependencies

(back to top)

Usage

Create a .aop file in the AgeOfPython folder. that is your base python ai code. when you run that file it will create the .per and .ai files in the ia\ folder for you. Run it with the python command like so if you are in the AgeOfPython folder

python .\src\Main.py -f yourAiName.py

(back to top)

Supported Python

If statemnts

if statments can do basic comparisons and any operators. if there is to complex of an expression, break it out before the if statment

if command(arg) and command(arg,arg):
  x = 1

For and While loops

you can do loops! and nest them, it makes readibility ver nice for algerithms

#set current_point
for i in range(-1,2):
    for j in range(-1,2):
        temp_point = last_point
        temp_point += (i, J)
        up_get_point_terrain(temp_point, terrain_id)

        if temp_point != last_point and up_point_terrain(temp_terraitemp_pointn_point) == Terrain.terrain_water_beach:
          current_point = temp_point

Asigning

Unlike Python, this is A strongly typed language. Once a varilabe has a type it will raise an error is another is used. to avoid confussion and the most bugs, use constructors on varaible. (sometimes this works without, but not for returning values of a function for exmaple)

x = Integer()
tc_location = Point()
tc_location = State()
my_array = (Point, 12) # (type, length)

if you add values into the constructor they will be asigned first pass of the code, and will then be disabled with a disable_self() Note that all variables (goals) are set to -1 when aoe2 starts

x = Integer(10)
tc_location = Point(0,0)

asignign variables supports arrays and AOP class attributes

x = y + 3 * 2
myArray[i] = 37
my_point.x = 3
my_point = (3,2)
x = y = z = 1

However do not add array slices inside array slices, and nest other asignemnts at your own risk

my_rray[other_array[r]] = 37

Functions

Functions require strong typeing for their parameter types and return types. you can notate that like in python, but now it is required. this function bellow takes a buildingId and will try to build that building, returning 1 on success and 0 on failer. (you cannot use function returns in conditionals)

def try_build(building:BuildingId) -> Integer:
    if up_can_build(_, building) and up_pending_objects(building) < 1:
        up_build(_,_,building)
        return 1
    return 0

all functions pass by value and all variables in the function are only in their own scope. Note that it is the same variable for every call of the function, so if you do not set the varible it will have the value for the last call. If you need a variable from ouside the funtion you can use global to access it. otherwize it will create a new function scoped veriable.
``` def build_around_tc(building:BuildingId, radius:Integer) -> Integer: global tc_location place_point = Point() if tc_location.x == -1: chat_to_all("E: tc_location not set, cannot build_around_tc") return -1 ```
aoe2script Commands now look like functions, as you have seen above. but they are not the same! if you use an aoe2script command it will work like it does in the original langauge. I have just added things for conveineince bellow.



if the command ends with CompareOp and value, you can pull that outside of the function. (effectivly it is still in the function and can't take complex input)

building_type_count_total(BuildingId.house) >= 5

g: and c: are removed, as I deal with all of the allocation of memory, so you can ignore that and it will be added in dynamicly

up_filter_distance(10, my_max)  #used to look like this -> (up-filter-distance c: 10 g: my_max)

Strategic numbers can be asigned in shorthand

SN.placement_zone_size = 7 #used to look like this -> (up-modify-sn sn-placement_zone_size c:= 7)

(back to top)

Roadmap

Pre Release

  • Add object types:
    • Point
    • State
    • Const
  • fix curent bugs
  • implement disable-self in if statments

Alpha Release

  • add loops:
    • while loop
    • for loop
  • add functions
  • Add simplified conditional expressions
  • Add better errors and comments to track user bugs
  • Add test casses:
    • parser
    • scanner
    • asserter
    • Interpreter
    • printer

Beta Release

  • Robust functions:
    • Add default values
    • Add return values
  • optimize rule usage
    • compine close truesy rules
    • remove jump rules on flat ifs & loops
    • refactor out lagging do-nothing rules on ifs
    • refactor out struct init asignment of +0
  • optimize goal usage
    • dealocate when out of scope
  • add predefined ai numbers
  • Add printout of rule number and goal useage

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

About

Compiler that translates limited Python into aoeScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •