import tornadofx.*
fun main() {
val wins = intProperty()
val lose = intProperty()
val Msg = stringProperty()
// 1000万次
val n = 10000000
(1..n).forEach {
if (play(true))
wins.value++
if (play(false))
lose.value++
}
Msg.value = "总次数:${n} -换门赢得次数:${wins.value}- 赢得概率:${wins.value.toDouble() / n} "
println(Msg.value)
Msg.value = "总次数:${n} -不换门赢得次数:${lose.value}- 赢得概率:${lose.value.toDouble() / n} "
println(Msg.value)
}
fun play(changeDoor: Boolean): Boolean {
val prizeDoor = (0..2).random()
val playerChoice = (0..2).random()
if (prizeDoor.equals(playerChoice)){
if (changeDoor){
return false
}else{
return true
}
}else{
if (changeDoor){
return true
} else{
return false
}
}
}