Пример #1
0
 public IPDGame(int numberOfGames, IPDPlayer a, IPDPlayer b)
 {
     _a        = new PlayerCard(a, numberOfGames);
     _b        = new PlayerCard(b, numberOfGames);
     Length    = numberOfGames;
     HasRandom = false;
 }
Пример #2
0
 public double[] GetPasts(IPDPlayer ab)
 {
     if (ab != _a.Player && ab != _b.Player)
     {
         return(new double[4]);
     }
     return((ab == _a.Player) ? _a.PastCounter : _b.PastCounter);
 }
Пример #3
0
 public double[] GetChoices(IPDPlayer ab)
 {
     if (ab != _a.Player && ab != _b.Player)
     {
         return(new double[2]);
     }
     return((ab == _a.Player) ? _a.ChoiceCounter : _b.ChoiceCounter);
 }
Пример #4
0
 public double GetScore(IPDPlayer ab)
 {
     if (ab != _a.Player && ab != _b.Player)
     {
         return(0);
     }
     return((ab == _a.Player) ? _a.Score : _b.Score);
 }
Пример #5
0
 public PlayerCard(IPDPlayer player, int numberofGames)
 {
     Player        = player;
     _history      = new Past[numberofGames];
     Score         = 0;
     _t            = 0;
     ChoiceCounter = new double[2];
     PastCounter   = new double[4];
 }
Пример #6
0
        public Past GetPast(IPDPlayer ab, int time)
        {
            if (time < 0 || (ab != A && ab != B))
            {
                return(Past.None);
            }

            int t = (time > T) ? T : time;

            return((ab == A) ? _a[t] : _b[t]);
        }
Пример #7
0
        private IPDPlayer[] CreatePool(int seed, int randoms, params Opponent[] opponents)
        {
            Players.IPDPlayerFactory pf = new Players.IPDPlayerFactory(seed);
            var pool = new IPDPlayer[randoms + opponents.Length];

            for (int i = 0; i < randoms; i++)
            {
                pool[i] = pf.Random();
            }
            for (int i = randoms, j = 0; i < pool.Length; i++, j++)
            {
                pool[i] = Players.IPDPlayerFactory.Create(opponents[j]);
            }
            return(pool);
        }
Пример #8
0
        public Choices GetChoice(IPDPlayer ab, int time)
        {
            if (time < 0 || (ab != A && ab != B))
            {
                return(Choices.R);
            }

            switch (GetPast(ab, time))
            {
            case Past.R:
            case Past.S:
                return(Choices.C);

            case Past.P:
            case Past.T:
                return(Choices.D);

            default:
                return(Choices.R);
            }
        }
Пример #9
0
        private void ShowHistory(IPDGame game)
        {
            IPDPlayer[] players = new IPDPlayer[2] {
                game.A, game.B
            };

            int  formWidth = 320;
            Form history   = new Form();

            history.Text            = game.ToString();
            history.Size            = new Size(formWidth, 500);
            history.FormBorderStyle = FormBorderStyle.Sizable;
            history.MinimumSize     = new Size(formWidth, 300);
            history.MaximumSize     = new Size(formWidth, 5000);
            history.MaximizeBox     = false;
            history.MinimizeBox     = false;

            DataGridView table = new DataGridView();

            table.Location           = new Point(0, 0);
            table.Dock               = DockStyle.Fill;
            table.AllowUserToAddRows = false;
            table.RowHeadersWidth    = 50;
            table.EditMode           = DataGridViewEditMode.EditProgrammatically;

            DataGridViewColumn[] cols       = new DataGridViewColumn[4];
            string[]             colHeaders = new string[4] {
                players[0].Name, players[1].Name, "Result", "Score"
            };
            for (int i = 0; i < cols.Length; i++)
            {
                cols[i]            = new DataGridViewTextBoxColumn();
                cols[i].HeaderText = colHeaders[i];
                cols[i].SortMode   = DataGridViewColumnSortMode.NotSortable;
                cols[i].Width      = 60;
            }
            table.Columns.AddRange(cols);

            table.Rows.Add(game.Length + 1);
            int a = 0, b = 0;

            for (int i = 0; i < game.Length; i++)
            {
                table.Rows[i].HeaderCell.Value = i.ToString();
                table.Rows[i].Cells[0].Value   = game.GetChoice(players[0], i);
                table.Rows[i].Cells[1].Value   = game.GetChoice(players[1], i);
                table.Rows[i].Cells[2].Value   = game.GetPast(players[0], i) + ", " + game.GetPast(players[1], i);
                a += IPDGame.PastToScore(game.GetPast(players[0], i)); b += IPDGame.PastToScore(game.GetPast(players[1], i));
                table.Rows[i].Cells[3].Value = a + ", " + b;
            }

            DataGridViewRow total = new DataGridViewRow();

            table.Rows.Add();
            table.Rows[game.Length].HeaderCell.Value = "T";
            table.Rows[game.Length].Cells[0].Value   = game.GetScore(players[0]).ToString("F0");
            table.Rows[game.Length].Cells[1].Value   = game.GetScore(players[1]).ToString("F0");

            history.Controls.Add(table);
            history.Show();
        }