Skip to content

Commit

Permalink
Add normally distributed values
Browse files Browse the repository at this point in the history
  • Loading branch information
Nojipiz committed Sep 17, 2022
1 parent f5303c6 commit 5a680c1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package simulator

import domain._
import simulator.Verificators.checkifSomeoneStillResistance
import utils._
import scala.util.Random.apply
import scala.util.Random

Expand Down Expand Up @@ -41,8 +41,8 @@ def simulateRounds(competitors:List[Competitor], historyRounds:List[Round]):List
simulateCompetitorRound(competitor)
)
val currentRound = Round(shoots)
val updatedHistory = historyRounds :+ currentRound
return simulateRounds(competitors, updatedHistory)
val updatedHistory:List[Round] = historyRounds :+ currentRound
return simulateRounds(competitors.getTired(), updatedHistory)
}
return historyRounds
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ package simulator

import scala.util.Random.apply
import scala.util.Random

import domain._
import breeze.stats.distributions.Gaussian
import breeze.stats.distributions.Rand.VariableSeed.randBasis

object PseudoRandomState {

val gaussianDist = Gaussian(mu = COMPETITOR_RESISTANCE_MEAN, sigma = COMPETITOR_RESISTANCE_DESV)
val randomGenerator:Random = Random()

def getBoolean():Boolean =
randomGenerator.nextBoolean()

def getResistance():Int =
COMPETITOR_RESISTANCE + (if (getBoolean()) COMPETITOR_RESISTANCE_VARIABLE else -COMPETITOR_RESISTANCE_VARIABLE)
def getResistance():Int = gaussianDist.get().toInt

def getLuck(): Float =
COMPETITOR_MIN_LUCK +(COMPETITOR_MAX_LUCK - COMPETITOR_MIN_LUCK) * randomGenerator.nextFloat()
COMPETITOR_MIN_LUCK + (COMPETITOR_MAX_LUCK - COMPETITOR_MIN_LUCK) * randomGenerator.nextFloat()

def getGender(): Gender =
return if (getBoolean()) Gender.Male else Gender.Female

def getTiredness(): Int =
return if (getBoolean()) 1 else 2
}
25 changes: 18 additions & 7 deletions montecarlo_archery/src/main/scala/simulator/Verificators.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package simulator

import domain._
import simulator.PseudoRandomState

object Verificators{
extension(comp:List[Competitor]){
def checkifSomeoneStillResistance(): Boolean =
comp.find(competitor =>
competitor.resistance >= SHOOT_RESISTANCE_COST
).isDefined

def getTired(): List[Competitor] = comp.map(competitor =>
Competitor(
team = competitor.team,
name = competitor.name,
resistance = competitor.resistance - PseudoRandomState.getTiredness(),
experience = competitor.experience,
luck = PseudoRandomState.getLuck(),
gender = competitor.gender,
score = competitor.score
)
)

extension(comp:List[Competitor]){
def checkifSomeoneStillResistance(): Boolean =
comp.find(competitor =>
competitor.resistance >= SHOOT_RESISTANCE_COST
).isDefined
}
}
9 changes: 9 additions & 0 deletions montecarlo_archery/src/main/scala/utils/Converter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package utils

import domain._

extension (round:Round){
def getCompetitors(): List[Competitor] = round.playersRounds.map( round=>
round.initialState
)
}

0 comments on commit 5a680c1

Please sign in to comment.