Monday, February 11, 2013

Implementing a Finite State Machine for Saga

So, I hope to get some good feedback on this blog post, as I need to know if this example is too specific to a game system that it is not usable or understandable for those not familiar with the game system in question (which is Saga, by Tomahawk Studios).

By the way, this is dedicated to my internet buddy, Shaun Travers, who is weathering a painful condition. Shaun's blog provided some great reading and inspiration on game mechanics and analysis. Shaun, I hope this helps take your mind off of things and is something you can find a use or inspiration for in your gaming.

The Story So Far…

If you have been tracking some of my gaming over on my Dale's Wargames blog, then you know that I have not only started playing Saga, but being the incurable 'rules tweaker' that I am, could not play the game straight and hard to start developing my own factions … in another part of the world … for another time period! In my defense that is largely because:

  1. I heard great things about the rules in a series of podcast interviews, so I knew I wanted to try it.
  2. I purchased (on impulse) a large, painted collection of 25mm Aztecs and I was searching for a set of rules to use with them. As there are more than 450 figures in the collection, I would still have more than enough figures left over after I built two DBA-sized armies.
  3. Meso-American warfare has a lot of similarities to Dark Ages 'shield wall'-type warfare. (Trust me, when you have a 450 figure collection collecting dust it is easy to convince yourself of that.)
  4. It was going to take me a long time to make two Dark Ages armies out of wood (see my Wooden Warriors blog).
So, with those noble justifications I set about creating a Meso-American variant for Saga. I pulled out my two Osprey books and one Ian Heath book on the Aztecs and started reading. Before long I knew that the enemy I wanted to use for the Aztecs were the Tlaxcaltecs1. This would give me a missile-oriented army to oppose the vicious and melee-oriented army; a nice contrast.

At first I simply used the Welsh abilities as the Tlaxcaltecs, and that was great for learning the rules and understanding the dynamics of the game (good to know the rules before you tweak them), but as the Welsh are mostly armed with javelins and the Tlaxcaltecs with bows, and javelins and bows working completely different in Saga, it was obvious that I needed to model the Tlaxcaltecs a little more accurately in order to test the abilities I would give them. I finally put the first draft out this weekend, including a faction-specific battle board.

The Basics of Saga

So, in order to understand what I am about to present it helps to know how Saga works. You can get some deeper ideas from my review of the rules and subsequent battle reports, but here are the basics.

Each turn a player rolls SAGA dice. Each die has three different symbols on it (the Common symbol being on three faces, the Uncommon on two faces, and the Rare symbol on a single face). These symbols are matched to the symbols shown on the faction's battle board (my Tlaxcaltec one being shown to the right, although it uses '1-3', '4-5', and '6' as its symbols so you can use regular six-sided dice as SAGA dice). Fulfilling the dice requirements of an ability (a box on the board) allows you to use that ability during your or your opponent's turn (the ability will specify which).

These abilities and their combinations, along with the special rules granted to the faction (akin to an Army List) give it its unique historical flavor. The Welsh battle board tends towards skirmishing and annoying the enemy while the Viking battle board tends toward crushing melee.

Once you have finished allocating dice you start activating units one at a time and giving them an order, either Movement, Shooting, or Rest. Some abilities can be used during specific actions, like Movement or Shooting, and some can be in reaction to your enemy's actions. A turn is over when you have activated all the units you wish to and completed the ordered actions.

A unit can be ordered to take more than one action, by using more activation dice and accumulating fatigue faster. So by allocating three activation dice to a unit it could move three times, shoot three times, rest once, move once, and shoot once, or any number of other combinations. Given that you have only so many dice, for both activations and abilities, you do not have complete freedom with your troops; you often have to make hard choices on how to allocate your dice for usage.

Isn't This a Solo Gaming Blog?

And this brings us to solo gaming. This decision-making process – on how to allocate your dice and what actions to take with your units – is what generally makes these sorts of rules so hard to play solo. Of course there is the method to 'play each side to the best of your ability', but to my mind that is the least challenging method of play. Bias towards one side always creeps in.

My goal has largely been to design an artificial opponent in such a way that much of the decision-making is taken away from the player and performed by a 'program'. If that program can be structured and standardized, then it might even be possible to develop several programs and trade them between players. The goal might not be so much to develop a programmed opponent that cannot be beaten as much as one that is both entertaining and challenging. (At this point I would settle for plausible.)

So the first task I want to solve is how to decide, for the programmed opponent, which abilities to allocate to with the SAGA dice rolled. As the abilities define which unit types are eligible to activate (Move, Shoot, or Rest) and what advantages they will have, this is a critical piece to program. It is probably also one of the hardest because it essentially defines your programmed opponent's whole strategy.

So I present to you the first draft of the Tlaxcaltec 'programmed opponent'.


Tlaxcaltec Program

This document contains the 'program' for a Tlaxcaltec force fighting the Aztecs using the Saga miniatures rules. This program provides the 'intelligence' in how the Tlaxcaltec side should be run, especially with regards to how Saga dice should be allocated abilities and for unit activations. When units are activated, the program indicates which actions should be taken (Movement, Shooting, or Rest).

This program is very specific to the Tlaxcaltec force, as it refers to Saga abilities that they possess, along with their troop types. It is also specific to fighting against the Aztecs, as their fighting style is embedded into these rules.

How to Use the Program

Every turn the Tlaxcaltec side starts in one of four particular states:

* All enemy units are outside of missile weapon range
* All enemy units are outside of charge range (but inside missile weapon range)
* Friendly units are within one or more enemy units' charge range

At the start of each turn the player goes down the list of Triggers, in order, to see if the force's state changes. If so, the Exit actions of the state you are leaving are executed, followed bby the Enter actions of the new state. Once that is complete, follow the Orders section to determine which SAGA dice to roll and how to allocate them. Once complete, follow the instructions in the Activation section to determine the order of unit activation and what type of action each unit will take.

----

State: all enemy outside of missile weapon range
Note that being outside of missile weapon range includes being within range of a unit that is out of line of sight and can currently neither fire, nor be fired upon.
Description: Units will build high-end SAGA abilities and activate ONLY to rest.
Triggers:
Enemy within charge range: exit this state and go to state 'enemy within charge range'
Enemy within missile weapon range: exit this state and go to state 'all enemy outside of charge range'
Enter: no action to take
Exit: no action to take
Orders Phase: use SAGA dice in the following order:
1. Re-roll all unallocated dice, allocated Common dice, and dice allocated in the leftmost column.
2. If you have more than two Rare symbols use one dice for the 'Activation Pool' ability.
3. Allocate enough dice to activate all Exhausted units once. Their activation will be used to Rest.
4. Allocate enough Common dice to activate all units that are one FATIGUE away from Exhaustion [1]. Their activation will be used to Rest.
5. Allocate Rare dice to Saga abilities in the order: Heavy Arrows, Eye of the Eagle, Loose Arrows!, Activation Pool, and Attack Pool, skipping any ability that already met its dice requirement.
6. Allocate Uncommon dice to Saga abilities in the order: Loose Arrows!, Aimed Volley, Eye of the Eagle, Heavy Arrows, Massed Volley [3], Shoulder to Shoulder, Shielded Volley, and Attack Pool, skipping any ability that already has already met its dice requirement.
7. Allocate Common dice to Saga abilities in the order: Harassing Fire, Heavy Arrows, Aimed Volley, Shoulder to Shoulder, Common Efforts [2], Shielded Volley, and Attack Pool, skipping any ability that already has already met its dice requirement.
[1] Note that a unit that qualifies for step 2 does not qualify for step 3, even if allocated a die in step 2.
[2] Note that funding this ability may cause you to require fewer activations or different dice for steps 3 and 4.
[3] Note that funding this ability may force you to exit this state and enter the 'all enemy outside of charge range' state if it would make any of your bow-armed units eligible to fire upon an enemy unit.
Activation Phase: Activate Exhausted units before other units. Activate Zoomorphic Warriors before Warriors, who activate before Levy.
Movement: No activations should be used for Movement actions.
Shooting: No activations should be used for Shooting actions.
Melee: If, due to an enemy ability, a unit is drawn into Melee, the ability 'Show of Strength' should be used if available. Otherwise use 'Shoulder to Shoulder' and 'Attack Pool', if they are available.
Activation/Reaction: Use the ability 'Harassing Fire' only on an enemy unit 

State: all enemy outside of charge range
Note that being outside of charge range is being outside of the normal movement allowance for one Movement action (i.e. L for mounted in the open, M for foot in the open, and S for either type in or that must move through Uneven Ground).
Description: Units will primarily utilize their missile weapons for Shooting action, resting with the those that require it, and building SAGA abilities.
Triggers:
Enemy within charge range: exit this state and go to state 'enemy within charge range'
No enemy within missile weapon range: exit this state and go to state 'all enemy outside of missile weapon range'
Enter: no action to take
Exit: no action to take
Orders Phase: use SAGA dice in the following order:
1. Re-roll all unallocated dice, allocated Common dice, and dice allocated in the leftmost column.
2. If you have more than two Rare symbols use one dice for the 'Activation Pool' ability.
3. Allocate enough dice to activate all Exhausted units once. Their activation will be used to Rest.
4. Allocate enough Common dice to activate all units that are one FATIGUE away from Exhaustion [1]. Their activation will be used to Rest.
5. Allocate Rare dice to Saga abilities in the order: Heavy Arrows, Eye of the Eagle, Loose Arrows! [3], Activation Pool, and Attack Pool, skipping any ability that already met its dice requirement.
6. Allocate enough Common or Uncommon dice to activate all units that are armed with missile weapons and currently eligible to fire for Shooting actions.
7. Allocate Uncommon dice to Saga abilities in the order: Loose Arrows! [3], Aimed Volley, Eye of the Eagle, Heavy Arrows, Massed Volley [3], Shoulder to Shoulder, Shielded Volley [3], and Attack Pool, skipping any ability that already has already met its dice requirement.
8. Allocate Common dice to Saga abilities in the order: Harassing Fire, Heavy Arrows, Aimed Volley, Shoulder to Shoulder, Common Efforts [2], Shielded Volley [3], and Attack Pool, skipping any ability that already has already met its dice requirement.
[1] Note that a unit that qualifies for step 3 does not qualify for step 4, even if allocated a die in step 3.
[2] Note that funding this ability may cause you to require fewer activations or different dice for steps 3 and 4.
[3] Note that funding this ability may cause you to require fewer activations for steps 6.
Activation Phase: Activate Exhausted units before other units. Activate units that are within one FATIGUE of exhaustion and have not yet activated after activating Exhausted units and before other units. Activate Zoomorphic Warriors before Warriors, who activate before Levy.
Movement: No activations should be used for Movement actions.
Shooting: Shooting is always at the enemy unit that can be hit by the greater number of figures. If more than one unit is eligible, fire at the closest enemy unit. If there is still a tie, fire at the unit fired at last. If no unit had been fired upon previously, randomly determine the target between the closest eligible targets.
Melee: If, due to an enemy ability, a unit is drawn into Melee, the ability 'Show of Strength' should be used if available. Otherwise use 'Shoulder to Shoulder' and 'Attack Pool', if they are available.

State: any enemy within charge range
Note that being within charge range is being within one Movement action of the enemy unit's normal movement allowance (i.e. L for mounted in the open, M for foot in the open, and S for either type in or that must move through Uneven Ground).
Description: Zoomorphic Warriors will charge, or get into position to charge. Other units will utilize their missile weapons for Shooting actions, resting with those that require it, and building SAGA abilities.
Triggers:
No enemy within charge range: exit this state and go to state 'all enemy outside of charge range'
No enemy within missile weapon range: exit this state and go to state 'all enemy outside of missile weapon range'
Enter: no action to take
Exit: no action to take
Orders Phase: use SAGA dice in the following order:
1. Re-roll all unallocated dice, allocated Common dice, and dice allocated in the leftmost column.
2. If you have more than two Rare symbols use one dice for the 'Activation Pool' ability.
3. Allocate enough dice to activate all Exhausted units once. Their activation will be used to Rest.
4. Allocate enough dice to activate all Zoomorphic Warriors once for a Movement action. [4]
5. Allocate enough Common dice to activate all units that are one FATIGUE away from Exhaustion [1]. Their activation will be used to Rest.
6. Allocate enough dice to activate all Warrior units that have one or two figures remaining for a Movement action.
7. Allocate Rare dice to Saga abilities in the order: Heavy Arrows, Eye of the Eagle, Loose Arrows! [3], Activation Pool, and Attack Pool, skipping any ability that already met its dice requirement.
8. Allocate enough Common or Uncommon dice to activate all units that are armed with missile weapons and currently eligible to fire for Shooting actions.
9. Allocate Uncommon dice to Saga abilities in the order: Loose Arrows! [3], Aimed Volley, Eye of the Eagle, Heavy Arrows, Massed Volley [3], Shoulder to Shoulder, Shielded Volley [3], and Attack Pool, skipping any ability that already has already met its dice requirement.
10. Allocate Common dice to Saga abilities in the order: Harassing Fire, Heavy Arrows, Aimed Volley, Shoulder to Shoulder, Common Efforts [2], Shielded Volley [3], and Attack Pool, skipping any ability that already has already met its dice requirement.
[1] Note that a unit that qualifies for step 3 does not qualify for step 5, even if allocated a die in step 3.
[2] Note that funding this ability may cause you to require fewer activations or different dice for steps 3 and 5.
[3] Note that funding this ability may cause you to require fewer activations for steps 8.
[4] Note that a Zoomorphic Warrior unit close enough to the Warlord can be activated for free, not requiring the allocation of a die for movement.
Activation Phase: Activate Exhausted units before other units. Activate units that are within one FATIGUE of exhaustion, or have one or two figures remaining in the unit, and have not yet activated after activating Exhausted units and before other units. Activate Warriors before Levy, who activate before Zoomorphic Warriors. The Warriors and Levy activate earlier than the Zoomorphic Warriors specifically so they can shoot into enemy units and soften them up prior to the Zoomorphic Warriors' charge.
Movement: Zoomorphic Warriors will activate for Movement, moving directly toward the closest unit that triggered the state change, if the unit has three or more figures remaining, or two or more figures remaining and moving with the Warlord. If there is more than one Zoomorphic Warrior unit, each can move towards a different unit, but in all cases move towards the closest units.
Shooting: Shooting is always at the enemy unit that can be hit by the greater number of figures. If more than one unit is eligible, fire at the closest enemy unit. If there is still a tie, fire at the unit fired at last. If no unit had been fired upon previously, randomly determine the target between the closest eligible targets.
Melee: If the Zoomorphic Warriors enter melee, the abilities 'Shoudler to Shoulder' and 'Attack Pool' should be used, if available. If, due to an enemy ability, a unit other than Zoomorphic Warriors is drawn into Melee, the ability 'Show of Strength' should be used if available. Otherwise use 'Shoulder to Shoulder' and 'Attack Pool', if they are available.

All references to abilities can be found on the battle board above. "Zoomorphic Warriors" are the elites – the "Hearthguard" in Saga – while I retain the names "Warriors" and "Levy" as they are used in Saga.

Again, I welcome any comments, even those along the lines of "I cannot make heads or tails of what you are trying to do because I don't understand Saga."


1 I made the mistake of calling them 'Tlaxcalans', which apparently is an Anglicized term fallen out of favor. I still have to correct the battle board I made.

3 comments:

  1. Dale

    there is lots of good stuff here. it made sense to me, even if i have not done state tables for nearly 20 years, and do not know the rules. it has got lots of promise, more so than flow charts and if/then combos. not to digress but i think i mentioned it last year sometime but state tables could work for ancients, espcially ones with undivsible units. the furtherist i got was maybe an army with refuse left flank orders and the left flank unit does not charge until unit is wirhin certain distance. this can be extended as you have done above. when i am out of surgery i would love to continue the discussion on state tables. lots to think about. thanks Dale.

    ReplyDelete
  2. Very thought provoking series of posts. I like it because it seems that you can program your opponent. A lot to digest, but worth investigating. I would also jump all over those books if I didn't have so many unread lying around right now. Sorry to hear that Shaun is not well. Good luck to him.

    ReplyDelete
  3. Nice post. A challenge in the case of using FSMs to create solo opponents is in avoiding complexity from e.g. combinatory explosion of states in order to make them bearable for a human to interpret. I suppose that some non-determinism could be exploited to that end, and finding the right balance is an interesting proposition. Further, making an adequate model of the game sounds like a fun challenge.

    I had been toying with the idea of experimenting with FSMs in solo games since the end of the last year and your post inspired me to move forward. Right now I am playtesting a very simple "alien safari" scenario where the hunted aliens change behavior depending on state.

    ReplyDelete