ENGINEERING

Home Engineering
  • Engineering
  • Senior Project
  • Projects
  • 3 Doors Game Simulation
  • Woodworking: Bedstand
  • Woodworking: Desk
  • Numbers Game
  • Path Planning
  • Snake Video Game AI
  • Minimum Spanning Tree
  • Heat Map
  • MATLAB: Rocket Simulation
  • MATLAB: Bike Suspension
  • MATLAB: Thermal FEA SS
  • MATLAB: Thermal FEA Tr
  • Notes
  • Statistics
  • Steoscopic Estimates
  • Cubed Roots
  • Other
  • Free Fall Distance
  • Speed of Sound
  • Travel
  • Solar System Scale
  • Videos
  • Yellowstone Geysers
  • Geysers and Waterfalls
  • Yellowstone and Glacier
  • Grinnell Glacier
  • Yellowstone Geysers
  • Photography

    Subjects

    Three Doors Game Show Simulation



    There is a game show where a contestant attempts to pick the correct one of three doors. Two of the doors hide goats and one of the doors hides a car behind it. The player attempts to pick the door with the car behind it to win. After choosing a door the game host then opens one of the other doors to reveal a goat and offers to let the player switch doors.


    If the player does not switch doors then his odds of winning are 33%. If the player switches doors then the player increases his odds of winning to 66%. The MATLAB simulation below demonstrates this statistical advantage over 1000 rounds of the game.

    The following cases will always prove true:

    MATLAB Source Code:


    % Program:
    % Three_Doors_Game_Show_Simulation.m
    % Three doors game show stastical simulation.
    % 
    % Simulates a game show where the contestant attempts to pick the correct 
    % one of three doors. The program shows the statistical odds of winning 
    % based on two strategies. The first strategy is to not switch doors when
    % given the opportunity. The second strategy is to always switch doors when
    % given the opportunity.
    %
    % Variable List:
    % Always_Switch_Doors = Strategy switch
    % Iterations = Number of times to simulate
    % Run = Current run number
    % Door_Setup = Number to determine door setup
    % Door = Current door setup
    % Door_Chosen = Door chosen by contestant
    % Door_Removed = Door removed by host
    % Wins = Total number of wins
    % Losses = Total number of losses
    % Percent = Percentage of games won
    % n = Counter
    
    clear, clc                              % Clear command window and workspace
    
    Always_Switch_Doors = 1;                % Always switch doors?
    Iterations = 1000;                      % Number of iterations
    Wins = 0;                               % Initialize wins
    
    for Run = 1:Iterations                  % Iterations to run
        fprintf('Run = %i \n', Run);
        Door_Setup = randi([1,3]);          % Generate random door scenario
        switch Door_Setup
            case 1                          % Scenario 1
                Door = {'Car';
                        'Goat';
                        'Goat'};
            case 2                          % Scenario 2
                Door = {'Goat'; 
                        'Car';
                        'Goat'};
            case 3                          % Scenario 3
                Door = {'Goat';
                        'Goat'; 
                        'Car'};
        end
        fprintf('Doors = %s %s %s \n', Door{1}, Door{2}, Door{3});
    
        Door_Chosen = randi([1,3]);             % Generate random door number
        fprintf('Door_Chosen = %i \n', Door_Chosen);
    
        while 1;
            Door_Removed = randi([1,3]);        % Choose random door to remove
            if strcmp(Door(Door_Removed), 'Goat') && Door_Removed ~= Door_Chosen;
                break                           % Remove a door with a goat
            end
        end
        fprintf('Door_Removed = %i \n', Door_Removed);
    
        switch Always_Switch_Doors              % Switch doors if switch is on
           case 0                               % Do not switch doors         
              fprintf('Not Switching Doors \n');
              fprintf('Door_Chosen = %i \n', Door_Chosen);
           case 1                               % Switch doors
               for n = 1:3
                   if n ~= Door_Chosen && n ~= Door_Removed;
                       Door_Chosen = n;         % Final door selected
                       fprintf('Switching Doors \n');
                       fprintf('Door_Chosen = %i \n', Door_Chosen);
                       break
                   end
               end
        end
        
        if strcmp(Door(Door_Chosen), 'Car');    % Winner if car door is chosen
            fprintf('Win \n \n');
            Wins = Wins + 1;                    % Increment win counter
        else
            fprintf('Lose \n \n');
        end   
    end
     
    Losses = Iterations - Wins;                 % Record simulation statistics
    Percent = Wins/Iterations*100;              % Percentage of games won
    fprintf(['Always Switch = %1.1i, Wins = %1.1i, Losses = %1.1i,' ...
        'Percentage = %1.1f \n'], Always_Switch_Doors, Wins, Losses, Percent);