using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace DoorsGame { public partial class Form1 : Form { private int no_switch = 0; private int did_switch = 0; private int total_trials = 0; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { total_trials++; Random r = new Random(); int door_chosen = r.Next(0, 3); int correct_door = r.Next(0, 3); if (correct_door == door_chosen) { no_switch++; listBox1.Items.Add("Win"); listBox2.Items.Add("Loss"); } else { listBox1.Items.Add("Loss"); int door_to_kill = r.Next(0, 3); while (door_to_kill != correct_door && door_to_kill != door_chosen) { door_to_kill = r.Next(0, 3); } if (door_to_kill != 2) { door_chosen++; } else { door_chosen = 0; } if (door_chosen == correct_door) { did_switch++; listBox2.Items.Add("Win"); } else { listBox2.Items.Add("Lose"); } } lpDNS.Text = ((int)((no_switch * 100) / total_trials)).ToString() + "%"; lpDS.Text = ((int)((did_switch * 100) / total_trials)).ToString() + "%"; } private void button2_Click(object sender, EventArgs e) { for (int i = 0; i < 1000; i++) button1_Click(sender, e); } } }