Tuesday 15 January 2013

java - "The three shooters algorithm" -


Like the title, you get 3 'shooters': Shooter A , B and C
Rules are as follows:

There is a different chance to hit each one:
shooter A of the time 100%
Shooter B will hit the bar for 80% and shooter C < / Strong> will be killed for the 50% of the bar

after each shooter once hit will actually die and remove Or.

Shooter with the most chance of hitting each shooter will give priority to survival if all the shooters are alive: C Shoot A , B < Shoots A , A B

Each shooter can shoot only one round when its turn

Each new game that starts, it will be a random start of three shooters.

Once a shooter played his turn (and if the shooter is not only standing one left), the next shooter will be randomly selected to play and the person who has played his turn can not be raised again (whose Meaning that the shooter who has played now can not play it twice, but after the next turn, he can play again).

A game can only end after being a winner in the form of a final shooter standings
_________________________________________________________________________

Now, I was later assigned to find the average victory ratio for each shooter. Let's say 2,000,000 games.
My results were as follows:
A: 0.2344525 (23.4%), B: 0.3187745 (31.8%), C: 0.446773 (44.6%).
We did not get any formal answer in our class and just got a different answer about the person I checked.

To solve this scenario my code is correct as the correct answer?

  public still character shooters () {char winner = 'x'; // 'x' means that no winner is still four A = 'V', B = 'V', C = 'V'; // 'V' means they are alive dual turn = monastery Random () * 3; Shoot; / * Turn: 0 to 1 will always mean that it is a turn 1 to 2 will always mean that it is the turn of B 2 to 3 will always mean that it is the turn of the moment * / while (winner == ' X ') {// When the winner ends,' a ',' b 'or' c 'will be changed (current & lt; 1) {// start (1.0) b =' x '; // b 'is dead turn = 2.5; // C's turn now} and if (turn and lieutenant; 2) {// B start (0.8) shoot = mathematics.Random (); If (shoot and lt; = 0.8) {// b hit (a == 'v' & amp; amp; c == 'v') {// live both opponents, one = 'x'; // one is dead 'turn = 2.5; // C's turn now} and {winner = 'B'; // Whatever is the case, the last contestant will be left out}} Other {// B if (a == 'V' and amp; C == 'V') misses {Bari = Math Random () * 2; If (turn & gt; = 1) {// since we can not play the next rotation instead: turn ++; Instead of representing the // b, adjust to represent the turn of C.}} and {turn = 2.5; // C is a dead, because one is dead}}} and {// start (0.5) shot = mathematics. RANDOM (); If (shoot and lt; = 0.5) {// C hit if (a == 'V' and B == 'V') {// survive both opponents, down to an = 'x'; // one is dead 'turn = 1.5; // B. Now turn. } And (winner = 'c'; // whatever is the case, the last contestant will be left left}} and {// C if (a == 'V' and B == 'V') Mimes {Bari = Mutt.Random} * 2;} And if (a == 'v') is the dead who dies since the turn of Winner = 'A'; // A is dead; And {turn of turn = 1.5; // b, since one is dead}}}} return winner;}  


No comments:

Post a Comment