public CooperativeGameForm(TestForm parent, string Coalition)
 {
     InitializeComponent();
     G              = Database.G.FindGame(Coalition);
     this.parent    = parent;
     this.Coalition = Coalition;
     UI_FirstSetup();
     CGStudentProgress.CurrentSection = 2;
 }
        private bool CheckEconStability()
        {
            double max = 0;

            for (int i = 0; i < CB.Count; i++)
            {
                max = Math.Max(max, (CB[i].Tag as BimatrixGame).outcome);
            }
            for (int i = 0; i < CB.Count; i++)
            {
                if (((CB[i].Checked) && ((CB[i].Tag as BimatrixGame).outcome != max)) ||
                    ((!CB[i].Checked) && ((CB[i].Tag as BimatrixGame).outcome == max)))
                {
                    CGStudentProgress.GenerateError("Ошибка при определении экономической устойчивости коалиции", null);
                    return(false);
                }
            }

            for (int i = 0; i < CB.Count; i++)
            {
                if (CB[i].Checked)
                {
                    G = (CB[i].Tag as BimatrixGame);
                    CB[i].Hide();
                }
                else
                {
                    CB[i].Parent.Dispose();
                }
            }

            for (int i = 0; i < CB.Count; i++)
            {
                CB[i].Dispose();
            }


            return(true);
        }
        public bool CheckDivisionAndSufficiency(string Coalition, bool Sufficient, bool DivisionRational)
        {
            List <List <int> > C = new List <List <int> >();

            for (int i = 0; i < Coalition.Length; i++)
            {
                if (Coalition[i] == '{')
                {
                    C.Add(new List <int>());
                }
                if ((Coalition[i] >= '0') && (Coalition[i] <= '9'))
                {
                    C.Last().Add(Convert.ToInt32(Coalition[i] - '0'));
                }
            }
            BimatrixGame G = Database.G.FindGame(Coalition);

            if (((Database.G.outcome > G.SingleGames[0].Ha + G.SingleGames[0].Hb) && (Sufficient)) ||
                ((Database.G.outcome < G.SingleGames[0].Ha + G.SingleGames[0].Hb) && (!Sufficient)))
            {
                CGStudentProgress.GenerateError("Ошибка при определении существенности", null);
                return(false);
            }

            bool Rational = true;

            for (int i = 0; i < PayoffDistributionTB.Count; i++)
            {
                double value = CGStudentProgress.ReadValue(PayoffDistributionTB[i].Text);
                if (value == -1)
                {
                    return(false);
                }

                double ActualValue;
                if (CGStudentProgress.DistributionType == 1)
                {
                    double IncooperativePrize      = Database.G.payoffs[i],
                           CoalitionPrize          = 0,
                           CoalitionPlayersPayoffs = 0;
                    int CoalitionIndex             = -1;
                    for (int p = 0; p < C.Count; p++)
                    {
                        for (int q = 0; q < C[p].Count; q++)
                        {
                            if (C[p][q] - 1 == i)
                            {
                                CoalitionIndex = p;
                            }
                        }
                    }
                    CoalitionPrize = G.payoffs[CoalitionIndex];
                    for (int j = 0; j < C[CoalitionIndex].Count; j++)
                    {
                        CoalitionPlayersPayoffs += Database.G.payoffs[C[CoalitionIndex][j] - 1];
                    }
                    ActualValue = IncooperativePrize * CoalitionPrize / CoalitionPlayersPayoffs;
                }
                else
                {
                    throw new NotImplementedException();
                }

                if ((value > 1.1 * ActualValue) || (value < 0.9 * ActualValue))
                {
                    CGStudentProgress.GenerateError("Ошибка при подсчете выражения для " + (i + 1) + " игрока.", null);
                    return(false);
                }
                if (ActualValue < Database.G.payoffs[i])
                {
                    Rational = false;
                }
            }

            if (((DivisionRational) && (!Rational)) || ((!DivisionRational) && (Rational)))
            {
                CGStudentProgress.GenerateError("Ошибка при определении рациональности дележа", null);
                return(false);
            }

            return(true);
        }
        public ViewCooperativeGameForm(TestForm parent, string Coalition)
        {
            InitializeComponent();
            G              = Database.G.FindGame(Coalition);
            this.parent    = parent;
            this.Coalition = Coalition;
            if (CGStudentProgress.CurrentSection == 6)
            {
                CreateArrays(0, 1);
                UI.ControlsAligner mpanel = new UI.ControlsAligner(MatrixesPanel);
                mpanel.AddElement(A);
                mpanel.AddElement(B, false);
                mpanel.Align();

                RP_v1.Text         += G.SingleGames[0].FirstPlayer + " = " + G.SingleGames[0].Ha.ToString("0.00");
                RP_v2.Text         += G.SingleGames[0].SecondPlayer + " = " + G.SingleGames[0].Hb.ToString("0.00");;
                RP_PriceLabel.Text += (G.SingleGames[0].Ha + G.SingleGames[0].Hb).ToString("0.00");
                for (int i = 0; i < G.SingleGames[0].x.Count; i++)
                {
                    RP_x.Text += G.SingleGames[0].x[i].ToString("0.00") + " ";
                }
                RP_x.Text += ")";

                for (int i = 0; i < G.SingleGames[0].y.Count; i++)
                {
                    RP_y.Text += G.SingleGames[0].y[i].ToString("0.00") + " ";
                }
                RP_y.Text += ")";


                UI.ControlsAligner rpanel = new UI.ControlsAligner(GameResultPanel);
                rpanel.AddElement(RP_PriceLabel);
                rpanel.AddElement(RP_v1);
                rpanel.AddElement(RP_v2, false);
                rpanel.AddElement(RP_x);
                rpanel.AddElement(RP_y);
                rpanel.Align();
                SkipBTN.Text    = "Несущественная";
                SkipBTN.Width   = 200;
                FinishBTN.Text  = "Существенная";
                FinishBTN.Width = SkipBTN.Width;
                GameResultPanel.Show();

                UI.ControlsAligner form = new UI.ControlsAligner(this);
                Task1Panel.Hide();
                form.AddElement(NavigationPanel);
                form.AddElement(MatrixesPanel);
                form.AddElement(GameResultPanel);
                form.AddElement(SkipBTN, true, "Left");
                form.AddElement(FinishBTN, false, "Right");
                form.Align();
                CreateNavigationPanel();
            }
            else
            {
                this.ControlBox = false;
                SecondInterfaceSetup_Domination();
                CGStudentProgress.NewSection();
                A.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(ColumnHeadersMouseClick);
                A.RowHeaderMouseClick    += new DataGridViewCellMouseEventHandler(RowHeaderMouseClick);
                B.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(ColumnHeadersMouseClick);
                B.RowHeaderMouseClick    += new DataGridViewCellMouseEventHandler(RowHeaderMouseClick);
            }
        }
        private void GenerateCoalitionPanel(string Coalition, bool first)
        {
            BimatrixGame G = Database.G.FindGame(Coalition);

            Panel p = new Panel();

            PanelsPanel.Controls.Add(p);
            p.BackColor = Color.Silver;

            Label name = new Label();

            name.Text      = Coalition;
            name.Font      = new System.Drawing.Font("Bookman Old Style", 16);
            name.Width     = TextRenderer.MeasureText(name.Text, name.Font).Width;
            name.Height   += 5;
            name.BackColor = Color.Maroon;
            name.ForeColor = Color.White;

            Label outcome = new Label();

            outcome.Text = "V = " + G.outcome.ToString("0.00");
            outcome.Font = new Font(name.Font.Name, name.Font.Size - 2);
            outcome.Size = TextRenderer.MeasureText(outcome.Text, outcome.Font);

            Label v1 = new Label();

            v1.Text = "V" + G.SingleGames[0].FirstPlayer + " = " + G.SingleGames[0].Ha.ToString("0.00");
            v1.Font = new Font(name.Font.Name, name.Font.Size - 4);
            v1.Size = TextRenderer.MeasureText(v1.Text, v1.Font);

            Label v2 = new Label();

            v2.Text = "V" + G.SingleGames[0].SecondPlayer + " = " + G.SingleGames[0].Hb.ToString("0.00");
            v2.Font = new Font(name.Font.Name, name.Font.Size - 4);
            v2.Size = TextRenderer.MeasureText(v2.Text, v2.Font);

            CheckBox c = new CheckBox();

            c.Text    = "Экономически устойчивая";
            c.Font    = new System.Drawing.Font("Bookman Old Style", 12);
            c.Size    = TextRenderer.MeasureText(c.Text, c.Font);
            c.Tag     = G;
            c.Width  += 20;
            c.Height += 10;
            CB.Add(c);


            p.Controls.Add(name);
            p.Controls.Add(outcome);
            p.Controls.Add(v1);
            p.Controls.Add(v2);
            p.Controls.Add(c);

            UI.ControlsAligner panel = new UI.ControlsAligner(p);
            panel.AddElement(name);
            panel.AddElement(outcome);
            panel.AddElement(v1);
            panel.AddElement(v2, false);
            panel.AddElement(c);
            panel.Align();
            pp.AddElement(p, first);
        }