Wednesday, 10 November 2021

v.0.4-dev - 'Throw Team-Mate' Implementation

 In v.0.4, Skill 'Throw Team-Mate' (and 'Right Stuff' and 'Always Hungry') has been implemented.

User Interface Implementation

This section explains how user can use the skill - for other existing rules see first release article.

1) Select (left click) the player with 'Throw Team-Mate' and click on the 'Pass' button

As usual, safe moving squares are displayed in green and risky in red.

2) Then move player next a player with 'Right Stuff' skill (right click on square to move).


Eligible players to be thrown are highlighted in blue - you still can move if you do not want to throw one of these players.

3) Select player to throw (left click).

Then you see all squares where players can be thrown:


4) Select square to throw (right click) and hope for the best! 🙏

Which is unlikely to happen 😁

AI Implementation

AI will use the skill for 2 different reasons:
- avoid opposite player to score - defensive use;
- try to score - offensive use.

Defensive use

Context: next team is about to score. No wizard remains, and there is no available player to blitz the ball carrier. Only way to stop ball carrier is to throw team-mate! Best would be to fall on him, but if thrown player can be moved to simply force a block/blitz or dodge, it's better than nothing!

How the AI uses skill in this case?

- It checks if opposite player can score in one turn without 'going for it';
- If yes different probabilities are calculated:

1) For each possible thrower (player with 'Throw Team-Mate), it checks if he can throw a 'right stuff' player next him on the ball carrier. If yes, we record the probability of success - PthrowPlayer.

We take into account:

- probability to activate player - PActivation (for 'Bone-Head' skill for example);
- probability to success 'Always Hungry' Roll (if relevant) - PAlwayshungry;
- probability to not fumble player - PFumble (tackle zones are taken into account);

Here we do not take into account probability of success landing - but it will be done in Offensive Use section. So probability to throw player is (for each pair Thrower/thrown player):

PThrow = PActivation * PAlwaysHungry * PFumble


2) Same calculation but taking into account that 'thrower' can move before to throw team-mate - all possible move probabilities are already known/calculated by the AI. We check all neighbor squares of thrower as it can impact probability (probability to move there and probability to throw player) due to possible tackling zones;

P = PMoveThrower * PThrow 

Best probability between 1) and 2) is selected - to be precise, best probability of all the possible combinations.

Notice that between 2 equal probabilities, the priority is to throw a player that has not yet moved: if landing is successful he will be able to bother ball carrier.

3) If previous points are not possible (because 'right stuff' player is too far from ball carrier), same calculation is done but taking into account that 'right stuff' player will first move - to enter into a square where he can be thrown on ball carrier. Final probability is then: 

P = PMoveThrown *  PMoveThrower * PThrow 

The thrown player will not be able to move after landing, so chances of success are low 😋

In the context of a League/Tournament, AI should not use this skill for defensive skill. Because potential gain (avoiding to receive a touchdown) probability is too low in comparison of probably to get a player injuried/dead!
Nevertheless because it's funny when it works, AI will use the skill for defensive skill  😁

Offensive use

This is the most useful use of the skill, but let's be honest: it rarely changes the result of a game! 
Actually, before each movement, AI calculates probability to score when he has the ball. It can be done:

- with a simple move;
- with a hand-off move then a move;
- with a pass move then a move;
- with a hand-off move then a pass move then a move;
- with a pass move then a hand-off move then a move;

All these probabilities were already calculated before this implementation. They take into account all possible player skills (dodge, pass, tackle, sure feet, sprint, hail mary pass, etc), and all possible combinations to keep at the end the highest one.

With this throw Team-mate skill, new probabilities have to be assessed:

- throw ball carrier (if he has not yet moved) then move ball carrier;
- move thrower then throw ball carrier player then move ball carrier;
- hand-off the ball to a player then throw him (with, again, eventually a move of the thrower), then move ball carrier;

Probability to throw a ball carrier that has already moved is not calculated - this has really too low change of success.

Practically, the attempt to score a touch down is done only if value is higher than a fixed value, or if it's the last turn of the half. From a probability point of view, we can see that throw team-mate will be used only if there is no other solution...

To score a touch down, this time it is necessary to assess probability to land and then probably to reach the TD, which is not guaranteed with the 3 'bounces'!
Probability to land 'on feet' (PLand) is not very precise as we are not sure of how many tackle zones we will have - well we can calculate the exact probability, but this is not needed and it has not been calculated.
What is important is to know if it will land (after bounces) 3 squares closer to the touch down, 2, 1, at same row as destination chosen by thrower, 1 square further, 2 or 3. It's important because player can land to a square where he's too far to touch down. Also to know if he will need to use 1, 2 or eventually 3 'going for it'. This probability to reach TD can be calculated as followed:

PMoveToTd = P+3 * PmoveToTd+3 + P+2 * PmoveToTd+2 + P+1 * PmoveToTd+1 + P0 * PmoveToTd + P-1 * PmoveToTd-1 + P-2 * PmoveToTd-2 + P-3 * PmoveToTd-3 

where:

- P3 is the probability that the ball bounces at the end on a square (pitch column) which is 3 squares closest to TD that initial destination;
- PmoveToTd+3 is the probability that if a player starts at this column, he will reach the TD. This takes into account player move value and number of 'going for it' needed (and skills like 'Sprint', 'Sure Feet', etc.), but we do suppose we will have no dodge. It's too complicated to assess the right probability, and this is not necessary. Notice this probability can be null.
- etc for other P;

Notice for 'Offensive Use' destination chosen is always far enough of the border - thrown player will never goes out of pitch. At equal probability, AI chooses also a destination where number of opposite players is low.

In the most complex case where player hand-off the ball to a player that will be thrown (with also a move of the thrower!), the probability to score is then: 

PTD = PHandOffMove * PMoveThrown *  PMoveThrower * PActivation * PAlwaysHungry * PFumble * ( P+3 * PmoveToTd+3 + P+2 * PmoveToTd+2 + P+1 * PmoveToTd+1 + P0 * PmoveToTd + P-1 * PmoveToTd-1 + P-2 * PmoveToTd-2 + P-3 * PmoveToTd-3 )

Quite simple, isn't it??? 😛

Let's watch small video where AI uses the skill!

Notice also that setup is modified for receiving Team if it's the last turn and if there are players to use the skill. If ball goes out of the pitch and must be given to a player, it will also be given to the 'good' player - player with 'Right Stuff' next a player with 'Throw Team-Mate'. This is visible in Part 3 of the video - ball has bounced out of pitch and ball has been given to the right player.