{ "cells": [ { "cell_type": "markdown", "source": [ "# The Bridge Game\n", "\n", "The glass bridge is a game in the [Netflix](https://netflix.com/) series [The Squid Game](https://www.imdb.com/title/tt10919420/). The series is Netflix's most-watched series to date, becoming the top-viewed program in 94 countries and attracting more than 142 million member households during its first four weeks from launch. (Source [Wikipedia](https://en.wikipedia.org/wiki/Squid_Game))\n", "\n", "**Spoiler Alert** Don't read the article if you intend to watch the series!\n", "\n", "![Squid Game Copyright Netflix 2021](squid_game_poster.png){: .center}\n", "\n", "
\n", "Squid Game - © Netflix 2021\n", "
\n", "\n", "\n", "In one scene in Episode 7, 16 players have to cross a bridge made of two rows of glass tiles. The bridge is 18 steps long. They have to jump to one tile per row, but just one tile will last whereas the other one is made of tempered glass, which breaks under impact. The players start in an ordered fashion, whereby players with higher numbers will avoid broken tiles. To penalize players with higher numbers, there is a time-limit after which players who have not passed the bridge have lost as well (and pay with their lives).\n", "\n", "**Disclaimer** The author considers the game purely from a scientific/fictional perspective. The game as well as the concept of the series are immoral, wrong, and detestable.\n", "\n", "![Squid Game Copyright Netflix 2021](squid_game_bridge_scene.png){: .center}\n", "\n", "\n", "Squid Game - © Netflix 2021\n", "
\n", "\n", "\n", "Inspired by another [simulation](https://www.jhelvy.com/posts/2021-10-19-monte-carlo-bridge-game/) this example illustrates how to run simulations in different configurations many times to work out process parameters. Here, the key parameter of interest is the **number of surviving players**.\n", "\n", "As players in the show can pick their start number, the episode - as well as the internet community - circles around the question regarding an optimal start number to _optimize the chance of survival_.\n", "\n", "## Model\n", "\n", "To answer this question, we will model and analyze the process with `kalasim`. At its heart - which is its [process definition](../component.md#process-definition) - it is a very simplistic model that centers around simulating the participant's stepping on the tiles one after another while considering the _learning experience_ of earlier participants with lower start numbers.\n" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "code", "execution_count": 43, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//@file:Repository(\"*mavenLocal\")\n", "//@file:DependsOn(\"com.github.holgerbrandl:kalasim:0.7-SNAPSHOT\")\n", "\n", "@file:DependsOn(\"com.github.holgerbrandl:kalasim:0.6.92\")\n", "@file:DependsOn(\"com.github.holgerbrandl:kravis:0.8.1\")" ] }, { "cell_type": "code", "execution_count": 44, "outputs": [], "source": [ "import org.kalasim.*\n", "\n", "import kravis.geomBar\n", "import kravis.geomCol\n", "import kravis.plot\n", "import org.apache.commons.math3.distribution.LogNormalDistribution\n", "\n", "import java.lang.Double.min\n", "import kotlin.random.Random" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "code", "execution_count": 45, "outputs": [], "source": [ "//LogNormalDistribution(3.5, 0.88).let{ dist ->\n", "// repeat(100){ println(dist.sample())}\n", "//}\n", "\n", "//TODO set random seed, blocked by https://github.com/Kotlin/kotlin-jupyter/issues/345\n" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "code", "execution_count": 86, "outputs": [], "source": [ "class SquidGame(\n", " val numSteps: Int = 18,\n", " val numPlayers: Int = 16,\n", " val maxDuration: Int = 12 * 60\n", ") : Environment(randomSeed =Random.nextInt()) {\n", "\n", " // randomization\n", " val stepTime = LogNormalDistribution(rg, 3.0, 0.88)\n", "// val stepTime = uniform(10,30)\n", "\n", " val decision = enumerated(true, false)\n", "\n", " // state\n", " var stepsLeft = numSteps\n", " var survivors= mutableListOf