Wednesday, May 18, 2016

Evaluate average to-hit probability, average hits and criticals in combat situation

You can find data sheets giving the probability to hit if you attack with three dice, have a focus, and the defender has 2 dice. In Squadron Benchmark, the menu entry "Probability" does just that for instance. However, what are the probabilities to hit when you have 4 ships with Twin Laser Turret firing on the same target ? What are then the average hits taken ?

This is the kind of situation now where Squadron Benchmark brings you an answer, in the version 0.8.8. Just press the button displaying the range of fire of the weapon, for as many units as you wish, it now displays additional information.


For instance, Vader, Soontir + Stealth Device + Autothrusters and a shuttle are here facing 2 Syndicate Thugs with Twin Laser Turrets.





 Pressing the primary weapon button for Vader shows now 3 values on the Thugs:
  • The to-hit percentage, corresponding to the probability to hit the target. Vader has 56% of chance to hit the first Thug, 41% to hit the second one
  • The average hit results: at the end of the combat, once all red and green dice have been compared, the attacked unit is dealt the hits and criticals that have not been cancelled. The mean value for each is shown here. The first thug takes in average 0.52 hits
  • The average crit result: Same as before for uncancelled crits. The first thug takes 0.19 crit in average.
What happens if the shuttle fires at the same turn ? The results shown for the first thug correspond to the updated values if BOTH Vader and the shuttle fire at it in the same turn: They have 88% of chance to hit it, with an average 1.36 hit result, 0.52 critical.
How is it computed ? The average results for hits and crits for Vader and the shuttle are simply added. For the to-hit probability, the probability to not hit is computed for Vader and the shuttle, they are multiplied and the final result is 1 - this probability to not hit, neither with Vader nor with the shuttle.



Now a more complex case.When the first Thug fires with the TLT, we can see he has 92% of touching the shuttle, taking into account both attacks. They perform in average 1.48 hits, and 0 crits (it's a TLT). For Soontir, the chance is only 43% to hit.

When both Thugs are firing at the same target, the shuttle seems an easy target with an average 2.92 hit taken by the shuttle.

The results are computed for the shuttle and Vader as if 4 different units were attacking them. The effect of Autothrusters needs more explanations. For each combat, the complete distribution of results is computed, associating for each combination of modified dice (red and green) the probability to see it: for instance, the probability to have 1 focus, 1 crit and 1 hit for the Thug, 1 evade, 1 focus and 2 blanks for Soontir is computed. The Autothrusters modify Soontir results into 2 evades, 1 focus and 1 blank and the probability is added to the probability to obtain this result. The average of hits and crits, the sum of probability for hit results are computed and displayed.

If Vader and Soontir have a focus token, we can see that the % to hit decreases, but not that much because if it is used in the first attack, it is no longer available for the second one.
Here the results for Vader and Soontir are only approximations: the values shown correspond to the case where the focus is always used for the first attack, and never available for the second one. The successive attacks are no longer independent, and this would require too much processing power for javascript, at least with a brute force method computing the whole distribution. So the real figures are actually lower than these ones. 

A last example, with Contracted Scouts, in order to evaluate the impact of Guidance Chips and of the Punishing One title. The topmost scout has only  Plasma Torpedoes+Deadeye, the second one has additionally Guidance Chips and the third one has Plasma, Deadeye, Guidance Chips and is the Punishing One (3 for primary weapon).
 The first ship  has 61% of chance of hitting the first IG-88 (both with Autothrusters) and only 48% of chance for the second one, at range 3 (Autothrusters effect).
 The Guidance Chips adds +24% of chance to hit the first IG-88, +30% to hit the second one. Not bad for a 0 point upgrade !

Finally, with the Punishing One title, the % to hit are the same, but the average number of criticals has significantly raised, from 0.45 to 1.18 for the first ship, 0.43 to 1.04 for the second one.







A real punishing attack, with all three Scouts, with focus and target lock (for firing the torpedo) for each, would deal 4.71 hits + 2.29 crit in average to the first IG-88, with their Plasma Torpedoes. More than 7 damages in average, a possible killing blow.
This is still a first draft for this probability evaluation and it may require some processing power. The web page may not be responsive while this is computing. This evaluation is part of the effort to improve the AI to better determine the threats and the force of its attacks.

The upgrades taken into account so far in the computations are the following.
  • Twin Laser Turret, TIE/D, Cluster Missiles, BTL-A4, Gunner, Luke Skywalker (crew), IG-88B for multiple attacks
  • Heavy Laser Cannon, Accuracy Corrector, Guidance Chips, Ion Cannon, Ion Cannon Turret, Ion Pulse Missile, Tractor Beam, Flechette Cannon, Adv.Homing Missiles, XX-23 S (modifying red dice or result)
  • Autothrusters (modifying defense dice)
All other upgrades/pilots that are not listed are not taken into account for the probability evaluation (Howlrunner for instance). The results are accurately computed for the listed effects. Tokens (evade, focus, target lock) are also taken into account, but an approximation is made when there are multiple attacks, since the tokens are assumed to be consumed after the first attack.

Enjoy !

Wednesday, April 27, 2016

One year after

I started developing Squadron Benchmark one year ago. So, between bug corrections, I'll take the time to discuss what I've learned and what to expect for the following year.

Evolution of the code

The code is still buggy, but nothing compared to the first 0.5 version online one year ago :-) 
I wish to thank all  of you who report bugs, provide encouragements and donate for Squadron Benchmark. The code would not be in its current state without you ! Testing this kind of webapp automatically is nightmarish, and developing with no test goes nowhere, so actually when you report bugs, you contribute to half the development, really.

The app, in term of code, uses javascript, HTML5, CSS3 and SVG. SVG+javascript is rather convenient for displaying moving units, computing intersections and distances, the display of the game area is rather stable. CSS3 is powerful enough for some fun 3D effects (maybe too many in squad creation...).

Now for javascript development. After one year of development, the code has 15000 lines of javascript, with 7800 lines just to describe the specificities of 180 pilots and 190 upgrades. The rest is the game engine. Roughly speaking, each pilot and upgrade requires, on average, 15 lines of code to describe its special effects in term of game mechanics. During this past year, I counted ~100 new cards published by FFG, including pilots and upgrades. If FFG publishes the same number of new units the year to come, this means 1500 new lines of code, assuming there is no new game mechanics. That should be sustainable !

 The game engine by itself still need some improvement, some rules are not fully implemented, the X-Wing rule FAQ does not yet apply completely. This is one of the main goals of this second year of development.

Artificial intelligence

The AI is very simple. There are 340 lines of code dedicated to the AI, so no miracle ! This was not on top of my priorities, bug correction first, but critical bugs tend to be solved, so it's time for AI. One possibility is to let all players customize the AI of the squads. There is still some effort here before it can be customized, and I need to implement higher level functions.
This is one of the main objectives of the forthcoming developments.

All the successfully completed combats are automatically registered in Google spreadsheets. You can replay any of them through battle log (the black book icon).  There are actually 7 spreadsheets with 2000 combats each, so ~14000 combats are available on line. I think it's an unused feature still, probably because you have to select or create a squad before checking its battle log. It's not possible so far to directly request the database for squads.  I'm open to any suggestion anyway on how to use this, that's the only way to share information between players so far.
I use this database to compute some stats however, such as the "quality" of the AI. For instance, the average score, computed every 200 combats between player/AI, is shown in the following figure.
So one vertex corresponds to 200 combats, and the y-axis shows the % of total points won by the AI. The x-axis corresponds to time (from Oct. to Apr.)
Here the AI makes in average 25% of the score. So for a 200 point combat, the average score would be 50 for the AI, 150 for the human player. This is an average, most of the time, the AI as a null score but from time to time, it manages to win.

Multiplayer game

Squadron benchmark includes most of the rules, including rules of the upgrades/pilots. As this is only a one player simulator, it's a complementary tool for the real table top game, for training and testing. As it was said in other places, it has not the look and feel of a miniature game of course, and playing for real against a real human is way better. Making the app for two player games, it could be seen as a computer alternative to the real game. I'm not going to do it without the explicit agreement of FFG.

The Dark Side of Squadron Benchmark

The source code of Squadron Benchmark is available on line, on github. However, it's developed using vanilla javascript and css, there is no developer documentation, no comment, no test. As my time dedicated to this is limited, I prefer to code rather than document or coordinate the dev. I do it for the fun, for the challenges, and for trying new ideas and new techs, I don't care about a clean project management. Don't expect too much in this direction therefore ! :-)

I'll document this anyway, at some point. As I'm not especially competent for the development of AIs, this is a good way to contribute if you wish :-) (well, as soon as a minimum set of functionalities for the AI is ready to be used anyway). 
In particular, if by chance someone is motivated by deep learning and willing to adapt/use ConvNetJS for Squadron Benchmark, I'll gladly help ! I don't know if the AI can learn by itself how to play and find interesting strategies, or even if ConvNetJS can scale to the complexity of X-Wing miniature game rules, but it's worth a try and should be fun !


Cheers !

Wednesday, April 6, 2016

Better display (part 2)

Here is the second part concerning information display, mostly thanks to your comments !

  • When creating squads, the information on each squad has been reorganized: all stats are more clearly displayed on the left, on the right you can destroy the unit (cross), duplicate it (when non unique) or see its dial (arrow). When you add an upgrade, you can see now a longer list of items, corresponding to the upgrades. Finally, the points shown near the pilot name include the cost of all the upgrades given to the ship. 

  • Asteroids: when you have created or selected a squad, you can associate to it 3 asteroids. Just click on the "Asteroid" button and the following sub-window will open. Select 3 asteroids. The next time you select the same squad, it will come with the same asteroids (only works with squads that are not among the Top 10 or Prebuilt). You can change multiple times of course. Coming soon: debris cloud...

  • Damage deck: In the settings, choose the damage deck you wish to use. The new criticals are implemented, feel free to experiment ! You can now loose a stabilizer, have a major explosion, a major hull breach, all weapons failure or the pilot may be shaken.
  • Bigger buttons in the "Manage squad" table.
  • R4 Agromech action now triggers during combat, and you can choose first to add a target lock or not (red target lock), and then to consume this target lock, in the same attack. 
  • A better way to select your background for the combat. This has no impact on the combat, it's just for having a change from the black background ! The two special maps, including the one with  the DeathStar trench, have been removed (temporarily). BTW, who has tried them ?? Do you want maps for scenarios, for testing a squad agility, training your skill in maneuvering or just the plain maps ? Please, give your opinion in the comments below.

  • Better compression for background images, reduced size for icons, removal of unnecessary displayed areas, loading of the only sound effects concerning the squads that are in combat. All this should speed up the loading time (hopefully). 
  • Finally, when you play the combat, the maneuvers of the AI are not revealed before their turn. This way, you cannot adapt your move or maneuver, before the enemy move occurs.
In addition to these modifications, the Top 10 list has been updated (manually) according to the Miniranker web site, and the battlelog has been updated to include the most recent battles. The battles are stored by pages of 2000 battle records, and now there are 4000+ battles available through battle logs ! 

Monday, March 28, 2016

Better display, all Wave 8 units in v0.8.4

Ruthless Freelancer
I just received the Ghost, Punisher and TIE Adv. Prototype boxes (in French) ! 
So this 0.8.4 update is essentially for improving display, adding a few units that were missing. 

I added the French translations for all these cards, and a few units/cards I missed: Baron of the Empire, Lothal Rebel, Ruthless Freelancer and Gand Findsman. I added their corresponding images, for use in the squad builder.  Electronic Baffle and Overclocked R4 are also added, not yet implemented.The squad builder has been slightly changed, to better fit the window.

In the previous versions, it was easy to miss an effect requiring the selection of a unit. The units were only highlighted in gray, and if you pressed the  "next phase", the game was probably stuck. Now, they are flashing ominously, this should help.
The mines dropped have now a different animation, with a line turning around the mine.
Tokens, hull and shield points  received and lost by pilots are shown on screen, as animation. I think this significantly improves the understanding of what happens during the game. 

In the navigation bar, a gear icon opens a setting window, where you can choose the volume for all game effects, you can show/hide  the console and show/hide movement traces. All units leave a trace of their faction color, actions such as barrel roll and boost leave dotted lines.

A few bug corrections for this update: 2 criticals were causing stalls, deploying units was stalling, mines were not functioning properly. This is better now.  Tel Trevura has been corrected.

The import button no longer exist. You just have to type or paste a list into one of the textarea for squads #1 and #2 to import the list. XWS3.0 imports are now possible again, just paste your squad list in this format and it will appear automagically as a plain list, and be integrated in your squad lists.

Wednesday, March 9, 2016

Translation Corner

So far, Squadron Benchmark is only in French and in (nearly correct) English. If you want to translate the whole interface into another language, you are most welcome !

To keep this simple, you just have to download this JSON file that contains all translations from English to French:
https://gist.github.com/anonymous/35ac8ed57cd1b98671ba
and then clone it, or download it and modify it, and send it back to me. You can edit with a text editor, this is a simple text file essentially.

The format is the following, you have several records:  ships, pilots, upgrades, criticals, css, ui.
Each corresponds to a table of translations.
  • For ships, css, ui, simply rewrite the French version into your preferred language. 
  • For pilots and upgrades, each entry looks like this (for Proton Torpedoes):
     "Proton Torpedoes": {
            "name": "Torpilles à protons",
            "text": "<strong>Attaque (acquisition de cible) :</strong> utilisez votre acquisition de cible et défaussez cette carte pour effectuer cette attaque. Vous pouvez échanger 1 de vos résultats %FOCUS% contre 1 résultat %CRIT%."
    },
    with two entries: name and text, that can be optional. Name is the translation of the name of the card and text is the translation of the card description. In the translated text, you can use HTML (fewer is better) and special words like %CRIT% and %FOCUS% as in the above example. They will be replaced by special symbols (for a critical and a hit). Don't put text for "Limited", "Rebels only" or this kind of restriction, since it is taken into account by the squad builder. The list of special symbols is (left moves are not shown):
    %ACTION%,%ASTROMECH%,%BANKRIGHT%,%BOMB%,%BOOST%, %CANNON%,
    %CREW%,%CRIT%,%ELITE%,%EVADE%,%FOCUS%,%HIT%,%ILLICIT%, %MISSILE%,%ROLL%,%STOP%,%STRAIGHT%,%SYSTEM%, %TALONRIGHT%,%TARGET%,%TEAM%,%TORPEDO%,%TURNRIGHT%, %TURRET%,%UTURN%
For some pilots, there is no entry at all (no translation available yet in French). Feel free to fill it if you know the translation.

Cheers  !

Sunday, February 28, 2016

JumpMaster5000 pilots



Version v0.8.2 has a number of new features and corrections.







 

 

 

New ships and upgrades

Pilots implemented: Zuckuss, Maranno, Contracted Scout, Tel Trevura, Dengar
Hera with a docked shuttle 
Upgrades implemented: 'Zeb' Orrelios, 4-LOM, Agent Kallus, Guidance Chips, Hound's Tooth, Juke, Kanan Jarrus, R4-B11, R7 Astromech, Sabine Wren, Tactical Jammer, Targeting Astromech, Targeting Coordinator, TIE/D, TIE/x7, Weapons Engineer, Punishing one, Attani Mindlink, Rage, 'Gonk', Ghost, Phantom, Tractor Beam.

For Hound's Tooth, a Nashtah Pup is added to the squad list automatically. It is docked on the YV-666 and will be active once deployed. For Ghost, Phantom is not automatically added. You have to create a list with both Ghost and an attack shuttle. The Phantom title is not added automatically. 
For the tractor beam, the token is shown as a red V in the status of the unit.

Battle Log

The list of the different combat is available now for each unit, in the main window. Just select the book icon to view all combats that have involved the squad. For each combat, the first number of the score corresponds to the score of the squad, while the second value is the opponent score. 
The score is in bold font if the squad was played by a human, in normal font if played by the AI. 

** The battle log is working again ! The previous battles, and the previous links are not longer working however ! Sorry for the inconvenience !
Everything is not completely lost however, at some point, I can try to correct the previous links so that they work again, at least in the battle log.
Let's see first if there are other bugs appearing...
For those interested, the log of all battles can be found on google drive:
The spreadsheet changes every 2000 entries. 

Modification of interface

In the main window, Squad #1 and #2 indications have been replaced by 1 and 2 in colored circles. 

New interface for managing squad lists
In the combat, there is a new subphase during combat:
  • When attack dice are rolled, the defender can first apply effects (such as Elusiveness), and then the attacker applies modifiers
  • When the green dice are rolled, the attacker can first apply modifications (such as R4-B11) and then the defender applies modifiers.
When there is no modifier, the subphase is silently skipped. 

In the  squad builder, it is now possible to clone a non-unique unit. All non-unique upgrades are also copied. 

All fonts have been modified, to provide a more controlled layout. The interface is a bit more responsive than before. 

Several new maps are available, corresponding to different background images

There are also several bug corrections, thanks to your reports, and thanks for the contributors ! Any feedback welcome, bug reports, suggestions !

Sunday, January 31, 2016

Battle log: Watch all other combats, show your tactics or learn from others !


You have access to all previous finished combats in the "Battle log". Watch other tactics, evaluate the strength of a squad/unit in combat, replay a particular combat if you think you can obtain a better score, or learn from others !

The Battle log can be consulted from the main screen. First select the pilots you want to see in combat, press "View" in the bottom table, and then pick one of the combat involving these pilots in the top table, with different upgrades and setups. For each combat registered, the number of views is displayed, the score and who played each side (Human or computer).

You can also try to obtain a better score if possible. or change sides. For this, view the battle full screen and then, press the "Replay" button, behind the score.

The Battle log is still in alpha stage, there are probably many bugs.
The log only displays the last 100 battles, for now.