예제 #1
0
        private void buttonSimulate_Click(object sender, EventArgs e)
        {
            int               height            = (int)numericUpDownHeight.Value;
            int               width             = (int)numericUpDownWidth.Value;
            int               numberOfRounds    = (int)numericUpDownRounds.Value;
            bool              modelInTime       = radioButtonTemporal.Checked;
            GameSymmetric     game              = radioButtonPrisonersDilemma.Checked ? new TrpsGame(10, 7, 0, 0) : new TrpsGame(10, 7, 0, 3);
            NeighbourhoodType neighbourhoodType = radioButtonMoore.Checked ? NeighbourhoodType.Moore : NeighbourhoodType.VonNeumann;
            Reselector        reselector;

            if (radioButtonMax.Checked)
            {
                reselector = Reselector.Max;
            }
            else if (radioButtonReplicator.Checked)
            {
                if (neighbourhoodType == NeighbourhoodType.Moore)
                {
                    reselector = Reselector.Replicator8;
                }
                else
                {
                    reselector = Reselector.Replicator4;
                }
            }
            else
            {
                reselector = Reselector.Custom;
            }

            Lattice lattice = new Lattice(height, width, neighbourhoodType, game, reselector);

            using (Graphics graphics = picture.CreateGraphics())
            {
                this.clear(graphics);

                if (modelInTime)
                {
                    drawLattice(lattice, graphics);

                    for (int n = 0; n < numberOfRounds; n++)
                    {
                        Thread.Sleep(500);

                        lattice.NextRound();

                        drawLattice(lattice, graphics);
                    }
                }
                else
                {
                    lattice.PlayRounds(numberOfRounds);

                    drawLattice(lattice, graphics);
                }
            }
        }
예제 #2
0
        protected void simulateMultiple()
        {
            experimentNumber = (int)numericUpDownSimulations.Value;
            roundNumber      = (int)numericUpDownRounds.Value;
            int               height            = (int)numericUpDownHeight.Value;
            int               width             = (int)numericUpDownWidth.Value;
            GameSymmetric     game              = radioButtonPrisonersDilemma.Checked ? new TrpsGame(10, 7, 0, 0) : new TrpsGame(10, 7, 0, 3);
            NeighbourhoodType neighbourhoodType = radioButtonMoore.Checked ? NeighbourhoodType.Moore : NeighbourhoodType.VonNeumann;
            Reselector        reselector;

            if (radioButtonMax.Checked)
            {
                reselector = Reselector.Max;
            }
            else if (radioButtonReplicator.Checked)
            {
                if (neighbourhoodType == NeighbourhoodType.Moore)
                {
                    reselector = Reselector.Replicator8;
                }
                else
                {
                    reselector = Reselector.Replicator4;
                }
            }
            else
            {
                reselector = Reselector.Custom;
            }

            fraction = new List <double> [roundNumber + 1];

            for (int round = 0; round < roundNumber + 1; round++)
            {
                fraction[round] = new List <double>();
            }

            for (int experiment = 0; experiment < experimentNumber; experiment++)
            {
                Lattice lattice = new Lattice(height, width, neighbourhoodType, game, reselector);

                fraction[0].Add(lattice.RatioActionOne);

                for (int round = 1; round < roundNumber + 1; round++)
                {
                    lattice.NextRound();
                    fraction[round].Add(lattice.RatioActionOne);
                }
            }
        }