Ejemplo n.º 1
0
        private async void Simulate(Prisoner prisoner1, Prisoner prisoner2, int iterations, bool slowMode)
        {
            await Task.Run(() =>
            {
                for (int i = 0; i < iterations; i++)
                {
                    if (_shouldEnd)
                    {
                        break;
                    }

                    var prisoner1Choice = _prisoner1.TakeAction();
                    var prisoner2Choice = _prisoner2.TakeAction();
                    _prisoner1.ProcessOpponentAction(prisoner2Choice);
                    _prisoner2.ProcessOpponentAction(prisoner1Choice);

                    CalculateScore(prisoner1Choice, prisoner2Choice);

                    Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                           (ThreadStart) delegate()
                    {
                        string p1 = prisoner1Choice ? "Współpracuje" : "Zdradził";
                        string p2 = prisoner2Choice ? "Współpracuje" : "Zdradził";
                        UpdateGUI($"W1: {p1}, W2: {p2}");
                    });
                    if (slowMode)
                    {
                        Thread.Sleep(100);
                    }
                }
            });
        }
Ejemplo n.º 2
0
        private void SelectStrategy(ComboBox comboBox, Prisoner prisoner)
        {
            switch (comboBox.Text)
            {
            case "Wet za wet":
            {
                prisoner.SetStrategy(new TitForTat());
                break;
            }

            case "Wet za dwa wet":
            {
                prisoner.SetStrategy(new TitFor2Tat());
                break;
            }

            case "Wet za dwa wet z 10% prawdopodobieństwem na zdradę":
            {
                prisoner.SetStrategy(new TitForTatWithProbability(BETRAYAL, 0.1));
                break;
            }

            case "Wet za dwa wet z 10% prawdopodobieństwem na współpracę":
            {
                prisoner.SetStrategy(new TitForTatWithProbability(COOPERATION, 0.1));
                break;
            }

            case "Nie zatapiaj łodzi":
            {
                prisoner.SetStrategy(new DontSkinTheBoat());
                break;
            }

            case "Zapominaj":
            {
                prisoner.SetStrategy(new CooperateStrategy());
                break;
            }

            case "Trzymaj się rozwiązania rutynowego":
            {
                prisoner.SetStrategy(new RutineStrategy());
                break;
            }

            case "Zawsze zdradzaj":
            {
                prisoner.SetStrategy(new AlwaysBetrayStrategy());
                break;
            }

            case "Zawsze współpracuj":
            {
                prisoner.SetStrategy(new AlwaysCooperateStrategy());
                break;
            }

            case "Losowo":
            {
                prisoner.SetStrategy(new RandomStrategy());
                break;
            }
            }
        }
Ejemplo n.º 3
0
 public MainWindow()
 {
     InitializeComponent();
     _prisoner1 = new Prisoner(new TitForTat());
     _prisoner2 = new Prisoner(new TitForTat());
 }