States and Rolls

Started by DimDragon, March 21, 2010, 06:14:35 AM

Previous topic - Next topic

DimDragon

Hello, I have been experimenting with states for a while and just want to share my findings. We have available 3 native functions which operate closely together :

native void AINewChooseSubState (int player, int which, int min, int max, int defaultSubState);
native void AISetSubStateChance (int subState, int chance);
native int AIChooseSubState ();

First one is something like 'randomizer' function. where :

which : state you want to set, one of :

const int e_mainState       = 1;
const int e_mainSubState    = 2;
const int e_attackState     = 3;
const int e_divert1State    = 4;
const int e_divert2State    = 5;
const int e_openRollState   = 6;
const int e_middleRollState = 7;
const int e_lateRollState   = 8;

Then min and max are basically the range of the roll you are taking, and finally "defaultSubState" is what you have set in case selection fails ( will get back on that in a while ).

Next you have AISetSubStateChance which allows you to set percentage/probability ( 100 = 100% ) per every choice you want to consider. So lets say for example in your opening build you may take 3 different paths but the choose is not random pick one of three but more 'smart' based on some variables you can have probability for every branch. Sample code will be like :

        AINewChooseSubState( player, e_openRollState, 0, 100, stateChoice1 );
        AISetSubStateChance( stateChoice1, 50);
        AISetSubStateChance( stateChoice2, 30);
        AISetSubStateChance( stateChoice3, 20);
        int selectedChoice = AIChooseSubState();
        AISetMainState(player, selectedChoice, e_mainSubState_Unset);

When you run this, your e_openRollState will be set to a number between 0-100(min - max) but the selectedChoice returned will be stateChoice1 50% of the time, stateChoice2 30% of the time, etc

Now some notes : 'defaultSubState' may be different then choices defined, since percentages can be lower then 100, in this case for the rest of the rolls, default is returned, if sum is greater then 100 then default is returned always. Also keep in mind then due to a fact you are working with integers some rounding is made in internal function ( which is unknown to me ) so in case you make for example range 1 - 7 and probability 50-50 you still may get default returned, using bigger roll spread diminishes this. In order to use AIChooseSubState you need to call AINewChooseSubState prior every usage.

Finally since call to the AIChooseSubState() effectively sets the state you can use it for random choice of main or attack states like this :

AINewChooseSubState( player, e_mainState, e_mainState_OpenGnd0, e_mainState_OpenGnd2, e_mainSubState_Unset );
AIChooseSubState();

This will set mainState to one of the 3 opening states.

Since AIBot is in most cases is a state engine I believe we can all use those. Of course everyone can mimic this and write own routine for probability randomization.

Regards DimDragon

Astazha

Thank you for exploring this and sharing what you found.  There's a lot of mysterious stuff in that API.