feat: ajout d'un simulateur
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b1b481536e
commit
7deebcf64c
1 changed files with 80 additions and 0 deletions
80
simulateurs/main.lua
Normal file
80
simulateurs/main.lua
Normal file
|
@ -0,0 +1,80 @@
|
|||
|
||||
|
||||
local function getDiceResult(stat, dice)
|
||||
local estCritique = false
|
||||
local isReussite = (dice <= stat)
|
||||
local niveauReussite = math.floor(stat / 10 ) - math.floor( dice / 10)
|
||||
if (dice <= 5) then
|
||||
isReussite = true
|
||||
estCritique = true
|
||||
niveauReussite = niveauReussite * 2
|
||||
if (niveauReussite < 0) then
|
||||
niveauReussite = niveauReussite * -1
|
||||
end
|
||||
end
|
||||
if (dice > 95) then
|
||||
isReussite = false
|
||||
estCritique = true
|
||||
niveauReussite = niveauReussite * 2
|
||||
if (niveauReussite > 0) then
|
||||
niveauReussite = niveauReussite * -1
|
||||
end
|
||||
end
|
||||
local unite = dice % 10
|
||||
return isReussite, niveauReussite, unite
|
||||
end
|
||||
|
||||
local function confrontation(stat1, stat2)
|
||||
local resultats = {}
|
||||
local egalites = 0
|
||||
|
||||
for i = 1, 100 do
|
||||
local isReussite1, niveauReussite1, unite1 = getDiceResult(stat1, i)
|
||||
|
||||
for j = 1, 100 do
|
||||
local resultat = {}
|
||||
resultat.reussite = false
|
||||
|
||||
local isReussite2, niveauReussite2, unite2 = getDiceResult(stat2, j)
|
||||
|
||||
if (niveauReussite1 == niveauReussite2 and unite1 == unite2) then
|
||||
egalites = egalites + 1
|
||||
else
|
||||
if (niveauReussite1 > niveauReussite2) then
|
||||
resultat.reussite = true
|
||||
elseif (niveauReussite1 < niveauReussite2) then
|
||||
resultat.reussite = false
|
||||
elseif (unite1 <= unite2) then
|
||||
resultat.reussite = true
|
||||
end
|
||||
resultat.delta = niveauReussite1 - niveauReussite2
|
||||
table.insert(resultats, resultat)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local total = 0
|
||||
local totalSansNegatif = 0
|
||||
local nombreReussite = 0
|
||||
|
||||
for _, resultat in ipairs(resultats) do
|
||||
if (resultat.reussite) then
|
||||
nombreReussite = nombreReussite + 1
|
||||
end
|
||||
total = total + resultat.delta
|
||||
totalSansNegatif = totalSansNegatif + math.max(0, resultat.delta)
|
||||
end
|
||||
|
||||
local stringPourcentageReussite = string.format( "%.2f%%", (nombreReussite / #resultats) * 100 )
|
||||
local stringMoyenne = string.format( "%.2f", (total / #resultats) )
|
||||
local stringMoyenneSansNegatif = string.format( "%.2f", (totalSansNegatif / #resultats) )
|
||||
local stringEgalites = string.format( "%.2f%%", (egalites / 10000) * 100 )
|
||||
|
||||
return stringPourcentageReussite, stringMoyenne, stringMoyenneSansNegatif, stringEgalites
|
||||
end
|
||||
|
||||
|
||||
local stringPourcentageReussite, stringMoyenne, stringMoyenneSansNegatif, stringEgalites = confrontation(tonumber(arg[1]), tonumber(arg[2]))
|
||||
print(stringPourcentageReussite, stringMoyenne, stringMoyenneSansNegatif)
|
||||
print("Egalités :", stringEgalites)
|
Loading…
Reference in a new issue