0

Suppose we have a class called "Archer"

class Archer {
   var Name : String
   var Spirit : Double
   init(Name : String, Spirit: Double){
      self.Name = Name
      self.Spirit = Spirit
   }

}

And we will make two archers

var Hawkeye = Archer(Name : "Hawkeye", Spirit : 70.00)
var Legolas = Archer(Name : "Logolas", Spirit : 50.00)

We let them duel, and the rule is:

The bigger someones Spirit the more probability he will attack at first in every turn until someone die.

The question is: how to make an algorithm to make a fair fight according to their Spirit?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Angger
  • 755
  • 6
  • 14
  • 31
  • 1
    Please define specifically what you mean be "best" and "fair" – Feldur Jul 26 '16 at 05:19
  • Is this what you are looking for: [Generate random numbers with a given distribution](http://stackoverflow.com/questions/30309556/generate-random-numbers-with-a-given-distribution) ? – Martin R Jul 26 '16 at 05:34

1 Answers1

2

Generate a random number between 1 and the total SPIRIT in the fight (70 + 50 = 120 in your example). If the random number is less than or equal to the spirit of player one then player one attacks first, otherwise player 2 attacks first.

Westside
  • 675
  • 1
  • 7
  • 16