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
        }
    }
}

tornadofx控制台输出“三门问题”,蒙特卡洛算法-LMLPHP tornadofx控制台输出“三门问题”,蒙特卡洛算法-LMLPHPtornadofx控制台输出“三门问题”,蒙特卡洛算法-LMLPHPtornadofx控制台输出“三门问题”,蒙特卡洛算法-LMLPHP

07-16 22:42