Results 1 to 1 of 1

Thread: Towards a Factions AI: Part A -- Simulator for Rank-0 units

  1. #1
    Skald Aleonymous's Avatar
    Join Date
    Mar 2013

    Towards a Factions AI: Part A -- Simulator for Rank-0 units


    I've been toying with the mathematical concepts of the TBS battle mechanics (what I refer to as the "ASWEAR" system, an acronym from Arm/Str/Wp/Ex/Ab/Rank) for quite some time, and was meaning to put a computer to do all the reasoning for me. Already, skills like Puncture demand for some quick "math" thinking to calculate, so why not expand this even further, and give it to somebody more qualified to do it?

    Anyway, the ultimate goal of this endeavor of mine is to develop an Artificial Intelligence (AI), that will
    • be capable of playing matches against me -- and beating me ,
    • help identify optimal choices for each unit's turn,
    • assess/compare/evaluate relative-performance of various builds.

    Building a TBSF simulator

    The first step was creating the two teams, assigning their stats, and implementing the turn-queuing employed by Factions, Pillage-mode included. The second (and quite more difficult) step was implementing the positioning on the rect-grid: moving units around, pathfinding etc. The most difficult aspect of positioning was the co-existence of 2x2 & 1x1 units, so I had to do a workaround for that. The third step was implementing the rank-0 units' (Raiders, Archers, Shieldbangers and Warriors) passive abilities. Puncture and Return-the-Favor where really simple, while Shield-Wall and Heavy-Impact were a little more complicated since they gotta take into account adjacencies with ally units etc. The fourth step was tying all the previous together, e.g. taking RtF from HI, removing a unit from turn-queue when it dies, modifying ShW bonus after every movement/death, calculating coals-damage etc. Finally, the fifth step was properly defining the "Orders" given to a unit in each of his turn. Actually, this simulates all the mouse-clicks you make during a turn. I've broken this down into the following sequence of "questions/answers":
    1. Rest? -- Yes/no
    2. Blow Horn? -- Provide number of Horn-Blows
    3. Move? -- Provide target-tile
    4. Blow Horn (again)? -- Provide number of horn-blows
    5. Action? -- Make an STR/ARM-attack or use Active-ability (coming soon...)
    6. Action target? -- Provide target unit or tile for Action
    7. Willpower? -- Provide willpower invested on Action (or Active-ability Rank)

    Having set-up all the above, I started putting them into a computer program. I'm quite proficient in Matlab, a scientific program with an easy to learn language, tons of utility functions (especially useful are those operating on sets & arrays) and capable of easy and pretty data manipulation/visualization and post-processing. Once I had this ready, I set-up two teams, picked a map, arrayed the units and started taking turns with each team having a power-0 battles with myself

    Here (Twitch Link) is a small sample of such a battle, between the Blue & Red team, at the Great-Hall, using mirror builds & deployments. Input is given my mouse R/L-buttons and keyboard, and it can then be modified in sum-up "Orders Vector" GUI before issued/executed. I didn't finish the battle because I just wanted to show that the basics described above were all up-and-acting. Here's a snapshot of how this looks like:

    Figure: In this snapshot, the Warrior of the Blue-team (he is the unit with serial-number [SN] #6 in his team) is about to act. According to the "Orders Vector" he chooses: (1) not to rest, (2) not to use Horn before moving, (3) to move to tile #185 [that number is the top-left tile for 2x2 sized units], (4) not to use Horn after moving, (5) to attack Red-team member with SN #2 [that's a Raider], (6) to perform an ARM attack, (7) to use 2 WP on that attack.

    Towards an AI

    So, the next step towards this AI is trying to devise an algorithm for evaluating moves & actions for each unit's turn. This is quite complicated as it has gotta take into account various aspects like
    • positioning,
    • potential damage (ARM and/or STR) output,
    • general "condition" of allies and enemies,
    • turn order of allies and enemies,
    • efficient use of limited resources, namely WP and time (!).

    The most intriguing part is requesting the AI to operate iteratively/recursively, meaning that to have it asking it's self "What would I do next if I were the opponent and I did this move now?" This final aspect seems rather difficult and far-fetched for the moment, so let's leave it for now.

    After long discussions with battle-worn strategists (raven2134, Tirean etc), we concluded that one good way to do the above "evaluations" is applying appropriate "weights" on each of the above aspects/choices. Once this weighting is set-up and tuned/balanced, a unit can choose the "heaviest" (most wise) option. Also, using an RNG could make the AI make slightly different choices given exactly the same conditions, in order to introduce the "human error" factor, or the unpredictability. For instance, how --relatively-- important is it to sacrifice an archer's safety (e.g. by moving her in harm's way) for the purpose of maiming a high-STR/low-ARM Varl about to kill your last remaining breaker? All this, and many and more, need to be defined and investigated...

    So, feel free to drop any suggestions and comments. Technically specific remarks from programming-literate vikings (and AI architects, machine-learning master etc) would be most appreciated

    *** John -- What pathfinding algorithm did you use for unit movement? I've implement the classical Dijkstra one, and by appropriate manipulations I've made him able to safely side-step burning-coals, when an "equal-cost" path exists. Waypoints are very helpful -- especially when there's RoA about -- but this simple thing of "proposing" a coal-free path by default would be extra helpful.
    Last edited by Aleonymous; 10-16-2014 at 11:02 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts