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); } } }
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); } } }
public Lattice(int height, int width, NeighbourhoodType neighbourhoodType, GameSymmetric game, Reselector reselector) { this.Height = height; this.Width = width; switch (neighbourhoodType) { case NeighbourhoodType.Moore: this.NeighbourDeterminer = new NeighbourDeterminerMoore(this); break; case NeighbourhoodType.VonNeumann: this.NeighbourDeterminer = new NeighbourDeterminerVonNeumann(this); break; } this.Game = game; switch (reselector) { case Reselector.Max: ActionReselector = new ActionReselectorMax(); break; case Reselector.Replicator4: ActionReselector = new ActionReselectorReplicator(Game.maxPayoff, Game.minPayoff, 4.0); break; case Reselector.Replicator8: ActionReselector = new ActionReselectorReplicator(Game.maxPayoff, Game.minPayoff, 8.0); break; case Reselector.Custom: ActionReselector = new ActionReselectorCustom(); break; } player = new Player[height, width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { this.player[i, j] = new Player(); } } recalculateRatios(); }