Two-player battle simulator stands for second player

I am writing a fairly simple (for now) crispy combat simulator in javascript. His goal is to check the formula for the upcoming game, so that we can balance the statistics of the players.

The simulator is currently reducing player health based on the following formula

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

HP starts at 100, and str is 2.

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

The code above selects 1 of the 3 "parts" of the player (head, body, legs), since each part has its own statistics.

So, for any particular turn, starting with player 1, their HP head decreases by a value based on the first formula (the random part of player 2 is selected, str str is multiplied by a random number from 1 to 5)

Then the player attacks 2 parts, and the random part of player 1 is selected for str stat.

(Yes, player 2 always attacks first at present, then player 1 - can this be a problem?)

When I launch one โ€œbattleโ€, the results are rather mixed. But when I start 100 or 1000 battles, player 2 usually comes out on top, with an average winning rate of 60%.

JS file here (download and run via Node)

+4
source share
3 answers

, , , 1-, , , 100 .. 1 = 10 , , , 10- , 2 9 . - , 1- 1

+1

, . , . - , . - , . ( ) : .

+1

An interesting solution to this may be to add something like the variable โ€œrageโ€ - basically, as lower, health becomes stronger than it fights and tries to balance it with a different scaling.

-1
source

Source: https://habr.com/ru/post/1677834/


All Articles