<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jake Mitchell on Medium]]></title>
        <description><![CDATA[Stories by Jake Mitchell on Medium]]></description>
        <link>https://medium.com/@Jake_Mitchell?source=rss-3d9ea428abd9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*x2k8l3EXqkCZkBVOZ5Bv8Q@2x.jpeg</url>
            <title>Stories by Jake Mitchell on Medium</title>
            <link>https://medium.com/@Jake_Mitchell?source=rss-3d9ea428abd9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 21:01:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Jake_Mitchell/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Simulating the Card Game ‘War’]]></title>
            <link>https://medium.com/data-science/simulating-the-card-game-war-ebafb4462a6a?source=rss-3d9ea428abd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebafb4462a6a</guid>
            <category><![CDATA[cards]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[simulation]]></category>
            <dc:creator><![CDATA[Jake Mitchell]]></dc:creator>
            <pubDate>Tue, 24 Jan 2023 10:53:10 GMT</pubDate>
            <atom:updated>2023-01-24T10:53:10.091Z</atom:updated>
            <content:encoded><![CDATA[<h4>A coding story about a simple game with an infinite twist</h4><p>I’ve simulated a lot of games — games that require skill, deception, or strategy.</p><p><strong>This is not one of those games.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VqvYVDONZ5fX8K6G" /><figcaption>Photo by <a href="https://unsplash.com/@flowinteractive?utm_source=medium&amp;utm_medium=referral">Ivan Slade</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Introduction:</h4><p>‘War’ is very simple. 2 players are each dealt out half of a standard 52-card deck. The two then face off, flipping over their top card. Whoever has the highest card takes both cards. On the occasion that the cards have the same value, players risk the next 3 cards of their deck, and battle with the 4th card. Whoever plays the highest 4th card wins all of the cards in the pile (their own 3 cards plus the opponent’s 3 cards). The game ends when a player does not have any cards left.</p><p>There is no secret to winning. You just hope your card is valued higher than your opponent’s card.<strong> You are at the mercy of dumb luck.</strong></p><p>When I set out to code this game, I was interested if the starting value of cards could predict a winner before the game even started. What I was not expecting to find was that this game, under the right circumstances, can actually go on<em> forever</em>.</p><h4><strong>Coding the Game:</strong></h4><p>I first ‘shuffle’ a deck of cards:</p><pre>deal = randperm(52,52);<br>  for i = 1:13<br>    for j = 1:52<br>      if deal(j) &gt; (i - 1)*4 &amp;&amp; deal(j) &lt;= (i - 1)*4 + 4<br>        deal(j) = i;<br>      end<br>    end<br>  end</pre><p>This block of code creates a 52-space array of the numbers 1–52 randomly placed. Then, the loops go through and assign groups of 4 to the values of 1–13, with 1 being an ace and 13 being a king. What is left is the equivalent to a shuffled deck of cards.</p><p>I then decide if the next cards for each opponent are not equal to each other. If so, the code is very simple:</p><pre>if next_up(1,1) ~= next_up(1,2)<br>  [best,index] = max(next_up(1,:));<br>  player_cards(index,size(player_cards,2) + 1:size(player_cards,2) + 2) = next_up(1,:);<br>  player_cards(1,next_up(2,1)) = 0;<br>  player_cards(2,next_up(2,2)) = 0;<br>end</pre><p>This determines which card is higher, given that the cards are not equal, and gives both cards to the winner, while taking away that card from the loser.</p><p>If the played cards are the same, then the players must go to war. This code is identical to the previous shown, with the exception being that an additional 3 cards are added to the shared pile from each player.</p><p>These steps are repeated until a winner is decided… <em>or so I thought</em>.</p><h4>The Results:</h4><p>Results are hard to come by when a simulation won’t end. Then I took a look at the decks of each player.</p><p><strong>The players had worked their way into a perfectly balanced game of ‘War’.</strong></p><p>I then plotted the amount of cards in each hand at each turn in the game to visualize what had a happened:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*DPR9oMzOC7WBcsqGrvHmMQ.jpeg" /><figcaption>Image provided by the author.</figcaption></figure><p>This is a plot that shows the state of the game at each turn. It is perfectly mirrored at the 26-card line, due to the zero-sum nature of the game. What it shows in this infinite game (I stopped it at 2000 turns to produce this image) is that <strong>the players had accidentally found a pattern of cards that resulted in a perfect equilibrium of card flow.</strong></p><p>Every card that the red player took, blue would take back the turn after. Over and over again — forever. I zoomed in on the previous plot to illustrate this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*AEVAq-AnG21xOaqWTQJafg.jpeg" /><figcaption>Image provided by the author.</figcaption></figure><p>This wasn’t happening every game though. Plenty of games were playing out completely normal. I accumulated more of these plots to show the different card flows that ‘War’ can produce.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*l1WJWbBMs3mUlygb9XQ7gg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*n9IShgH1ocQlvqAPuiX8cg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*JZSAFYDiciqHFXPHBNBJ5Q.jpeg" /><figcaption>Images provided by the author.</figcaption></figure><p>It is fascinating to visualize what some of these games were like. On one end (left), you have a game that featured many different pivot points. Players went back and forth, exchanging the lead until one couldn’t compete any more. Then on the other end of the spectrum (right), you have a game that heavily favored a player right from the start. Blue was likely hanging on by a few high-value cards, but eventually ran out of luck.</p><p>I was still interested in finding what ratio of games take the leap to infinity. I simulated ‘War’ hundreds of times and tracked the amount of games that reached 2000 turns (this was my definition of infinity since I would not be able to finish the simulation if I actually left it running forever). <strong>I found that 16.67% of games resulted in an infinite game.</strong></p><p>I also found that <strong>the average non-infinite game lasts 513 turns.</strong> According to the histogram below, most games last under 500 moves. While this might seem like a lot, the average move lasts maybe 2–3 seconds, meaning that the average game is 15–20 minutes long.</p><p>When we consider that 16.67% of games go to an infinite amount of turns, <strong>we could theoretically say that the average turns per game… is infinity — </strong>but that idea hurts my brain a little bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*eVKLxVV6RlC6JhwlyO8LSw.jpeg" /><figcaption>Image provided by the author.</figcaption></figure><p>At this point, I was finding that maybe my understanding of the rules was causing this infinite game. I was coding the game so that when a player won, they returned those cards to the bottom of their hand — unshuffled.</p><p>I simulated the same code, with a shuffling block this time, and the results that were produced aligned more with my experience in playing the game.</p><p>I found that <strong>none of the simulated games went to infinity.</strong> I also found that <strong>the average turns per game shrunk to around 250 turns</strong> — half the amount of the non-shuffled version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*t1rzdnJ8vT6oOlFZe4-LBA.jpeg" /><figcaption>Image provided by the author.</figcaption></figure><p>The histogram speaks for itself. Far fewer games got anywhere close to being infinite, and many only lasted 5–10 minutes.</p><p>It makes total sense how simply shuffling the cards can produce enough variation to prevent the game from lasting forever. For the average player not interested in experimenting with the sturdiness of total card equilibrium, the tedious task of shuffling your winnings is all it will take to keep your game time to a reasonable length.</p><h4>Conclusions:</h4><p>The game of ‘War’, when played as the unshuffled version, has a decent chance at lasting forever. 1 of every 6 games was likely to be infinite. If your goal is to find perfect equilibrium amongst the cards, then I suggest playing this version.</p><p>It’s not often that I finish a project with results I was not somewhat expecting. In <a href="https://medium.com/codex/the-best-and-worst-catan-board-setups-989df4ba550a">Catan</a>, I generally knew what a good setup was, and I was just optimizing it. With <a href="https://medium.com/towards-data-science/a-data-driven-tactics-simulation-for-monopoly-864e7cffe508">Monopoly</a>, I went in expecting to find that properties with the best return-on-investment would be ideal. With this project, I went in blindly — and found that my simplest project yielded the most interesting results.</p><p>Thanks for taking the time to read my article! If you made it this far, why not read more about data science in board games? Take a look at some of my other projects:</p><ul><li><a href="https://medium.com/codex/simulating-the-card-game-bs-to-find-the-optimal-setup-82541bacf628">Simulating the Card Game ‘BS’</a></li><li><a href="https://medium.com/towards-data-science/simulating-mancala-what-happens-when-i-push-this-game-to-its-limits-28d9c0a58616">Simulating Mancala</a></li><li><a href="https://medium.com/towards-data-science/applying-machine-learning-to-tic-tac-toe-47d954671c73">Applying Machine Learning to Tic-Tac-Toe</a></li><li><a href="https://medium.com/towards-data-science/the-surprisingly-interesting-mathematics-within-chutes-and-ladders-40f931c18489">Chutes and Ladders</a></li><li><a href="https://medium.com/towards-data-science/i-taught-a-machine-how-to-play-connect-4-df261da4e23f">Teaching a Machine the Play Connect-4</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebafb4462a6a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/simulating-the-card-game-war-ebafb4462a6a">Simulating the Card Game ‘War’</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Data-Driven Tactics Simulation for Monopoly]]></title>
            <link>https://medium.com/data-science/a-data-driven-tactics-simulation-for-monopoly-864e7cffe508?source=rss-3d9ea428abd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/864e7cffe508</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[economics]]></category>
            <category><![CDATA[matlab]]></category>
            <category><![CDATA[board-games]]></category>
            <dc:creator><![CDATA[Jake Mitchell]]></dc:creator>
            <pubDate>Mon, 09 Jan 2023 16:28:08 GMT</pubDate>
            <atom:updated>2023-01-09T16:28:08.983Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Data-Driven Tactics Simulation of Monopoly</h3><h4>A visual guide on dominating your next Monopoly game using thousands of MATLAB simulations</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*58JL-fnIHJ0paSp3" /><figcaption>Photo by <a href="https://unsplash.com/@mrthetrain?utm_source=medium&amp;utm_medium=referral">Joshua Hoehne</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Introduction:</h4><p>In this sequel to a previous article of mine, <a href="https://medium.com/towards-data-science/simulating-monopoly-finding-the-best-properties-using-matlab-130fe557b1ae">Simulating Monopoly</a>, I will be looking into the buying strategies of players — and how those strategies affect game outcomes. I will be doing this by modeling the game in MATLAB, and then simulating thousands of games to find patterns within the player choices.</p><h4>Coding the Game:</h4><p>To model monopoly, you just need to simulate the rolling of dice and move players based on that roll value. Then apply a list of conditional statements based on what kind of tile they land on. If they land on a property, either decide to buy the property or pay rent to the owner. If they land on “Go to Jail”, change the location of the player to “Jail”. That aspect of the game is pretty straightforward in the code, and is outlined in more detail in my previous article linked above.</p><p>The code that is most exciting to me is the decision-making when it comes to buying property, buying houses/hotels, and trading. When a player is deciding to buy a property, two factors are taken into account:</p><ul><li><strong>The Price Ratio </strong>— the player’s money divided by the price of the property. The smaller the ratio, the bigger the impact on the player’s financial health.</li><li><strong>The Purchase Coefficient</strong> — a random value assigned at the start of the game. The lower the purchase coefficient, the more risky a player is with their buying habits.</li></ul><p>These two values are fed into the <strong>Decision Factor Formula</strong>. This formula is a modified sigmoid function that yields a result between 0 and 1. Results closer to 0 mean that the player would never buy this property in this situation, and results closer to 1 would be a great deal for the player. Then a random number generator produces a number between 0 and 1. If that number if less than the decision factor, the player buys the property (see code below).</p><pre>price_ratio = player_data(turn,1)/property_data(i,2); % calculates price ratio<br>decision_factor = 1/(1 + exp(-1 * price_ratio + player_data(turn,3))); % calculates decision factor<br>if change == 1 % if buying property would result in a monopoly<br>  player_data(turn,3) = player_data(turn,3) + mon_weight; % increases chance of getting property<br>end<br>if rand(1) &lt; decision_factor % if player decided to buy property<br>  property_data(i,11) = turn; % assignes property to new owner<br>  player_data(turn,1) = player_data(turn,1) - property_data(i,2); % subtracts price from owner&#39;s money<br>end</pre><p>These two values and associated function are used for all players at every decision point in the game. There is even an extra incentive added to properties that would create a monopoly for that player.</p><p>The game is simulated until all but 1 player is bankrupt, at which the game is over and the statistics are recorded. Then everything is reset, and a new game starts. Repeat 1,000 times.</p><h4>The Results:</h4><p>The following results and analysis were performed with the assumption that 6 people were playing the game.</p><p><em>Should you be more risky, or more conservative with your money?</em></p><p>The plot below shows how your buying strategy affects your average wealth over the course of a game. As you move from left to right along the x-axis, the buying strategy goes from risky to conservative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*XD8B1qd6jvoqrknYGXFVDA.jpeg" /><figcaption>Image provided by the author.</figcaption></figure><p>You could argue that there is a slight advantage towards being more risky based on the darker cluster of points in the bottom-left corner, but it’s not much. This plot unfortunately shows that <strong>there is no correlation between buying strategy and success rates</strong>, which was really disappointing to see. To prove it is not dependent on player amount, here are the same results with 4 players and 8 players:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*Ml7-cdAQQxsEuLV964NCEw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*MV8OcC9TKDKGXUHRMfeLzA.jpeg" /><figcaption>4 players (left) and 8 players (right). Images provided by the author.</figcaption></figure><p>Once again, there is a little evidence to show that being more risky can increase your average wealth based on these plots alone. Also, the accumulation of points near 0 is because in a game where almost everyone ends with 0$, you would expect the average to be skewed in that direction.</p><p><em>So there is no ideal buying strategy that I could use?</em></p><p>As it turns out, there is a buying strategy that could benefit a player, but it actually has to do more with how your opponents are playing.</p><p>The plot below is nearly identical to the previous plots, but now the x-axis is the <strong>Purchase Coefficient Ratio</strong>, or the ratio of your coefficient to the average of your opponents. Values lower than 1 mean you are being more risky than your opponents. Values higher than 1 mean you are being more conservative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*Sclbgu3W-oefiAvdryQpKA.jpeg" /><figcaption>Image provided by the author.</figcaption></figure><p>Based in this plot, we could say with more certainty that <strong>being more risky with your buying strategy — compared to your opponents — increases your expected average wealth. </strong>This is because there is a significant increase in points located higher up the y-axis between the x-axis values of 0.5 and 1.</p><p>We could also say that <strong>being more conservative — compared to your opponents — decreases you expected average wealth. </strong>The right side of the chart shows that players who were more conservative than their opponents almost had no cases of ending with a significant amount of money.</p><p><em>So if I should be more risky with my property buying compared to my opponents, which properties should I be focusing on?</em></p><p>Over the course of the 1,000 simulated games, I looked at which properties the eventual winners had at the point of their first opponent going bankrupt:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*8Dsv6wS3ntNzAflp-JWG5A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*TE0xw7y23nnHiln4eTId7w.jpeg" /><figcaption>Images provided by the author.</figcaption></figure><p>The x-axis is simply the tile location on the board. It’s like if you broke apart the 4 sides of the board and lined them up in a row. The colors match the properties on a standard monopoly board, with the exception of railroads being black points and utilities being gray points.</p><p>When looking at this plot, it is clear that <strong>the winning players targeted 3 specific groups of properties. They targeted the light blue, pink, and orange property groups </strong>(see red circles on board above).<strong> </strong>All of these properties had ownership rates well over 35%, and some came close to 45% in the case of the light blues.</p><p><em>Why do players who win often own these properties?</em></p><p>The ideal property to own is one that has an excellent return on investment. You do not want to own properties that will take an expected 80 turns for you to make your money back. The plot below describes it perfectly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*84eZ9IVyoEYPcPSyqdbAlA.jpeg" /><figcaption>Image provided by the author.</figcaption></figure><p>The rounds to breakeven is calculated using the average money spent on the property, including the initial purchase, and any subsequent housing added. This is divided by the average amount of rent earned per round to find the average rounds it takes to get your money back.</p><p>The properties that were most likely to be owned by winners are near the bottom, meaning that it takes less time to earn your money back, hence more time to make money from it. The plot below shows how these winner really valued properties with excellent return on investment rates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*VQ6gfZbQgGapMhzQYMP5eg.jpeg" /><figcaption>Image provided by the author.</figcaption></figure><p>The light blue, pink, and orange properties are clearly the best on the board. This is important because <strong>not only should you be more risky than your opponents, you should also focus that risk on these 3 property sets.</strong></p><p><em>What is a quantitative value that can be assigned to this level of risk?</em></p><p>I tracked the wealth of all 1,000 winners from the simulated games and then averaged the amount of money at each dice roll to produce this visual:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*8g9zcLYauBvOBhrwqvHVUw.jpeg" /><figcaption>Image provided by the author.</figcaption></figure><p>The average winner for a 6-player game <strong>spent money on properties until they reached between 750$ and 800$ left in their hand.</strong> This should be achieved over the course of roughly 60–70 dice rolls, or around 10 complete cycles amongst all the players.</p><p><strong>Once the average winner reached nearly 3 times the starting amount of money, they began reinvesting in properties</strong> that become available as players go bankrupt. They also start to focus on buying houses and hotels at this point.</p><h4><strong>Conclusions:</strong></h4><ol><li>It is not enough to just play in a risky manner, you should also try to be more risky than your opponents. At the very least, match your opponent’s playing style.</li><li>Your buying strategy should revolve around trying to acquire the light blue, pink, and orange properties.</li><li>Aim to spend around half of your starting amount on properties early in the game.</li></ol><p>Thank you for taking the time to read my article! If this type of content interests you, I recommend reading some of my other board game simulations including <a href="https://medium.com/towards-data-science/i-taught-a-machine-how-to-play-connect-4-df261da4e23f">Teaching a Machine How to Play Connect 4</a> or <a href="https://medium.com/towards-data-science/simulating-mancala-what-happens-when-i-push-this-game-to-its-limits-28d9c0a58616">Simulating Mancala</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=864e7cffe508" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/a-data-driven-tactics-simulation-for-monopoly-864e7cffe508">A Data-Driven Tactics Simulation for Monopoly</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simulating the Card Game “BS” to Find the Optimal Setup]]></title>
            <link>https://medium.com/codex/simulating-the-card-game-bs-to-find-the-optimal-setup-82541bacf628?source=rss-3d9ea428abd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/82541bacf628</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[card-game]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Jake Mitchell]]></dc:creator>
            <pubDate>Tue, 03 Jan 2023 07:24:20 GMT</pubDate>
            <atom:updated>2023-01-03T07:24:20.497Z</atom:updated>
            <content:encoded><![CDATA[<p>I used MATLAB to simulate the card game “BS” over 1,000 times — here&#39;s what I found:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AWtg8Yg9D9oqAWjo" /><figcaption>Photo by <a href="https://unsplash.com/@amandagraphc?utm_source=medium&amp;utm_medium=referral">Amanda Jones</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Introduction:</h4><p>The card game called “BS” (also known as “Cheat”, “I Doubt It”, or “Bluff”) is a very simple game at it’s core. You either have the correct card to play, or you must bluff your way through your turn. While there are certainly aspects of deception and strategy, there is also enough luck involved that when simulated thousands of times, some interesting patterns occur.</p><h4>The Rules of “BS”:</h4><p>Before I get into the coding of the game or the results of the simulations, I will briefly go over how the game is played.</p><p>A standard deck of 52 cards is dealt out evenly amongst all of the players. The player with the ace of spades puts that card in the middle of everyone, and then the game rotates clockwise. The player to their left now plays any 2’s facedown that they may have. The player after that plays any 3’s facedown. The players take turns placing down their cards in order from ace to king.</p><p>At some point, a player will be forced to play a card that they do not have in their hand. This player still needs to put a card down in the middle, so this player must lie. If at any point someone suspects an opponent of lying, they can call “BS” and flip the card their opponent just placed. If they were correct in calling the bluff of their opponent, the opponent receives all the cards that have accumulated in the middle over the rounds. If they were incorrect, and the opponent was not lying, the “BS” caller takes all of the cards.</p><p>The goal of the game is to get rid of all of your cards. The first to do so is declared the winner.</p><h4>Coding the Game:</h4><p>The idea that some players are theoretically at an advantage from the start due to their starting cards is what sparked this project. In order to test this, I needed to code the game itself so I could play thousands of games at a time to find any patterns. Here is how I did that:</p><p>A random permutation of 52 cards that are then classified into the 13 different face values, ace through king:</p><pre>cards = randperm(52,52);<br>    for i = 1:52<br>        if cards(i) &lt;= 4<br>            cards(i) = 1;<br>        elseif cards(i) &lt;= 8<br>            cards(i) = 2;<br>        elseif cards(i) &lt;= 12<br>            cards(i) = 3;<br>        elseif cards(i) &lt;= 16<br>            cards(i) = 4;<br>        elseif cards(i) &lt;= 20<br>            cards(i) = 5;<br>        elseif cards(i) &lt;= 24<br>            cards(i) = 6;<br>        elseif cards(i) &lt;= 28<br>            cards(i) = 7;<br>        elseif cards(i) &lt;= 32<br>            cards(i) = 8;<br>        elseif cards(i) &lt;= 36<br>            cards(i) = 9;<br>        elseif cards(i) &lt;= 40<br>            cards(i) = 10;<br>        elseif cards(i) &lt;= 44<br>            cards(i) = 11;<br>        elseif cards(i) &lt;= 48<br>            cards(i) = 12;<br>        else<br>            cards(i) = 13;<br>        end</pre><p>These are then evenly dealt out to all the players:</p><pre>while card_num &lt;= 52<br>        if p &gt; players<br>            p = 1;<br>        end<br>        hands(p,cards(card_num)) = hands(p,cards(card_num)) + 1;<br>        p = p + 1;<br>        card_num = card_num + 1;<br>    end</pre><p>I then start a loop that continues until a player has no more cards in their hand. This loop consists of a player either playing the correct card, or choosing a card to lie with in the event that they do not have a correct card to play.</p><pre>if hands(turn,value) &gt; 0 % if the player has that card, they put them in the pile<br>  amount = hands(turn,value);<br>  pile(1,value) = pile(1,value) + hands(turn, value);<br>  hands(turn,value) = 0;<br>  actual_move = value;<br>else % if not, then they pick a card to lie with<br>  done = 0;<br>  while done == 0<br>    random_lie = randi(13);<br>      if hands(turn,random_lie) &gt; 0<br>        amount = 1;<br>        pile(1,random_lie) = pile(1,random_lie) + 1;<br>        hands(turn,random_lie) = hands(turn,random_lie) - 1;<br>        actual_move = random_lie;<br>        stats(turn,2) = stats(turn,2) + 1;<br>        done = 1;<br>        break<br>      end<br>   end<br>end</pre><p>The final step is to have all the other players decide if they want to call ‘“BS”. The players decide by looking at their own hand, and what is currently in the shared middle pile. Take this scenario for example:</p><p>Player 1 places down 1 king out of their hand of 23 cards. Player 2 is currently holding 3 kings out of their hand of 11 cards. Player 2 also knows that there are currently no kings in the shared pile, because someone just called “BS” on the previous turn. This means that the odds that player 1 actually had a king to play are 23 out of 41, or 56%. 23 coming from the amount of cards in player 1’s hand, and 41 coming from the amount of cards in play that are not in player 2’s hand.</p><p>Once all players determine the odds of the current player telling the truth, the player that is the most suspect needs to make a decision. If one of the players determines that there is only a 11% chance that the player just told the truth, then they will call “BS” 89% of the time. The code for this is shown below:</p><pre>if and(amount == 1, first == 1) % if it&#39;s not the very first turn of the game<br>  poss = zeros(1,players);<br>  for j = 1:players % all other players decide if they want to call BS<br>    known = 0;<br>    possible = 0;<br>    poss(1,turn) = bs_sims + 1;<br>      if j ~= turn<br>        known = hands(j,value) + before; % each player calculates how many cards of that type they have, and how many have already been played<br>        if known &lt; 4 % if the player knows about the location of less than 4 cards<br>          for k = 1:bs_sims % loop for sims<br>            sim_setup = zeros(1, 52 - sum(hands(j,:)) - before_total); % setting up a row of all cards not in their own hand or in the pile<br>            while sum(sim_setup(1,:)) &lt; (4 - known) % randomly assigns a simulated card until the amount of unknown cards have been added<br>              sim = randi(size(sim_setup,2)); % randomly assigns a location<br>              if sim_setup(1,sim) == 0 % if the is not a card already in that location<br>                sim_setup(1,sim) = 1; % it puts the card there<br>              end<br>            end<br>            if sum(sim_setup(1,1:(sum(hands(turn,:)) + amount))) &gt;= amount % if that card happened to be in the opponent&#39;s hand<br>              possible = possible + 1; % increases the possibility by 1<br>            end<br>          end<br>          poss(1,j) = possible;<br>      else % if the player knows the location of all 4 cards<br>        poss(1,j) = 0;<br>      end<br>    end<br>  end<br>  [minimum,index] = min(poss);<br>  bs_nums = bs_nums + 1;<br>  confidence = confidence + minimum;<br>  lie = randi(bs_sims); % chooses a random value<br>  if lie &gt; minimum % if the player chooses to call BS<br>    BS = 1;<br>    if value ~= actual_move % if the player is correct<br>      hands(turn,:) = hands(turn,:) + pile(1,:); % gives whole pile to opponent<br>      pile(1,:) = 0;<br>    else % if player is incorrect<br>      hands(index,:) = hands(index,:) + pile(1,:); % gives whole pile to itself<br>      pile(1,:) = 0;<br>    end<br>  end<br>end</pre><h4>The Results:</h4><p>I simulated “BS” with as little as 3 players, to as many as 10. Each scenario was simulated 200 times with the intent to find the following statistics:</p><ul><li>Average Turns per Game — the amount of turns it takes until a winner is decided.</li><li>Average Lie Rate per Game — the amount of lies divided by the amount of total turns.</li><li>Average “BS” Correct Call Rate — the amount of correct “BS” calls divided by total “BS” calls.</li><li>Average Confidence Rate of “BS” Callers — how sure the players were that a player was lying on average.</li><li>Average End Variability Value — how distributed the cards were at the end of the game.</li></ul><p>The average turns per game generally increases as you add more players, with a couple exceptions (see image below). Games with 4 players and 6 players generally take less turns per player to complete, which is great for people who don’t want a game to last very long.</p><p>This has to do with the starting distribution of cards for odd-numbered player games. 52 cards can’t be evenly distributed to 3 or 5 players, so some players will have an extra card to start. This uneven start affects the “BS” rates of those with more cards, and extends the game length over a simulation of 200 games.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*14ee41p2JAu0b-mskCmksw.png" /><figcaption>Image provided by the author</figcaption></figure><p>The average lie rate over the course of a game increases as more players are added. This is because as the players increase, the number of starting cards decrease for each person. While less cards to get rid of is good, it also decreases the variety of cards a player starts with. This means players must lie more often.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*WyJ77fgrnvTOKoci4BLWlg.png" /><figcaption>Image provided by the author</figcaption></figure><p>The correct “BS” call rate is the rate at which opponents correctly identify when a player is lying. If players call “BS” 10 times in a game and are correct 6 times, then the rate would be 60%.</p><p>Players correctly call “BS” more times as more players are added as shown by the graph below. This has to do with the ever-decreasing odds that a player actually has a card as more players are added to the game (see the confidence rates explanation below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*4pomi7XhSZjg5ElhC6_8Wg.png" /><figcaption>Image provided by author</figcaption></figure><p>The confidence rate is how sure an opponent was that a player was lying. As the player number increases, the confidence rate increases as well. This is because with more players, the odds that any player has the required card to play is lower. A player who puts down 3 jacks in a 4 player game is much more likely to be telling the truth than that same person in a 10 player game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*KAf_y-4mUlRQY4npdNPvYw.png" /><figcaption>Image provided by the author</figcaption></figure><p>The variability value is the average value of card groups the players have left in their hand at the end of the game. For example, a variability value close to 4 means that players were left with an average a 4 cards per type. This statistic is important, because a higher value means that the end of the game was less deceptive. If all players have collections of 4 card sets in their hand, then nobody can lie and get away with it.</p><p>This value decreases as the players increase. From a player perspective, this would make the end of a game more fun for setups with more players.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*rfafkAuZ3aKD3ugyT87UbQ.png" /><figcaption>Image provided by the author</figcaption></figure><p>I was also interested in finding out how the amount of players affects how many groups of cards a player can encounter at the start. In addition to that, how does the amount of groups of cards in a hand affect the win rate of that player? Is it better to have more players or less players? These are the questions I look to answer with the following two statistics:</p><ul><li>Distribution of Card Groups based on Player Number</li><li>Average Win Rate</li></ul><p>The distribution of card groups at the start of the game varies depending on how many players there are. A game with 4 players will most likely yield a hand of 9 different groups of cards, whereas a game with 7 players will likely yield 6 groups (see visual below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*JAiUp41IX4759ijcU5locg.png" /><figcaption>Image provided by the author</figcaption></figure><p>This graph shows how an increase of players results in a decreased amount of card groups. In a game with 10 players, you will likely only have 4 or 5 different cards to play. This could be great for you if your 4 or 5 groups of cards align perfectly with the order of play, but will most likely end up with you needing to lie. If that is the case, what amount of players results in the most equal chance of winning for everyone, regardless of starting cards?</p><p>I tracked the win rates of all data points in the previous graph to find which amount of players is the most fair for everyone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*RnekCLv6IVS5IQeEb2YLsw.png" /><figcaption>Image provided by the author</figcaption></figure><p>As you can see in the graph, the most fair setup in terms of win rates is 8 players. 8 players has the lowest variability of win rates amongst all initial card distributions found in the simulation. In an 8 player game, the highest win rate goes to those with 6 groups of cards at the start (win rate of 12.94%) and the lowest win rate goes to players who had 4 groups of cards at the start (win rate of 9.94%). When looking at all the other setups, 8 players is clearly the best option in terms of win variability.</p><h4>Conclusions:</h4><p>The best setup for “BS” is an inherently arguable decision based highly on personal preference.</p><p>If you are great at bluffing and think you can use that to your advantage, then generally a game with more players suits you. The need to lie increases as you add more players, so being deceptive is a obvious advantage. You would also need to consider the fact that players get more confident when calling “BS” in games with more players. You may be great at lying, but if it’s simply impossible for you to put down a 7 then you’ll get called on it.</p><p>If you are someone who values the excitement and uncertainty at the end of the game, then more players is your answer. You’ll have more turns per game and more individual cards remaining at the end of the game.</p><p>If you don’t have time for a long-lasting game, then less players is your best bet. The game will take less turns, and the confidence rate is lower so there will be less “BS” calls.</p><p>For the most balanced game of “BS”, the simulations showed that 8 players is ideal for one main reason — the game starts out more equal. Nobody wants to play a card game where they start out with a huge disadvantage. Games with too few players or too many players heavily favorite those with the ideal setup given to them randomly right at the start. In addition, the lie rate hovers around 50%, giving those who like to be deceptive plenty of chances gain an advantage. To counter this, the correct “BS” call rate is around 66%, giving players plenty of opportunities to call the deceptive ones on their lies.</p><p>While “BS” may seem like a game of skill and deception, there is enough luck involved to give some an advantage right from the start. At the end of the day, if you are the unlucky player at the end of the game with 41 cards in your hand — it’s probably not your fault, but the fault of whoever shuffled and dealt the cards.</p><p>If this type of content interests you, I recommend reading some of my other game simulation articles like <a href="https://medium.com/codex/the-best-and-worst-catan-board-setups-989df4ba550a">“How I Built the Best Catan Board”</a>, <a href="https://medium.com/towards-data-science/i-taught-a-machine-how-to-play-connect-4-df261da4e23f">“I Taught a Machine How to Play Connect 4”</a>, or <a href="https://medium.com/towards-data-science/simulating-monopoly-finding-the-best-properties-using-matlab-130fe557b1ae">“Simulating Monopoly”</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82541bacf628" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/simulating-the-card-game-bs-to-find-the-optimal-setup-82541bacf628">Simulating the Card Game “BS” to Find the Optimal Setup</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Used Queuing Theory to Simulate Disney’s New Virtual Line System]]></title>
            <link>https://medium.com/data-science/i-used-queuing-theory-to-simulate-disneys-new-virtual-line-system-bd593213c006?source=rss-3d9ea428abd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd593213c006</guid>
            <category><![CDATA[matlab]]></category>
            <category><![CDATA[disneyland]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Jake Mitchell]]></dc:creator>
            <pubDate>Thu, 07 Apr 2022 14:30:33 GMT</pubDate>
            <atom:updated>2022-04-07T14:30:33.873Z</atom:updated>
            <content:encoded><![CDATA[<h4>A minute-by-minute population simulation comparing the new virtual queues to the classic fastpass system</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXaWK0UKadAHQ8qPPWm1bQ.jpeg" /><figcaption>Image provided by the author</figcaption></figure><h4>Introduction:</h4><p>On December 8th, 2021, Disneyland debuted a new virtual queuing system that replaced the original paper fastpass with a prepaid, mobile version. This new service is called Genie+, and it comes at a cost of $15 per person per day in the park. What was once a free service, available for all guests to take advantage of, is now a premium subscription. Does this new method give those who can afford the extra $15 a better Disney day? Has Disneyland officially divided it’s guests into mini social classes? I will attempt to answer these questions and more in this installment of Simulating Disneyland.</p><h4>Building the Simulation:</h4><p>To simplify the simulation, imagine a theme park in which guests enter into the middle of 10 different ride options, ranging from kiddie rides to thrill rides. Each ride is equidistant from the center of the park, and each ride has the same volume of 1500 riders/hour.</p><p>Now think of each person, all 16,800 of them, as an individual with very strict preferences. Each of these people are randomly given these qualities:</p><ul><li>A scheduled arrival and departure time that closely resembles how crowds enter and exit a theme park. Those time distributions are shown below, with T = 480 minutes (8am) being the time that the park opens and T = 1320 minutes (10pm) being the time that it closes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*XiIfry0GdNRp32t8w53mhg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*d0VYCx6omEUnUQv6GtfcSA.jpeg" /><figcaption>Images provided by the author</figcaption></figure><ul><li>A ride type preference using the same scale that the rides were classified previously. This distribution is shown below, with the average person enjoying a level 7 ride, but the most people enjoying a level 10.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*NpTcc94bHdGQryqVSKuGxg.jpeg" /><figcaption>Image provided by the author</figcaption></figure><ul><li>A balking time, which is the maximum time the person will wait to get on a ride. That distribution is shown below, with the average balking time being 45 minutes, and 95% of people having a balking time between 25 and 65 minutes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Cx_jXCeeUEqdBplm_Vs6nA.jpeg" /><figcaption>Image provided by the author</figcaption></figure><ul><li>Whether or not the person has fastpass capabilities, 1/3 of park guests have this capability for the Genie+ simulation.</li></ul><p>When it comes time for an individual to select a ride, all 10 rides are scored based on the current wait time, how the ride matches the person’s thrill preferences, and whether or not they have already ridden it. The person then selects one of the more favorable rides and walks to it.</p><p>When the person gets to the ride entrance, they either get in line, or balk at the time and leave to go find another ride. This balking time is different for every person, much like it is in reality. If the person balks at the time and has fastpass capabilities, they will get a fastpass/lightning lane return time and then join the virtual queue. They also go to pick a new ride to go on while they wait out their virtual return time. The code for this decision making is shown below:</p><pre>if crowd_data(j,11) &gt; ride_data(crowd_data(j,6),5) % if person thinks wait time is good</pre><pre>waittime_score = 1/(1+exp(0.05*((round(ride_data(k,1)*60/volume)) - 45))); % Waittime score is sigmoid-based, low wait times = 1, high wait times = 0</pre><pre>thrill_score = 1/(1+exp(-0.25*(abs(ride_data(crowd_data(j,6),4) - crowd_data(j,3))-4))); % How similar the ride is to the person&#39;s interests, also sigmoid based</pre><pre>if crowd_data(j,crowd_data(j,6) + 11) == 0 % if the person has ridden the ride already</pre><pre>variation_score = 1;</pre><pre>else</pre><pre>variation_score = 0;</pre><pre>end</pre><pre>crowd_data(j,25) = 50*waittime_score + 33.33*thrill_score + 33.33*variation_score; % adds the score to the person&#39;s cell</pre><pre>crowd_data(j,5) = 3; % indicates waiting in line</pre><pre>crowd_data(j,7) = ride_data(crowd_data(j,6),5); % sets wait time to posted time</pre><pre>ride_data(crowd_data(j,6),1) = ride_data(crowd_data(j,6),1) + 1; % increases ride posted wait time</pre><pre>ride_data(crowd_data(j,6),5) = round(ride_data(crowd_data(j,6),1)*60/1500); % updates wait time</pre><p>For every minute of the day (8am — 10pm), every person has an action carried out, whether that’s one less minute waiting in line, or one less minute walking to the ride. Data on every individual and ride is tracked over the course of the day. These data points include:</p><ul><li>Balking Rates — how many times each person balked at a wait time that day.</li><li>Fastpasses Used — how many times each person used a fastpass/lightning lane that day.</li><li>Ride History — how many times each person rode each ride.</li><li>Current Action — whether the person was picking a ride, walking, waiting in line, or riding a ride at each minute of the day.</li><li>Total Time Waited — sum of how long each person stood in a line.</li><li>Total Rides — sum of how many rides the person went on.</li><li>Total “Fun” Score — a value generated after a person gets on a ride based on how long they waited and how much they enjoy that type of ride. These are summed up for the day for each person.</li><li>Wait Time — how long the current wait time is for each ride at each minute of the day.</li></ul><p>Using these data points for three different fastpass systems, I will be able to compare how wait times and crowd mood is affected by each type.</p><h4>Results:</h4><p>I figured it would be best to reveal the results of each system in the order that they were used by Disneyland. This means that the “No Fastpass” system from 1955–1999 will go first.</p><p>No individual in the simulation has fastpass capabilities, and they either choose to get in line or try their luck at another ride. This simulation yielded these results:</p><ul><li>Average Rides/Person: 7.732 Rides</li><li>Average Wait Time: 60.97 Minutes</li><li>Average “Fun” Score: 528.68</li></ul><p>From 1999–2021, the classic paper fastpass system was in use. Now, every individual in the simulation has fastpass capabilities. This simulation yielded these results:</p><ul><li>Average Rides/Person: 8.90 Rides</li><li>Average Wait Time: 52.10 Minutes</li><li>Average “Fun” Score: 350.72</li></ul><p>Lastly, starting in 2021, the new virtual fastpass system is in use. Now, only those who pay the $15 have Genie+ capabilities (around 1/3 of the crowd). This simulation yielded these results:</p><ul><li>Total Average Rides/Person: 8.02 Rides</li><li>Total Average Wait Time: 57.45 Minutes</li><li>Total Average “Fun” Score: 462.10</li></ul><p>Now it is separated into two categories, those who purchased Genie+ and those who did not:</p><ul><li>Genie+ Member Average Rides/Person: 10.24 Rides</li><li>Genie+ Member Average Wait Time: 43.30 Minutes</li><li>Genie+ Member Average “Fun” Score: 465.18</li><li><em>Non</em>-Genie+ Member Average Rides/Person: 6.90 Rides</li><li><em>Non</em>-Genie+ Member Average Wait Time: 68.10 Minutes</li><li><em>Non</em>-Genie+ Member Average “Fun” Score: 460.54</li></ul><h4>Analysis:</h4><p>There is a noticeable difference between those who paid for fastpass privileges in all three categories. Those who paid for Genie+ experienced 3.34 more rides, waited 33.8 minutes less, and had 4.64 more fun points on average when compared to those who didn’t pay.</p><p>While this does seem like a good deal for $15, it actually increased the total average wait time per person (+5.35 minutes) and decreased the average rides per person (-0.88 rides) when compared to the original paper fastpass. However, Genie+ yielded a higher average fun score at 462.10 when compared to the original fastpass system (350.72). Why are people having more fun even when the average wait time went up?</p><p>It has to do with the skewness of the lightning lane fun score distribution. While the average ride count and wait times don’t look good for Genie+, the fun score distribution is skewed far to the right, meaning that lightning lanes allow for those who paid for Genie+ to have massive fun scores. The drawback would be that less people are having average fun scores when compared to the other two systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*1LOWW5Qfb6r5hZ1moQ9_4g.jpeg" /><figcaption>Image provided by the author</figcaption></figure><p>While this is a plus for lightning lanes, it doesn’t compare to the fun scores of the pre-fastpass era (1955–1999). The fun score of the no-fastpass simulation (528.68) is incredible considering that there is no option other than to wait in a long line if necessary. I suppose people are happier when there is not an invisible line taking spots on the ride before them.</p><p>The plots below represent what each person is doing in the park during each minute of the day (Left = No Fastpass, Middle = Classic Fastpass, Right = Genie+).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*48p-G0nARcu7l3jBrPmm9g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*7w3KAasyR_AfdJZ0wchi1A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*wTvPZmxua5qOiYb7bR4qGA.jpeg" /><figcaption>Images provided by the author</figcaption></figure><p>These show the differences in crowd decisions based on the type of fastpass system. The no-fastpass system reaches peak waits at 5pm with 88% of the crowd in a queue, the classic fastpass system reaches peak waits at 6:30pm with 87% of the crowd in a queue, and the Genie+ reaches peak waits at 4:30pm with 91% of the crowd in a queue.</p><p>This means that the current Genie+ system makes wait times drop off sooner, with the park reaching 50% queuing rates by 8:30pm (compared to 9:15pm for the no-fastpass system).</p><p>One of the main reasons why fastpasses exist is the idea that these systems can disperse the crowds more evenly throughout the park. By finding the variance of each wait time at each minute during the day, I can see how well the crowds are dispersed for all three systems. The plots below show the variance throughout the day for the wait times of all 10 rides (Left = No Fastpass, Middle = Classic Fastpass, Right = Genie+). Lower variance is better, and it means that all of the wait times are more similar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*qiiSV6IFUdUmmmN3NPvziw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*vP2ZmGuuNpmfCJdYNszmVg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*LnVvGqPZfHGAL0JXWvl-qA.jpeg" /><figcaption>Images provided by the author</figcaption></figure><p>The average wait time variance for the no-fastpass system (left) was 3.41, meaning that the wait times were 3.41 minutes away from the mean for the day. The spikes in variance near the beginning and end of the day are due to individuals arriving and leaving the park at their respective times. When the variance settles at it’s lowest point during the middle of the day, the park has reached an equilibrium state. This equilibrium period happens from 11am — 4:30pm for the no-fastpass system.</p><p>The average wait time variance for the classic fastpass system (middle) was 3.44. It’s equilibrium state happens from 11am — 5:00pm.</p><p>The average wait time variance for the Genie+ system (right) was 4.04. It’s equilibrium state happens from 11am — 4:30pm just like the no-fastpass system.</p><p>In terms of dispersing crowds, the no-fastpass system worked best with the lowest average variance for the day (3.41). However, in terms of longest equilibrium period, the classic fastpass system worked best with a period length of 6 hours. Perhaps the crowds at this park do well in dispersing themselves without needing a virtual queue to do it for them.</p><h4>Conclusions:</h4><p>Looking back at the statistics and plots presented, it is clear that while the classic fastpass system yielded the best wait times (52.10 avg. minutes) and ride counts (8.90 avg. rides), it was really the no-fastpass system that gave the crowd the best Disney day (528.68 avg. fun points).</p><p>Has Disney officially divided it’s guests into mini social classes? If we look at the differences between those who paid for Genie+ and those who did not, we’ll see that the additional 3.34 average rides and 33.8 less minutes in line provide a massive gap between the two sides. This could be considered acceptable if there were some benefits like an overall decreases in wait times, but the simulation showed that it made wait times increase by 5 minutes and it actually increased the queue length variance.</p><p>So if there is no park benefit to Genie+, then why did Disney implement this new system into their parks? The answer is pretty simple — $$$. With a park of this size, (10 rides, 16,800 guests maximum per day), the park revenue would increase by $84,000 per day. That’s over 30 million dollars per year of added revenue for this hypothetical park, a park that is roughly 1/3 the size of Disneyland. Disneyland is also just 1 of the 4 parks currently using Genie+ as well. It’s no wonder why Disney achieved all-time revenue and operating income records in the first quarter of 2022.</p><p>So the answer is yes, there are now two distinct social classes at Disneyland. Those who can afford to pay $15 per person per day ($375 for a family of 5 on a 5-day vacation), and those who cannot. Does this mean that all fastpasses are bad? No. The classic fastpass system did not prey on the family vacationers, but instead gave advantages to those who were smarter with their time, regardless of their budget or group size.</p><p>Unfortunately, the simulation shows that Disney is heading in the wrong direction with Genie+.</p><p>If this type of content interests you, I suggest reading my other pieces on Disneyland simulations:</p><p><a href="https://towardsdatascience.com/the-disneyland-algorithm-a-supervised-machine-learning-program-67c730cd62d5">The Disneyland Algorithm: A Supervised Machine Learning Program</a></p><p><a href="https://towardsdatascience.com/predicting-disneyland-strategies-to-better-your-disney-day-e08f8b84f51">Predicting Disneyland: Strategies to Better Your Disney Day</a></p><p><a href="https://towardsdatascience.com/predicting-disneyland-wait-times-through-population-simulations-20f44c7582f6">Predicting Disneyland Wait Times Through Population Simulations</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd593213c006" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/i-used-queuing-theory-to-simulate-disneys-new-virtual-line-system-bd593213c006">I Used Queuing Theory to Simulate Disney’s New Virtual Line System</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The 256-Team MEGA March Madness Bracket Simulation]]></title>
            <link>https://medium.com/top-level-sports/the-256-team-mega-march-madness-bracket-simulation-f53591a4e9d7?source=rss-3d9ea428abd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f53591a4e9d7</guid>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[march-madness]]></category>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[matlab]]></category>
            <dc:creator><![CDATA[Jake Mitchell]]></dc:creator>
            <pubDate>Thu, 10 Mar 2022 19:52:04 GMT</pubDate>
            <atom:updated>2022-03-12T17:54:24.449Z</atom:updated>
            <content:encoded><![CDATA[<h4>Simulating every possession of a 256-team March Madness tournament using offensive statistics and MATLAB.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*Q5HbBDQixiw3HregloRWcA.png" /><figcaption>Image provided by the author</figcaption></figure><h4>Introduction:</h4><p>With Selection Sunday just days away, I began working on my MATLAB code for simulating the March Madness bracket. My goal was to find the odds of each team reaching each round of the tournament, using offensive statistics found on NCAA statistical sites. It was at this point that I realized that I was doing what dozens of other major stats websites were doing, and I wanted to create something different. Hence, the 256-team bracket was born.</p><p>Imagine a tournament in which the 1–16 game became the 1–64 game, and the 12-seed Cinderella story was now the 34-seed Cinderella story. The 63-game bracket now becomes a 255-game mega bracket, and anything is possible.</p><h4>Building the Simulation:</h4><p>There are 358 NCAA D1 Men’s Basketball programs and only 256 spots available. Some cuts have to be made. I wanted this to be straightforward, so I cut the lowest 102 teams in terms of Strength of Record (a metric that not only takes into account wins and losses, but also the Strength of Schedule of the team). This leaves the strongest 256 teams to compete for the hypothetical national championship. This strength ranking is also what I used for seeding all 256 teams.</p><p>In the past, I simply used one metric for each team to simulate a win or a loss. Teams with a higher overall ranking would have a better chance of beating a team with a lower ranking (like in my <a href="https://towardsdatascience.com/simulating-the-nba-2021-22-season-results-a0884b13690a">NBA Simulation</a> article). This time, I wanted to simulate each possession of a game between two teams. This meant retrieving data for the following fields:</p><ul><li>Adjusted Field Goal Percentage</li><li>Adjusted Three Point Percentage</li><li>Adjusted Free Throw Percentage</li><li>Turnover Rate</li><li>Offensive Rebound Rate</li><li>Average Time-Per-Possession</li></ul><p>Using these 6 metrics, I can code each possession using the following flowchart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*mWZaqsEPZNBjHxRsAqp4ZA.png" /><figcaption>Image provided by the author</figcaption></figure><p>The code that calculates the chances of advancing down each path of the flowchart above is shown below:</p><pre>rebound_chance = teamdata(team,21)/100;</pre><pre>shot_chance = (teamdata(team,7) + teamdata(team,13))/(teamdata(team,7) + teamdata(team,13) + teamdata(team,19));</pre><pre>total_poss = teamdata(team,7) + teamdata(team,13);</pre><pre>ft_chance = teamdata(team,13)/total_poss;</pre><pre>pt2_chance = (total_poss - (teamdata(team,13) + teamdata(team,10)))/total_poss;</pre><pre>pt3_chance = teamdata(team,10)/total_poss;</pre><pre>ft_make = teamdata(team,14);</pre><pre>pt2_make = (teamdata(team,6) - teamdata(team,9))/(total_poss - (teamdata(team,13) + teamdata(team,10)));</pre><pre>pt2_make = pt2_make * (1/(1+exp(0.12*(-1*teamdata(team,2)-15))));</pre><pre>pt3_make = teamdata(team,11);</pre><p>After a round of the flowchart is complete for a team’s possession, the time remaining in the game is reduced by the average possession time for that team.</p><p>This pattern is repeated between the two teams until the 40-minute clock expires, signaling the end of the game. If the score is tied, 5 minute overtime periods are played until a winner is decided.</p><p>The winners of each game move on to the next round, and the process is repeated for all 255 games.</p><h4>The Results:</h4><p>In the tables below, the team name is listed on the left side along with their original seed. The colored cells indicate that team’s chance of making it into that round. For example, Gonzaga (1 seed) has a 99.79% chance of making it into the round of 128 teams remaining, and a 13.77% chance of winning the tournament. It should be noted that there are 4 quadrants of the mega bracket, meaning that there are 4 of each seed. Below is the top portion of teams in terms of championship chances:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s0fMN4sroCOUJQ7P1qhbfg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T3jwsxW6OYr9zKZehJSv9A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m63dkk7oOD71HHJHLZyUyg.png" /><figcaption>Images provided by the author</figcaption></figure><p>The first thing that stands out is South Dakota State, a 13-seed, having the 10th best chance to win the national tournament. The 256-team mega bracket is built for teams like this. Even after adjusting for strength of record, South Dakota State (SDSU) boasts a nation-leading 0.402 3pt%, and 3rd-overall 0.494 FG%. It’s 13-seed pairs SDSU with 52-seed Montana University, giving them a 95.58% chance to advance to the next round. They also have great placement in that they wouldn’t have to face the 1-seed Auburn (also the weakest 1-seed) until the Elite 8 round. This same principle applies to Virginia Tech (13), Furman (24), and Toledo (16). Just as it is with the normal 64-team tournament, seeding can play a huge role in a team’s postseason success.</p><p>Another thing that I love about this simulation is the sheer amount of teams that have a decent chance of winning the championship. For the normal 64-team bracket, there are usually only 3–4 serious contenders. For the 256-team mega bracket, there are 12 teams with above a 2% chance to win the title, with an additional 11 more teams above a 1% chance to win.</p><p>Over the course of 10,000 simulations, 182 different teams made the final 4, and 117 different teams were crowned the champions. The increased amount of teams and rounds certainly increased the madness.</p><p>Below are teams 100–215 in terms of championship chances:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K5qfwO-0vGRRh7ecPSK7VQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d7Zn02seJzEOvnxvlOIiLw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hzn4vzz1uYmiJQcEnpczfw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ikpG1r8gUopRiJTqxYxSWg.jpeg" /><figcaption>Images provided by the author</figcaption></figure><h4>Conclusion:</h4><p>While the 256-team Mega March Madness bracket is 4 times the fun, it would definitely take twice as long (2 additional rounds), and March and April Madness just doesn’t have a good ring to it. While I don’t see the NCAA expanding the tournament anytime soon, it was interesting to watch some new matchups play out and give the underdogs a better chance at a national title.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f53591a4e9d7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/top-level-sports/the-256-team-mega-march-madness-bracket-simulation-f53591a4e9d7">The 256-Team MEGA March Madness Bracket Simulation</a> was originally published in <a href="https://medium.com/top-level-sports">Top Level Sports</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simulating the NBA: 2021–22 Season Results]]></title>
            <link>https://medium.com/data-science/simulating-the-nba-2021-22-season-results-a0884b13690a?source=rss-3d9ea428abd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0884b13690a</guid>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[nba]]></category>
            <dc:creator><![CDATA[Jake Mitchell]]></dc:creator>
            <pubDate>Fri, 01 Oct 2021 13:01:57 GMT</pubDate>
            <atom:updated>2021-10-01T13:01:57.801Z</atom:updated>
            <content:encoded><![CDATA[<h4>I used Monte-Carlo methods to simulate all 1,230 games plus the postseason. How many wins will your team get?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*PWG0G0-5ueF9d-bcrdG-0g.png" /><figcaption>Image provided by the author</figcaption></figure><h4>Introduction:</h4><p>With the start of the NBA 2021–22 Preseason approaching quickly, I set out to simulate every team’s 82 games, plus the postseason, to find the league’s best and worst performances.</p><h4>Coding the NBA:</h4><p>Similar to my <a href="https://towardsdatascience.com/the-nfl-simulation-monte-carlo-methods-2f110424b1dd">NFL Season Simulation</a>, all 30 teams have a rating. This year’s range starts at 1304 (Cleveland Cavaliers) and goes to 1752 (Milwaukee Bucks) with every other team somewhere in between.</p><p>Every team’s chance of winning a matchup is determined by this rating. Take the season opener as an example: The Bucks (1752) at home against the Nets (1717).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*fdAmH1l_RNIMFud0SRDksA.png" /><figcaption>Image provided by the author</figcaption></figure><p>Using these equations, the Bucks have a 55.20% chance to win, while the Nets have a 44.80% chance to win.</p><p>A random number generator decides the winner, and then both ratings are adjusted based on if they were the underdog or not. The Bucks beating the Nets would increase their rating less than if the Nets beat the Bucks, purely because the Bucks are expected to win. This allows for teams to gain momentum throughout a season. The code for this is shown below:</p><pre>for i = 1:length(home_schedule)</pre><pre>Ha = 1/(1+10^((team_data(home_schedule(i),1) - team_data(away_schedule(i),1) + 2.5) * -1/400)); % approx home team chance of winning</pre><pre>Aa = 1/(1+10^((-1 * team_data(home_schedule(i),1) + team_data(away_schedule(i),1)) * -1/400)); % approx away team chance of winning</pre><pre>T = Ha + Aa - 1; % chance of a tie</pre><pre>H = Ha - T/2; % adjusted home team winning chances</pre><pre>A = Aa - T/2; % adjusted away team winning chances</pre><pre>team_data(home_schedule(i),1) = team_data(home_schedule(i),1) + 20 * (HW - H); % adjusts home team&#39;s ranking based on result</pre><pre>team_data(away_schedule(i),1) = team_data(away_schedule(i),1) + 20 * (AW - A); % adjusts away team&#39;s ranking based on result</pre><pre>end</pre><p>This pattern is applied to all 1,230 games to decide the postseason schedule. The NBA postseason consists of 10 teams from each conference. The top 6 teams from each are automatically placed into the first round, while seeds 7–10 play in a small bracket to decide the 7th and 8th seed. Once all 8 teams from both conferences are determined, the postseason commences like a standard bracket, with the winners of both conference finals meeting at the championship game. Each matchup is a best of 7 series, with the higher seed getting the home games in game numbers 1,2,5, and 7 (if necessary).</p><p>All the data for regular season records, postseason records, and playoff chances are documented along the way as the season is repeated 50,000 times.</p><h4>The Results:</h4><p>Below shows the most likely regular season record for all 30 teams, along with the statistics after 50,000 simulated seasons. The minimum and maximum columns represent the least and most amount of wins in a season for that team. The 10%, 50%, and 90% are the percentiles for all 50,000 simulations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*syTPCdwQW1DrDU0WCire6Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*4BlHPYJ2wCJmkPFtncgsoA.png" /><figcaption>Images provided by the author</figcaption></figure><p>The Miami Heat are expected to go 43–39, with a 10% chance that they win less than 33 games and 10% chance that they win more than 55 games. This leaves them with an 80% chance they win between 33 and 55 games.</p><p>Each team’s playoff chances are shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*rPQb7GG-qWxspiv6i4WNRg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*PWG0G0-5ueF9d-bcrdG-0g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*-mmvEfjU16B-O_DsswpZnA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*-DlFKHYCbh9M7aiJzuLh7w.png" /><figcaption>Images provided by the author</figcaption></figure><p>The first column represents the chances of that team finishing in the top 10 of that conference, meaning that they made the playoffs. The next column is the chance that a team makes the first round games (top 8).</p><p>Only one team did not win a single championship out of all 50,000 games, the Cleveland Cavaliers. The Orlando Magic and Oklahoma City Thunder both only won one championship.</p><p>The top 3 favorites to win the NBA Finals are the Milwaukee Bucks (16.150%), the Los Angeles Clippers (12.158%), and the Phoenix Suns (11.802%).</p><p>I was also interested in the odds that a team has the best or worst season in NBA history. The chance that at least one team beats the season wins record is 6.44%, with the Milwaukee Bucks accounting for 34.70% of those seasons. The next two likely teams are the Los Angeles Clippers (14.20%) and the Phoenix Suns (13.77%).</p><p>The chance that at least one team beats the season losses record is 12.08%, with the Cleveland Cavaliers accounting for 40.31% of those seasons. The next two likely teams are the Orlando Magic (19.20%) and the Oklahoma City Thunder (16.55%).</p><p>Out of all 50,000 simulated seasons, only one team has a chance to beat both the season wins and losses record. The Golden State Warriors have a 0.026% chance to lose the most games in NBA history, but a 0.031% chance to win the most games in NBA history.</p><h4>Conclusions:</h4><p>This NBA season simulation showed that the Milwaukee Bucks are clear favorites for this year’s NBA Finals (16.15%), even with the Western Conference accounting for the majority of the championships won (54.05%).</p><p>The odds of a team having the worst season in NBA history are nearly twice as much as a team having the best season in NBA history.</p><p>Only one team won zero championships over all 50,000 simulations, and that is the Cleveland Cavaliers with an expected record of 17–65.</p><p>If this type of content interests you, I recommend reading my other article on professional sports simulations, <a href="https://towardsdatascience.com/the-nfl-simulation-monte-carlo-methods-2f110424b1dd">The NFL Simulation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0884b13690a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/simulating-the-nba-2021-22-season-results-a0884b13690a">Simulating the NBA: 2021–22 Season Results</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simulating Mancala: What Happens When I Push This Game to its Limits?]]></title>
            <link>https://medium.com/data-science/simulating-mancala-what-happens-when-i-push-this-game-to-its-limits-28d9c0a58616?source=rss-3d9ea428abd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/28d9c0a58616</guid>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[matlab]]></category>
            <category><![CDATA[board-games]]></category>
            <dc:creator><![CDATA[Jake Mitchell]]></dc:creator>
            <pubDate>Thu, 23 Sep 2021 12:58:12 GMT</pubDate>
            <atom:updated>2021-09-23T12:58:12.296Z</atom:updated>
            <content:encoded><![CDATA[<h3>Simulating Mancala: What happens when I push this game to its limits?</h3><h4>Using MATLAB, I simulated 100,000 Mancala games to see what would happen. Here are the results:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*t1LoJ0oJdILDs7vc8OHt7Q.png" /><figcaption>Image provided by the author</figcaption></figure><h4>Introduction:</h4><p>With Mancala being one of the oldest games in the world, it only made sense to pick this game as my next board game MATLAB project. Mancala is a zero-sum game, meaning that one person’s gain directly results in the other person’s loss. This makes it very easy to simulate hundreds of thousands of games at a time.</p><h4>Mancala Rules:</h4><p>This is a very simple game. Each player has 6 pits and a store for a total of 12 pits and 2 stores on the board. Each pit has 4 seeds at the start. The goal is to get the most seeds in your store. For each turn, one player picks one of their 6 pits and takes out all of the seeds. Moving counter-clockwise, that player drops one seed out of their hand and into the next pit or store, until running out of seeds in their hand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fJcoeHBYm-eRpWA-3kS-VQ.jpeg" /><figcaption>Image provided by <a href="https://www.pexels.com/">pexels.com</a></figcaption></figure><p>There are some special rules to note as well:</p><ul><li>If your last seed ends in your store, you get to go again.</li><li>If your last seed ends in a completely empty pit on your side, you get to collect all the seeds directly across the board.</li></ul><p>The game ends when one person’s side is completely empty, at which the other player collects the remaining seeds from their pits and places them in their store. The stores are counted up, and the person with the most seeds wins.</p><h4>Coding Mancala:</h4><p>This simulation works by having two players make random moves against each other until one person wins. A pit that has seeds is randomly picked, and those seeds are distributed counter-clockwise along the board (see below).</p><pre>while gameover == 0 % while nobody has won</pre><pre>while p1_turn == 0 % while still player 1 turn</pre><pre>if sum(layout(1:6)) ~= 0 % while player 1 still has seeds in pits</pre><pre>moves = moves + 1; % plus 1 for total moves</pre><pre>while good_pick1 == 0 % loop to find a pit with seeds</pre><pre>p1 = randi(6); % picks random pit</pre><pre>amount = layout(p1); % finds amount of seeds in that pit</pre><pre>if amount &gt; 0 % if pit has seeds</pre><pre>break % breaks out of loop (found a good pit)</pre><pre>end</pre><pre>end</pre><p>At the end of every game, the data points of interest are documented and carried through until all 100,000 simulations are complete.</p><pre>move_data(repeats) = moves; % adds moves to move dataset</pre><pre>p1_data(repeats) = mean(p1_moves); % adds average move to player 1 move dataset</pre><pre>p2_data(repeats) = mean(p2_moves) - 7; % adds average move to player 1 move dataset</pre><pre>score1_data(repeats) = layout(7); % adds player 1 score to player 1 score dataset</pre><pre>score2_data(repeats) = layout(14); % adds player 2 score to player 2 score dataset</pre><h4>The Results:</h4><p>What does a standard game of Mancala look like? How many average turns does it take to complete a game? What is the shortest possible game? All of these questions can be answered through 100,000 Mancala simulations.</p><p>The average game of Mancala (4 seeds per pit) takes 41.42 moves to complete a game. The longest game found was 77 moves long, and the shortest was 11 moves long (see histogram below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*xwBNcS-4Wd05zGdE9D177A.jpeg" /><figcaption>Image provided by the author</figcaption></figure><p>The shortest possible game happens when one player gets rid of all of their seeds very quickly, and then the game ends with the other player collecting the remaining seeds.</p><p>What about the win probability for each player? Does going first have any impact on your chances of winning? Well, with 4 seeds in each pit at the start, the player who goes first has a 48.624% chance of winning, while the other player has a 44.604% chance of winning (with the remaining 6.772% chance being for a tie).</p><p>Is there a best first pit to choose when starting a game to increase your chances of winning? If you are the player to make the first move, choosing pit #6 (the rightmost pit) will get you an average 24.9033 seeds per game, which is 0.3 more seeds on average than the next highest pit. The same goes for the second player to go. Pit #6 will get them an average 23.9039 seeds per game.</p><h4>Pushing Mancala to its Limits:</h4><p>What does a game with 100 seeds per pit at the start look like? What about 1,000? How does that affect win and tie probabilities?</p><p>I ran 100,000 simulations for each starting seed amount shown below (1–10, 15,20,50, and 100) to see how the win percentages changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*t1LoJ0oJdILDs7vc8OHt7Q.png" /><figcaption>Image provided by the author</figcaption></figure><p>The chances of a game tying went down as the number of starting seeds increased. This makes sense because the odds of the stores having the exact amount of seeds at the end gets lower and lower as the amount of seeds increases.</p><p>The win probabilities are interesting to note here. The difference between the player with the first move and player with the second move seems to get smaller, meaning that as more seeds are added, the game gets more fair. At 10 seeds per pit, the difference jumps back up again and starts over. This means that if you want the fairest match possible, 9 seeds per pit is the ideal setup (also 100 seeds has a small difference, but that game would take forever).</p><p>I also wanted to look at how the amount of starting seeds affects the total average moves to complete a game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*7UxLtdEEOOevsdAufeciog.png" /><figcaption>Image provided by the author</figcaption></figure><p>The average moves per game does not increase linearly, but almost in a logarithmic fashion. I expanded it out to 1000 seeds and 5000 seeds and found a best-fit equation with an R² value of 0.9715 (shown below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*c5hGd_LlcWBflLffCv0agw.png" /><figcaption>Image provided by the author</figcaption></figure><p>The best-fit equation can be used to find approximately how many moves a game would take for any starting seed amount, assuming you start with 3 or more.</p><h4>Conclusion:</h4><p>Mancala has some interesting patterns that occur as you tweak the starting setup in different ways. Going first can increase your chances of winning by a significant amount, and if you want to lower the chance of a game ending in a tie, add more seeds. It is fascinating to look at the limits of board games and how the game reacts in those moments.</p><p>If this type of content interests you, I recommend reading some of my other articles on simulating board games with MATLAB:</p><ul><li><a href="https://medium.com/codex/the-best-and-worst-catan-board-setups-989df4ba550a">Building the Best Catan Board</a></li><li><a href="https://towardsdatascience.com/simulating-monopoly-finding-the-best-properties-using-matlab-130fe557b1ae">Finding the Best Monopoly Properties</a></li><li><a href="https://towardsdatascience.com/the-surprisingly-interesting-mathematics-within-chutes-and-ladders-40f931c18489">The Mathematics within Chutes and Ladders</a></li><li><a href="https://towardsdatascience.com/applying-machine-learning-to-tic-tac-toe-47d954671c73">Teaching a Machine to Play Tic-Tac-Toe</a></li><li><a href="https://towardsdatascience.com/i-taught-a-machine-how-to-play-connect-4-df261da4e23f">Teaching a Machine to Play Connect-4</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28d9c0a58616" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/simulating-mancala-what-happens-when-i-push-this-game-to-its-limits-28d9c0a58616">Simulating Mancala: What Happens When I Push This Game to its Limits?</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Surprisingly Interesting Mathematics within Chutes and Ladders]]></title>
            <link>https://medium.com/data-science/the-surprisingly-interesting-mathematics-within-chutes-and-ladders-40f931c18489?source=rss-3d9ea428abd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/40f931c18489</guid>
            <category><![CDATA[matlab]]></category>
            <category><![CDATA[board-games]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Jake Mitchell]]></dc:creator>
            <pubDate>Sat, 11 Sep 2021 04:33:57 GMT</pubDate>
            <atom:updated>2021-09-11T04:33:57.237Z</atom:updated>
            <content:encoded><![CDATA[<h4>I wrote a MATLAB program that simulates 100,000 Chutes and Ladders games. Here are the results.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*yjQamOxx3ljviKtvIWktsw.jpeg" /><figcaption>Image provided by the author</figcaption></figure><h4>Introduction:</h4><p>Chutes and Ladders is a game based on complete random chance. There is no strategy involved whatsoever. Your pawn movement completely relies on what number you spin on every turn. While this makes it a rather boring game for some, it provides those interested in data science with a solid foundation for a game simulator.</p><h4>Chutes and Ladders Rules:</h4><p>This game is extremely simple. On your turn, you spin a dial and get a number between 1 and 6. Starting from space 0, you move your pawn the amount of spaces you were granted by the dial. If you land on a ladder, you climb up the ladder to that space above. If you land on a chute, you slide down to that space below. The first person to land on the 100th space exactly wins.</p><h4>Coding the Game:</h4><p>I started out by having a random number generator pick a number between 1 and 6. Then, the pawn is moved to that new space. If that pawn lands on a chute or a ladder, it is taken to it’s new space.</p><pre>while gameover == 0 % keeps the loop going if game is not over</pre><pre>turns = turns + 1; % keeps track of amount of turns</pre><pre>spin = randi(6); % random number between 1 and 6</pre><pre>spin_data(length(spin_data) + 1) = spin; % adds spin value to dataset</pre><pre>start = start + spin; % moves pawn</pre><pre>if turns == 1 % if first turn</pre><pre>starting_spin = spin; % adds dial value to first spin dataset</pre><pre>end</pre><pre>for i = 1:length(ladder_start) % checks if pawn should go up ladder</pre><pre>if start == ladder_start(i)</pre><pre>start = ladder_end(i);</pre><pre>break</pre><pre>end</pre><pre>end</pre><pre>for i = 1:length(chute_start) % checks if pawn should go down chute</pre><pre>if start == chute_start(i)</pre><pre>start = chute_end(i);</pre><pre>break</pre><pre>end</pre><pre>end</pre><p>The program also has parts that check to see if the pawn reaches the 100th space exactly for the win.</p><pre>if start &gt; 100 % if space is above 100</pre><pre>start = start - spin; % takes pawn back to original spot</pre><pre>end</pre><pre>if start == 100 % if pawn reaches exactly 100</pre><pre>gameover = 1; % ends game</pre><pre>break</pre><pre>end</pre><p>All the data in terms of average dial value, first dial value, best and worst turn amounts, and even amount of times a space is landed on is documented and used to produce graphics that can help show the mathematics within Chutes and Ladders.</p><h4>Results:</h4><p>The average number of turns it takes to reach the 100th space in Chutes and Ladders is 38.93 turns, with a standard deviation of 24.81. Below is the histogram for number of turns per game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*7Zdefla-cERkpcGXLklPDg.jpeg" /><figcaption>Image provided by the author</figcaption></figure><p>The best game of Chutes and Ladders involved just 7 dial spins. Starting from space 0, they spun a 1, which took them up a ladder to the 38th space. Then they spun a 5 and a 3, bringing them to the 46th space. Another 5 resulted in another ladder sending them up to space 67. A dial spin of 4 sent them up a third ladder to space 91. Finally, a dial spin of 6 and 3 put them right on the 100th space as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*44mdMpIFpIHoFB-70Z2IaQ.png" /><figcaption>Image provided by the author</figcaption></figure><p>The worst game of chutes and ladders went on for an incredible 312 turns. Even if every turn took you only 10 seconds to play, that would still take you 52 minutes to finish the game (assuming you were just playing by yourself). Below is the route that was taken during this horribly tedious game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*TBZnAmWjCXDvexrTOOVLDg.jpeg" /><figcaption>Image provided by the author</figcaption></figure><p>As you can see, there were 9 different times when the pawn reached a space above 80, only for it to have to slide down back into the 20’s or 30&#39;s.</p><p>At this point, I started wondering if your starting spin had any affect on how many turns it would take you to win. Well it turns out, it does:</p><ul><li>Spinning a 1 on starting turn: 35.482 average turns-to-win</li><li>Spinning a 2 on starting turn: 40.508 average turns-to-win</li><li>Spinning a 3 on starting turn: 39.713 average turns-to-win</li><li>Spinning a 4 on starting turn: 37.999 average turns-to-win</li><li>Spinning a 5 on starting turn: 39.977 average turns-to-win</li><li>Spinning a 6 on starting turn: 39.857 average turns-to-win</li></ul><p>Spinning a 1 on your first turn can drastically decrease the expected number of turns to win. This is because it will send you straight to the 38th space, just as it did in the best Chutes and Ladders game mentioned previously. Spinning a 4 will give you better chances of winning, as that will send you up a ladder to space 14. Overall, a 2 is the worst value to start with because it doesn’t have a ladder connected to it, and it prevents you from reaching space 9 on the next turn (which does have a ladder).</p><p>Since your starting spin does have some affect on your expected turns-to-win, I wanted to know if your average spin value over the course of a game had any affect on your turns-to-win.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*yjQamOxx3ljviKtvIWktsw.jpeg" /><figcaption>Image provided by the author</figcaption></figure><p>It turns out that spinning lower or higher numbers on average does increase your chances of having a lower expected turns-to-win value. This doesn’t correlate 100% of the time (the best game had an average of 3.86 spin value), but it is interesting to see that simulations that had more 3’s and 4’s spun averaged longer games.</p><p>Just like I did in my <a href="https://towardsdatascience.com/simulating-monopoly-finding-the-best-properties-using-matlab-130fe557b1ae">Monopoly Simulation</a>, I wanted to find out what spaces are most likely to be occupied after each turn. Those results are shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*M7Hg4O8EUWo-Y6Nz81f5hA.jpeg" /><figcaption>Image provided by the author</figcaption></figure><p>Spaces that are empty are the start of the ladder or a chute, so they do not ever end with a pawn on it. Spaces that are abnormally high are spaces that have the end of a ladder or a chute. As you can see, there is a higher curve on the spaces 20–40, and again once you get above 75. The 99th space is extremely high, because players get stuck on this space trying to spin a 1 to get exactly 100. This results in multiple turns ending without the player moving from the 99th spot.</p><h4>Conclusions:</h4><p>Chutes and Ladders may be random, but that does not mean that there are not any patterns within the game. Spinning a 1 right away will increase your chances of winning. Averaging lower or higher spin values can help you win too. None of these can be controlled, but it is still something interesting I found within the game.</p><p>If this type of content interests you, I recommend reading my other articles on board game simulations:</p><ul><li><a href="https://towardsdatascience.com/applying-machine-learning-to-tic-tac-toe-47d954671c73">Machine Learning: Tic Tac Toe</a></li><li><a href="https://towardsdatascience.com/simulating-monopoly-finding-the-best-properties-using-matlab-130fe557b1ae">Simulating Monopoly</a></li><li><a href="https://towardsdatascience.com/i-taught-a-machine-how-to-play-connect-4-df261da4e23f">Machine Learning: Connect 4</a></li><li><a href="https://medium.com/codex/the-best-and-worst-catan-board-setups-989df4ba550a">How I Built the Best Catan Board</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40f931c18489" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/the-surprisingly-interesting-mathematics-within-chutes-and-ladders-40f931c18489">The Surprisingly Interesting Mathematics within Chutes and Ladders</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Applying Machine Learning to Tic-Tac-Toe]]></title>
            <link>https://medium.com/data-science/applying-machine-learning-to-tic-tac-toe-47d954671c73?source=rss-3d9ea428abd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/47d954671c73</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[matlab]]></category>
            <dc:creator><![CDATA[Jake Mitchell]]></dc:creator>
            <pubDate>Sat, 04 Sep 2021 14:36:24 GMT</pubDate>
            <atom:updated>2021-09-04T14:36:24.896Z</atom:updated>
            <content:encoded><![CDATA[<h4>I created a program that learns how to play tic tac toe over a period of simulations</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*F4tfEXyLjklrMkXwMNpF0g.png" /><figcaption>Image provided by the author</figcaption></figure><h4>Introduction:</h4><p>After making a MATLAB program that can play Connect 4 at a decent skill level, I decided that the next logical step was to design a program that can learn how to play Tic-tac-toe. After all, it’s just a simplified version of Connect 4, so it should take less time for the machine to learn and increase it’s winning rate.</p><h4>Tic-Tac-Toe Machine V1.0</h4><p>It starts with 2 completely random Tic-tac-toe move generators playing each other. After a game is finished, one of the machines takes all of the decision data that it collected from the game, and puts it in it’s database. If that move resulted in a win, that move gains 3 points. If the move resulted in a loss, it loses 1 point. A tie game results in plus 1 point. Over a period of 100,000 games, each unique scenario is documented in it’s database, along with the moves it chose after that. Moves with higher scores for that scenario are more likely to be picked in the next game, while moves with lower scores are more unlikely.</p><p>The idea is that over the course of several thousand games, moves that resulted in wins or ties gain more points, and are more likely to be picked. What resulted was a database of over 2,000 unique game scenarios, with different weights for each move. Below is a plot of the total amount of unique scenarios in the database over the course of the 100,000 games.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*VGOedg6rlsMdnUak5ev4YA.jpeg" /><figcaption>Image provided by the author</figcaption></figure><p>As you can see, the amount converges on the value 2,423, and at that point, the machine starts seeing reoccurring scenarios and refines the weights for each of the 9 possible moves.</p><p>But how did TTT-M1’s winning percentage look over the 100,000 games? Below on the left is the overall winning percentage for all simulations, and the right plot is a zoomed-in portion of the first few thousand games.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*SSOSKMM5nvJOCo3-x3qAFw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*F4tfEXyLjklrMkXwMNpF0g.png" /><figcaption>Images provided by the author</figcaption></figure><p>Since both TTT-M1 and it’s random move opponent both start with zero knowledge of the game, the win percentage fluctuates greatly in the first 2,000 games. As some point, it begins to settle and form a smooth line that slowly increases over time. This is because the machine has now seen all the possible scenarios, and is now refining the weights for each move.</p><p>It was at this point that I thought I had a completed project. There was no way anyone would be able to beat a machine with 100,000 games of Tic-tac-toe experience. Well, I thought wrong.</p><p>It turns out that while 100,000 games is a lot, it really means nothing when it is playing against a random move generator. A real person has intuition, which is something my machine’s opponent did not. As such, it was quite easy to beat this machine, or at least tie it. This does not mean that the machine hadn’t learned some techniques when it came to blocking it’s opponent. It was definitely making smart decisions, it just did not account for an human opponent with decent logic.</p><h4>Tic-Tac-Toe Machine V2.0</h4><p>The solution to this was rather simple. Have another machine start with no logic of the game whatsoever, and have it face my Tic-tac-toe machine version 1.0 (TTT-M1). Using the same code as before, this new machine (TTT-M2) would learn over 150,000 games how to play Tic-tac-toe, but it would learn against an opponent with a decent amount of skill. Theoretically, TTT-M2 should be smarter than TTT-M1, since it has thousands of games to expose it’s weaknesses, while still getting to develop new strategies.</p><p>One particular situation I was interested to see play out was the first move decisions. TTT-M1 got the first move, and I expected it to converge on the middle spot as being the best. It turns out, it actually liked the corners more for it’s starting spot. This left the middle open for the second player, leading to TTT-M1 losing a lot of it’s games against real people. I wanted to see if TTT-M2 would pick up on this weakness, and start targeting the middle spot if it was open for it’s turn.</p><p>Here is the learning rate for TTT-M2 against TTT-M1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*HigZrXYs69-JFLH1LW595A.jpeg" /><figcaption>Image provided by the author</figcaption></figure><p>As you can see, the win percentage started out very low since it was facing an opponent with some knowledge of the game. As the simulations went on, it learned the weaknesses of TTT-M1 until it converged to a winning rate around 0.50. This is very good considering it did not have the first move.</p><p>It had also learned that if TTT-M1 did not take the middle on the first move, then it should take it. This proves the well known fact that the middle spot is the best spot to have in Tic-tac-toe.</p><p>Now that I had a decent opponent, I developed TTT-M3.</p><h4>Tic-Tac-Toe Machine V3.0</h4><p>The final evolution of my Tic-tac-toe machine learning project is TTT-M3. This machine faced off against TTT-M2 in 150,000 games, learning the best strategies while also finding the current holes in the best database. After 150,000 games, here are the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Pd9-_Ile_v-kJYMHIeJT0A.jpeg" /><figcaption>Image provided by the author</figcaption></figure><p>This shows that the final generation of this Tic-tac-toe machine learning project started out very weak. It hovered around a 25% win rate in the first 1000 games, but then took off and reached around 74%. This is against an opponent with some Tic-tac-toe logic as well (TTT-M2). Here is an example game I played against TTT-M3 (“2” is TTT-M3’s move, and a “1” is my move):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/143/1*CtVvHUrDRvayoQNYfHaX2A.png" /><figcaption>Image provided by the author</figcaption></figure><p>I noticed right away that it had developed a strategy to lure me into picking the center spot. Once I did that, it was a tie game every time, which in the computer’s mind, is a good result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/142/1*NzC4yKF7eYg1fgoZhY2TRA.png" /><figcaption>Image provided by the author</figcaption></figure><p>I played the middle spot, falling for the trap. It then sets me up to take the top left corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/153/1*yAAuVuNRqLnX-vSO189tfw.png" /><figcaption>Image provided by the author</figcaption></figure><p>After blocking it’s horizontal attempt up top, it then sets me up again on the rightmost column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/150/1*qnHs1U13E-GuL4Nmb7-M6w.png" /><figcaption>Image provided by the author</figcaption></figure><p>It’s next move in the second row and first column sets up the tie, securing the fate of this match.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/152/1*1NUQBT6aOyfgN_4G_z25lQ.png" /><figcaption>Image provided by the author</figcaption></figure><h4>Conclusions:</h4><p>After only 3 generations of evolution for this program, it had developed a strategy to set up ties, block the opponent, and go for the win. Overall, this project was a success in that a program was created that can learn new skills and get better at Tic-tac-toe when playing against other opponents.</p><p>If this type of content interests you, I have an assortment of articles based on board games and data science:</p><ul><li><a href="https://towardsdatascience.com/simulating-monopoly-finding-the-best-properties-using-matlab-130fe557b1ae">Simulating Monopoly</a></li><li><a href="https://towardsdatascience.com/i-taught-a-machine-how-to-play-connect-4-df261da4e23f">Teaching a Machine to Play Connect 4</a></li><li><a href="https://medium.com/codex/the-best-and-worst-catan-board-setups-989df4ba550a">The Best and Worst Catan Board Setups</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47d954671c73" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/applying-machine-learning-to-tic-tac-toe-47d954671c73">Applying Machine Learning to Tic-Tac-Toe</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simulating Monopoly: Finding the Best Properties Using MATLAB]]></title>
            <link>https://medium.com/data-science/simulating-monopoly-finding-the-best-properties-using-matlab-130fe557b1ae?source=rss-3d9ea428abd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/130fe557b1ae</guid>
            <category><![CDATA[monopoly]]></category>
            <category><![CDATA[editors-pick]]></category>
            <category><![CDATA[board-games]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[matlab]]></category>
            <dc:creator><![CDATA[Jake Mitchell]]></dc:creator>
            <pubDate>Sat, 28 Aug 2021 06:42:52 GMT</pubDate>
            <atom:updated>2021-08-28T06:42:52.496Z</atom:updated>
            <content:encoded><![CDATA[<h4>I simulated 10 million Monopoly turns using MATLAB to find the best properties</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*ezATkEy46ogSQjw64AHGaA.png" /><figcaption>Image provided by the author</figcaption></figure><h4>Introduction:</h4><p>With 40 spaces, and 28 different properties, Monopoly may seem completely random at first, but there are certain properties that can be more beneficial to you over the course of a game. I wanted to find which properties these were using a MATLAB simulation of 10,000,000 dice rolls.</p><h4>How it works:</h4><p>I simulate two dice being rolled using a random number generator and then add the two values together. I then add that amount on to the current position of the player to get their new position. I also have a variable to track the amount of doubles in a row. If the player rolls 3 doubles in a row, they are sent to jail for speeding.</p><pre>die1 = randi(6); % roll first die</pre><pre>die2 = randi(6); % roll second die</pre><pre>if die1 == die2 % if same value</pre><pre>doubles = doubles + 1; % increase number of doubles in a row</pre><pre>else</pre><pre>doubles = 0; % set doubles to 0 if different dice values</pre><pre>end</pre><p>What follows in the code is all of the special case situations. For example, if the position adds up to be greater than 40, it reverts it back to the starting spot as a reference since the board is a loop. A position value of 43 would be changed to 3. Also, if the player lands on position 31 (“go to jail” space) they are sent to position 11 (jail).</p><pre>if doubles &lt; 3 % if less than 3 doubles in a row</pre><pre>position = position + die1 + die2; % finds new position</pre><pre>if position &gt; 40 % if above 40</pre><pre>position = position - 40; % reverts position back to starting position as a reference</pre><pre>around = around + 1; % indicates the player went around the board</pre><pre>end</pre><pre>if position == 31 % if player lands on the &quot;go to jail&quot; space</pre><pre>lands(position) = lands(position) + 1; % indicates player landed on position 31</pre><pre>position = 11; % sends player to jail</pre><pre>end</pre><p>Other special case examples are community chest spaces and chance spaces. Of the 16 community chest cards, only 1 changes the location of the player (go to jail). Of the 16 chance cards, 9 change the player’s location:</p><ul><li>Go to Jail</li><li>Advance to Boardwalk</li><li>Advance to Illinois Ave</li><li>Advance to St. Charles Place</li><li>Advance to Reading Railroad</li><li>Advance to Nearest Railroad</li><li>Advance to Nearest Utility</li><li>Advance to GO</li><li>Go Back 3 Spaces</li></ul><p>After every turn is over, the space that the player ended up on is tallied in an array of all 40 spots, and then each spot is divided by the total amount of simulations (10 million). This gives us a percent likelihood of all 40 spaces being landed on.</p><h4>Results:</h4><p>After 10,000,000 dice rolls, the likelihood of each space being landed on is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*NZIGeP_kdCzGMm68joCKig.png" /><figcaption>Image provided by the author</figcaption></figure><p>Shown below is the top 20 board spaces from the bar graph above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*Sa71uc3lAPpuj3ZmN25dow.png" /><figcaption>Image provided by the author</figcaption></figure><p>While the amount of times a property is landed on does affect the benefit it will bring to you as a player, we also need to consider how much it costs to buy the property, and how much players will pay you every time they land on it.</p><p>The probabilities shown above can also be described as the chances of a player landing on that property after every roll. We can use that, along with the rent for every property, to find the expected amount of money you will make on every player’s dice roll if you own said property.</p><p>For example, Ventnor Ave (shown above) is at a 2.691% chance of being landed on every roll. The rent with no houses for Ventnor Ave is $22, which means that every roll results in an expected $0.59202 for the owner.</p><p>The revenue per roll is not the best thing to compare between properties because a property that costs more than Ventnor should yield more revenue, but this is not always the case. If we divide the initial cost of buying the property by the revenue per roll, we can find how many rolls it will take to break-even on a property. For example Ventnor costs $260 to buy, so the owner should expect to make all of that money back after 439.18 rolls. Properties that take less rolls to break-even would be considered better investments because you could start turning a profit before other players.</p><p>We also need to consider how building houses and hotels on properties affects the rolls per break-even. Below is a breakdown of each property on a Monopoly board, given it’s situation regarding houses and hotels (excluding railroads and utilities). The value in each cell represents to amount of rolls it will take on average to make back the money spent on the property.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*gJ0CEEF-UcEOjaIjIryhJg.png" /><figcaption>Image provided by the author</figcaption></figure><p>As you can see, some properties are almost guaranteed to lose you money in the long run. Buying Mediterranean Ave and not putting any houses on it will certainly cost you money over the course of a game. It won’t be a significant amount (only $60 to buy), but it is still not the best purchase.</p><p>All properties without houses take an extraordinary amount of time to break-even, which is why buying houses and hotels is so important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*smghm8lQAgIcBXZkh-2mdw.png" /><figcaption>Image provided by the author</figcaption></figure><p>The plot above shows how buying at least 3 houses for every monopoly you own can greatly reduce the amount of rolls it takes to make your money back. Even the brown-colored properties (brown line above), which are a horrible investment at the start, can start to turn a profit over the span of a game with 3 or more houses on it.</p><p>Something else interesting to note is that as the properties get more expensive, the less change is seen between 3 houses, 4 houses, and a hotel. Take the light-blue and yellow properties for example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*YvAzYP94U0OGd7ca6oaJyg.png" /><figcaption>Image provided by the author (the value in each cell represents to amount of rolls it will take on average to make back the money spent on that property color)</figcaption></figure><p>Light-blue properties see a considerable drop between 3 and 4 houses, and between 4 houses and a hotel. The yellow properties show almost no change between the 3 rightmost columns. This means that it will take the same amount of time to make back the money spent on 3 houses as it does for 4, but the revenue after breaking-even will be bigger (for the more expensive properties).</p><p>But what about the railroads and utilities?</p><p>The railroads are shown below, with all the different permutations for which ones you own. The value in each cell represents to amount of rolls it will take on average to make back the money spent on the property or properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*euyZdQ_qq5SxR3W8jmZzKQ.png" /><figcaption>Image provided by the author</figcaption></figure><p>For ownership of just 1 railroad, it is best to own B&amp;O, just because it gets landed on more. If you want to own 2, go for the Reading and B&amp;O combination. For 3, look for Reading, Pennsylvania, and B&amp;O. Overall, the best investment for the railroads is either getting 3 or all 4, just because as people start to build houses on their properties, your 1 or 2 railroads won’t be making nearly as much compared to earlier in the game.</p><p>As for utilities:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*OrVtHm0dNoj8RHzCcvPsQQ.png" /><figcaption>Image provided by the author</figcaption></figure><p>Owning the utilities early in the game is probably one of the best moves. Both have the lowest rolls per break-even compared to any other property without houses. However, just like the railroads, you can’t build houses on these, so as the game goes on, these become less and less useful. Even owning both utilities still puts them at the bottom, considering 21 of the 22 other properties have lower rolls per break-even with 3 houses.</p><h4>Conclusions:</h4><p>The orange properties are the best spots in the game. The oranges are all within the best 5 properties with 3 houses, and are the top 3 locations for hotels. The orange properties New York Ave and Tennessee Ave place 3rd and 5th amongst the spots most landed on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*J5PEfME5pTwMFvQ0pPT6XQ.png" /><figcaption>Image provided by the author</figcaption></figure><p>Boardwalk and Park Place (dark blues) are tricky ones. Boardwalk consistently places high on the list in terms of rolls per break-even, while Park Place is always near the bottom. This monopoly is a high-risk, high-reward option compared to the oranges.</p><p>The absolute worst group to put hotels on are definitely the greens. All 3 place in the bottom 5 in terms of rolls per break-even with hotels. They are also below-average in terms of likelihood of being landed on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*pUcqQrFr-7cD_2hrubZf6A.png" /><figcaption>Image provided by the author</figcaption></figure><p>Railroads are only beneficial near the end of the game if you have 3 or all 4. If you can get them early and start breaking-even, then that is a great move. Utilities are the best properties until people start building houses. You can’t win with just utilities or railroads, so do not put all of your effort and money into them.</p><p>Overall, this simulation showed that there is some strategy that can be implemented into your next Monopoly game. If this type of content interests you, I recommend reading my other board game articles, <a href="https://towardsdatascience.com/i-taught-a-machine-how-to-play-connect-4-df261da4e23f">I Taught a Machine How to Play Connect 4</a>, and <a href="https://medium.com/codex/the-best-and-worst-catan-board-setups-989df4ba550a">The Best and Worst Catan Board Setups</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=130fe557b1ae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/simulating-monopoly-finding-the-best-properties-using-matlab-130fe557b1ae">Simulating Monopoly: Finding the Best Properties Using MATLAB</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>