Two player number battling simulator favours second player

Viewed 115

I am writing a fairly basic (for now) number crunching battle simulator in javascript. Its purpose is to test formula for a forthcoming game, so we can balance players stats.

Currently, the sim reduces a players health based on the following formula

player1.hp -= (Math.floor(Math.random() * 5) + 1) * player2[Math.floor(Math.random() * player2.length)].str;

HP starts on 100, and str is 2.

player2[Math.floor(Math.random() * player2.length)].str

The above code picks 1 of 3 "parts" of the player (head, body, legs) as each piece has its own stats.

So for any particular turn, starting with player 1, their head's HP is reduced by an amount based on the first formula (random part of player 2 picked, it's str stat is multiplied by a random number between 1 and 5)

Then player 2's parts are attacked, with a random part of player 1 being picked for the str stat.

(Yes, player 2 attacks first always currently, then player 1 - this may be the issue?)

When I run a single "battle", the results are fairly mixed. But when I run 100 or 1000 battles, player 2 typically comes out on top, with an average 60% win rate.

JS file here (download and run via Node)

2 Answers
Related