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.



Sunday 31 October 2021

v0.3 is Released!

New version 0.3 available here - add comment if cannot be downloaded.

To summarize: bug corrections + added some missing skills. At UI level, 'gif' are now working and lots of players have new icons when they gain one level! Ogre example:



(Reminder: I'm not author of all these icons, most are coming from other projects like SkiJunkie, AIBowl or Fumbll - to be honest I do not remember what is coming from where, I have downloaded them a loooong time ago)
Previous save should still be compatible. See change log below for the full list of changes.
In the 'not yet implement' side, are still missing:

- Skill 'Bombardier';

- Skill 'Throw Team-Mate' (and all related skills);

- Skill 'Leap';

Also it's is still not yet possible to select inducements before a game - but AI can, and can now use Wizard! UI for tournament/team creation has unfortunately not yet been improved.

Rules are still LRB6 rules - yes I'm some years in late 😀

Next release will (I hope) contain all the rules. After that this will highly increase time available for developing the AI itself, which has still a too low level in my opinion. Idea is also to be able to create some leagues with divisions instead of simple tournament.

A FFAI version (see https://github.com/njustesen/ffai) exists but is not yet enough tested and consequently is not released. You can see a video of v.0.3 versus v.0.2 using FFAI framework:

Some behaviors are strange and probably due to bug when interfacing Drefsante AI and FFAI - see for example last turn of red team at first half where player starts a Pass action (in order to score), picks-up the ball... and then does not do the pass! On the other hand some new AI features are visible (like Ball carrier can now stay several turns next Touchdown area without scoring if not threatened and if team is not loosing). But some strange player moves are also visible, it remains tough work! 💪
Just for fun, 100 matches have been played between 2 last releases (Human vs Human) with a result of 40 Wins (for new release), 26 Draws and 34 Losses. 100 is not significant, but trend is that AI level has not been increased a lot in this release. In comparison my last 20 games against Drefsante AI v.0.3: 20 Wins and 2 goals received 😕
Still some work needed before reaching human level !
Notice result versus FFAI scripted bot is good on last 100 matches (Human vs Human): 89 Wins, 9 Draws, 2 Loses.

Final change log:

Version 0.3

Requires now Java 11.

Rules Implementation

- Add skill 'Kick';

- Add skill 'Piling On';

- Add skill 'Hail Mary Pass';

- Add skill 'Blood Lust';

- Add skill 'Diving Catch';

- Add skill 'Kick-Off Return';

- Add skill 'Animosity';

- Add skill 'Multiple Block';

- Add skill 'Dump-Off';

- Add skill 'Pass Block';

- Add Wizard (for AI only);

Bug correction

- 'Diving Catch' skill was sometimes used as if it was skill 'Diving Tackle';

- Was not possible to correctly use 'Hypnotic gaz';

- Correct bug where ball can bounce too many times;

- Correct bug where failed block against player with skill 'Block' was not ending the team's turn;

- Correct bug where not relevant player (prone, bone-head, etc) could catch the ball from accurate pass;

- Correct bug where Stunned player (after pitch invasion) can keep the ball;

- Correct bug to avoid that player picks up the ball if ball is in the air (at quick snap of blitz event for example);

- Correct bug at kick-off if player selected to get the ball (if ball goes out of pitch) is stunned ('Pitch invasion') or Ko ('throw rock'): the ball was disappeared;

- Correct bug where kick-off set-up and kicking events were played twice at the start of second half if previous turn  ended with a Touchdown;

- Skill 'Pro' was not correctly implemented;

- With 'Jump up' skill it was possible to block while stunned. Now it's only possible if knock down;

Was not possible to use re-roll when failing Jump Up on block;

AI improvements

- Avoid not needed catcher move;

- Improve move to bother ball carrier;

- Improve 'follow' behavior;

- Correction in pass probabilities - fumbble was not taken into account;

- Correction in pass probabilities: probability of moving of the thrower was not correctly taken into account;

- Correction in HandOff probability;

- Improve global defensive position;

- Improve Block/Blitz behavior;

- Correct bug where AI wanted to always move before to pass ball;

- Now AI is not moving on a ball if not explicitly wished;

- Better estimation of remaining turns needed for a player to move to touch down area;

- Tune selection of skill after a game;

- If AI is last to play during a half and cannot score, he will do the easiest pass in order to gain experience;

- When available, 'Pro' skill was always used when doing a block, whatever dice result;

- Better take into account 'Tackle' skill;

- Ball carrier can now stay several turns next Touchdown area without scoring if not threatened and if team is not loosing;

UI improvements

- When selecting ball position at kick-off: scatter directions are now visible;

- Correct loading of 'gif' that were not animated;

- Automatic path selected when moving can now never go on the ball square;

- Some players have now a new icon when they gain one level;

- It is now possible to get result of activation Roll without moving (for example Bone Head, Really Stupid or Blood Lust):

  Eventually select your action (it will be considered as Move action if none is selected) and then right click on the player. Activation  result will be visible. It's important because result can impact your planned move (mainly for blood lust). If you right click again on same player, his move is finished. For player without these kills, right click on him end player's action;

- Do not display apothecary icon if team has none apothecary;


Wednesday 15 September 2021

V0.3-dev Current state of the version

 V0.3-dev Current state of the version

Next version will be 0.3 (one digit has been removed in version number). Below is the status of the change log. Still some improvements are expected before the release. In parallel a proxy version has been developed for FFAI.

Version 0.3
===========
Requires now Java 11.

Rules Implementation
--------------------
- Add skill 'Kick';
- Add skill 'Piling On';
- Add skill 'Hail Mary Pass';
- Add skill 'Blood Lust';
- Add skill 'Diving Catch';
- Add skill 'Kick-Off Return';

Bug correction
--------------
- 'Diving Catch' skill was sometimes used as if it was skill 'Diving Tackle';
- Was not possible to correctly use 'Hypnotic gaz';
- Correct bug where ball can bounce too many times;
- Correct bug where failed block against player with skill 'Block' was not ending the team's turn;

AI improvements
---------------
- Avoid not needed catcher move;
- Improve move to bother ball carrier;
- Improve 'follow' behavior;
- Correction in pass probabilities - fumbble was not taken into account;
- Correction in pass probabilities: probability of moving of the thrower was not correctly taken into account;
- Correction in HandOff probability;
- Improve global defensive position;
- Improve Block/Blitz behavior;
- Correct bug where AI wanted to always move before to pass ball;
- Now AI is not moving on a ball if not explicitly wished;
- Better estimation of remaining turns needed for a player to move to touch down area;
- Tune selection of skill after a game;

UI improvements
---------------
- When selecting ball position at kick-off: scatter directions are now visible;
- Correct loading of 'gif' that were not animated;
- Automatic path selected when moving can now never go on the ball square;

Saturday 7 August 2021

Blood Bowl AI - First Release

 Blood Bowl AI - First Release

Here it is, a new Blood Bowl AI implementation (using Blood Bowl Living Rulebook 6.0): BloodBowl_0_0_2.jar.

Requires Java 1.8.
Tested only on Windows.

Small tutorial

Download .jar file and type in a command prompt: java -jar bloodbowl-0.0.2.jar.
Click on File → New to create a new Tournament.

You get following options:

Number of Rounds: indicate number of times each team plays against same team.
Number of Human Teams (random): number of user team, race will be selected randomly.
Number of AI (random): number of AI teams, race selected randomly.
Create All: create the 24 available teams (controlled by AI). It is added to the other team created by the other options. Probably not a good idea to create a tournament with so many teams.
Add Team: each click on the button will add a new line where you can fully control the team creation - select if team is controlled by AI or Human, select race and team name. Ensure each team name is unique, there is no check for that.

Total number of teams in the tournament will be the sum of each option selected. Avoid to have a odd number: in this case some games with teams with not same number of played games can occur.

Click on 'Ok' to create the tournament.

As you can see interface is very simple and minimum time has been spent on it :-)


You can see the current team ranking, the schedule of the tournament, what will be the next game and results of already played games.

Team in bold are controlled by Human. Others by AI. 

Before starting any match, select your team and click on 'View Selected Team'. The Team Editor will be visible:


A roster has been selected, but while any match has not been started, you can remove each player and change your roster as you want - button 'Exit' will be unavailable if you do not have 11 players to start.
Once you're done, click on 'Exit', you're back to the ranking table. In the 'Options' menu, you have:


Animation Speed can be changed: by default it's set to 200. It's a delay in ms between two animation steps. I strongly suggest to let the default value. Put it at 0 to have the maximum speed. You can also deactivate AI Game visibility if you do not want to watch AI playing against AI. By default game is visible.

Click on 'Play Next Match' and first match will start. Just enjoy the game if it's an AI vs AI game.
If user team is in the game, you will have to play :-) 
If you close an AI vs AI game while not finished, it will resume without the UI at the maximum speed. If you close a game where you're playing, it will not be possible to resume the tournament - you will have to load your last saved file.
When user is starting a drive, by default a pre set-up is done for you, but you can still modify the positions (left click button) and click on button 'End Turn' when you're done:

If you're the kicking team - as in this example - wait AI set up and then select ball position and then click on 'End Turn'.

How to move your players?

Select the player (left click) and move the cursor:

In this example mouse is at square '69': if player wants to go there, it has 69% of chance to success. Not 100% because he has to do 2 'Going for it'. Square where probability is 100% are displayed in green (note: skills that do not produce turn over if failed like 'Bone Head', 'Take Root' etc are not taken into account here), other in red. The highlighted squares are the squares the player will follow - notice sometimes they are different paths with same probability to go to a square, if you really want to follow one path move your player square by square, mainly if you want to be sure to not pass over a square with the ball.
Right click on a square to move the player.

How to blitz?

If you move the mouse on an opposite player (here the left bottom red player), you will have:


A suggested path for the blitz is given: highlighted squares and final square where blitz occurs contains 2 numbers - probability to reach the square and probability to put the other KO (defender has neither block or dodge → 'Defender Down', 'Defender Stumbles' and 'Both Down' faces make him bite the dust, which is one chance over two). One small blue square means we will throw one dice if blitz is done from this square. Two blue: we will throw two dices and select the result. Two red: we will throw two dices and opposite player will select the result.
If you do not want to follow suggested path for blitz, left click on buttonand then select another path - eventually square by square - before to finally select (right click) the opposite player. It's important to click on this button before to move if you do not click on an opposite player: if not, blitz will not be available, your action will be considered as an action move.

After right click on the opposite payer, dice(s) is (are) rolled:

You have to select the dice (here only one) or click on 'Team Re-Roll' - if available. Then eventually you'll have to select to follow or not the player, or to select a skill or not (like stab).
After that you select square where to push player (left click on a blue square):

If player has remaining move points, you can move it.

How to throw ball?

Select a player (left click). If player has not yet moved and has not yet the ball, click on button:
Then move on the ball (hoping to get it) with right click. If you pick it then put mouse over player with ball and you'll see:

The different colors correspond to the difficulty to pass the ball. Not possible to launch ball further than red squares.
If you move your cursor on a friendly unit and right click on it, an attempt to pass is done.
As for blitz, if you simply move the player with the ball without clicking on the 'pass' button, it will not be allowed to pass the ball - it's considered as a move action.

How to hand off the ball?

Same as for throwing, except you have to use button:

and that you need to be just next player you want to give the ball.

How to make a foul?

Same as blitzing, except you have to use button:

and move on a player on the ground. If you select a player (that has not yet moved) and right click on an opposite player on ground, the best path will be automatically chosen and foul will be done on player. Do not forget your unit can be excluded.

How to make a block?

Select a player next opposite players. As for blitz, you will see small 'red' or 'blue' squares to indicates number of dices for the block. Just right click on unit you want to block.

Notice that after selecting the player (here blue guy with white hair), you see the 'block' dices on player you can block, and all squares where you can move are in 'red' has you will have to dodge if you want to move. If you click on the 'block' button:

you do not see these 'red' square as your action is considered as a block action. Notice practically there is no really need to use the button, just right click on the opponent unit.

Post Match sequence

After the match you come back to the ranking table. Notice an AutoSave file has been created, in the folder 'Save' created in the directory where you have launched the game.

It will not be possible to play next match while all user teams have not upgraded their players (if needed) and select at least 11 players in the roster - with eventually the help of journeymen. To do that, select your team and click on 'View Selected Team'. Next each player that can be upgraded, you will have a button that will allow to upgrade it. You can also enroll free journeyman, or buy journeymen that have played last match. Notice there is no reason to keep some money in your treasury (and not in the bank) as for a user, it is not yet possible to buy inducements before the match.
Be careful before to buy/fire a player, once it's done, it's done...

Loading/Saving Tournament

This is possible when no match is running. Notice there is no save mechanism for a match you are currently playing. Like the 'AutoSave' file, save files are located in the folder 'Save' created in the directory where you have launched the game.

Missing functionalities

- Following skills are not implemented: Piling On, Pass Block, Multiple Block, Kick Off Return, Kick, Hail Mary Pass, Diving Tackle, Blood Lust, Animosity, Bombardier, Throw Team-Mate (and consequently Right Stuff and Always Hungry), Leap, Dump-Off
- Pre-match sequence: AI can do the selection, but not human player - wizard is not yet implemented at all
- Special play cards - it's not intended to implement this
- Mercenary - it's not intended to implement this

Before to improve current AI level, next step will be to add the missing skills - although the most important are implemented.

Tuesday 13 July 2021

Blood Bowl AI Implementation


Project History

Several years ago I've decided to create my own Blood Bowl AI, being quite disappointed by the one available in Cyanide's BB1. This has been done on my free-time, with sometimes some (long) beak (could be some years).
Work is still going on and this blog will help to keep information regarding this development. And to release versions.

First idea was to start from AIBowl which is a Java application (released in 2011) with a UI, an integrated AI and an API that allow you to create your own AI. The existing AI in AIBowl (named Grodbot) is quite good, far better than the Cyanide's one.
My goal was to be able to play some tournaments with AI opponents, where matches AI-AI are really played to take into account injuries, experience and so on.

For these tasks, AIBowl has some issues:
  • match must be played with UI activated, with long animation time →  this takes times to simulate matches;
  • no pre-post matches sequences → league currently not available;
  • lack of debugging tool for AI developers;
I have decided to re-create everything from scratch but using existing icons, portraits etc - from AIBowl but also from other tools. For that reason interfaces are really similar. Game is not 100% finished but is already playable. If I compare my version (named DrefsanteAI) vs AIBowl, here are some advantages:
  • AIvsAI game can be played without UI in about 5 seconds for the whole match;
  • Interface is more user-friendly. For example to move a unit, a predefined best path (where probability to turnover is minimal) is shown, and if user agrees only one click is needed to move the unit. For AIBowl, the unit must be moved square by square;
  • AI can select best option in pre-match sequence;
  • AI can create automatically its initial team;
  • AI can manage pre/post-match sequence (fire, hire, 'upgrade' player, buy inducements, etc);
For some points, AIBowl is still better:
  • In my version 100% of skills are not yet implemented (for example throw team-mate, leap, etc.);
  • It's not expected to add new AI (like in AIBowl). Well it's possible but this is not designed for;
  • Passing the ball is nicer in AIBowl I think :-)
  • No sound implemented (and I do not intend to add some);

AI characteristics:

  • Each action executed is done knowing its probability of success and of turnover. Probability calculation includes for each unit:
    • probability to go from one square to another one (taking into account all skills, like dodge, tentacles, etc);
    •  probability to block opposite unit (split in different categories: probability to put the other down, to turnover, to push, etc), again using all skills (block, wrestle, etc);
    • probability to blitz other units;
    • probability to foul other units (ie probably of success and probability to be excluded);
    • probability to pick up ball;
    • probability to hand off ball to another unit (best path is calculated);
    • probability to pass ball to another unit (here again, all different moves from the ball carrier are tested, to keep the best one);
    • probability to score a TD - for example we compare all possibilities for the ball carrier, ie simply moving to TD area, but also hand-off or pass or both in all possible combinations;
  • Based on all these probabilities, strategic behavior is implemented - like obviously doing safe move at first, and doing more risky option at the end. But some actions have higher priority like those related to the ball (it's better to try to blitz ball carrier than someone else). All this strategic implementation is the crucial part of the AI, it is the AI brain;
  • It takes into account number of remaining turns - for example if possible, you will always see an attempt to score on last turn;
Following link shows (no sound) a half-time between the AI (in red) and myself (blue), to show AI behavior and also to see how the interface works. It has been recorded a few years ago and many AI improvements have been done since the recording.

Remaining work

  • Implement missing skills (80% are implemented);
  • Add missing interface features (like pre match sequence: AI can do the selection, but not human player - wizard is not implemented at all);
  • Test, test and autotests! Bugs of such game can be at many different levels:
    • due to misunderstanding of rules;
    • due to bad implementation of rules;
    • UI bugs;
    • AI bugs (probabilities are calculated but they should be all tested/validated in detail);
  • Still lots of AI work can be done. Mainly to improve strategical defensive play;
  • Could be nice to have a replay mode (and it would help for debugging);

Current AI Level

In one word: decent. I have created a bot that can be used in AIBowl. I inspect the game state of AIBowl, fill the info in DrefsanteAI (like position of each unit, skills, turns, etc) and ask for an answer when requested by AIBowl. It was quite simple - that's why if Cyanide gives an API to develop bot, it would be easy to plug the AI. Some stuffs were not 100% compatible between the 2 software → the version implemented in AIBowl could be a little bit weaker than in reality. Mainly also because it adds a new level of possible bug - the 'information' could be bad transferred from one software to the other one.

It is possible to watch DrefsanteAI versus GrodBot (the AIBowl's AI). Quite funny to watch these 2 AI with zero common coding line playing against each other. Link of a half-time:


I have feeling that my AI is better but I'm not neutral. I would have to do hundreds of games to detect the winner, but this is not easy with AIBowl. After looking dozen of games, I would say DrefsanteAI is better to score but is weaker to defend.

'Soon' I will release my own interface to allow user to play a league, and maybe AIBowl compatible bot if you want to use it with AIBown interface, versus you or GrodBot.

Tournament Interface

Following video shows the simple interface to play a tournament - here only AI vs AI matches. You can see the ranking updating each time a game is finished.

First release

Coming soon!