Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var gameWon = 0
- var gamePlayed = 0
- fun tirage(changerDePorte: Boolean) {
- gamePlayed++
- val car = portes.random()
- val choice = portes.random()
- if (!changerDePorte) {
- if (car == choice) {
- println("T'as choisi la bonne porte du premier coup. Bravo !")
- gameWon++
- } else {
- println("Oh non t'es nul, t'aurais du changer d'avis :(")
- }
- } else {
- val porteOuverte = openDoor(car, choice)
- val newChoice = portes.toMutableSet().apply {
- remove(choice)
- remove(porteOuverte)
- }
- assert(newChoice.size == 1)
- if (newChoice.first() == car) {
- gameWon++
- println("T'as choisi la mauvaise porte, mais tu t'es ravisé.. Bravo !")
- } else {
- println("Oh non t'es nul, t'aurais pas du changer d'avis :(")
- }
- }
- }
- fun main(args: Array<String>) {
- println("Voulez vous changer tout le temps de porte (0) ou tout le temps garder la même (1) ?")
- val choix = readLine()!!.toInt()
- println("\nCombien de tirages ?")
- val nombreTirage = readLine()!!.toInt()
- for(i in 0 until nombreTirage) {
- tirage(choix == 0)
- }
- println("\nNombre de parties jouées $gamePlayed\n Nombre de parties gagnées : $gameWon\nRatio : ${gameWon.toFloat()/ gamePlayed.toFloat()}")
- }
- fun openDoor(car: Int, choice: Int): Int {
- return portes.toMutableSet().apply {
- remove(car)
- remove(choice)
- }.random()
- }
- const val PORTE_1 = 0
- const val PORTE_2 = 1
- const val PORTE_3 = 2
- val portes = setOf(PORTE_1, PORTE_2, PORTE_3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement