Esempio n. 1
0
        int IComparable.CompareTo(object obj)
        {
            PlacePoint temp = (PlacePoint)obj;

            if (this.Rate > temp.Rate)
            {
                return(1);
            }
            if (this.Rate < temp.Rate)
            {
                return(-1);
            }
            else
            {
                return(0);
            }
        }
Esempio n. 2
0
        public static Gamefield NextStep(Gamefield fld)
        {
            bool Winplayer = false;
            bool WinAuto   = false;

            // PlacePoint[] PlPoint = new PlacePoint[9];
            double[,] PlPoint = new double[3, 3];
            for (int i = 0; i <= 2; i++)
            {
                for (int j = 0; j <= 2; j++)
                {
                    PlPoint[i, j] = 0;
                }
            }

            //столбцы

            int CX = 0;

            for (int i = 0; i <= 2; i++)
            {
                int    cnt0 = 0;
                int    cntx = 0;
                double rat  = 0;
                int    X    = 0;
                for (int j = 0; j <= 2; j++)
                {
                    if (fld.field[i, j] == 1)
                    {
                        cnt0 = cnt0 + 1;
                    }

                    if (fld.field[i, j] == 2)
                    {
                        cntx = cntx + 1;
                        X    = j;
                        CX   = CX + 1;
                    }
                }

                rat = cntx + cnt0;
                if (cntx == 2)
                {
                    rat = 2 + 3;
                }
                if (cnt0 == 2)
                {
                    rat = 2 + 6;
                    if (cntx == 0)
                    {
                        WinAuto = true;
                    }
                }
                if (cnt0 == 1 && cntx == 1)
                {
                    rat = 0;
                }
                if (cnt0 == 1 && cntx == 1)
                {
                    rat = 0;
                }

                if (cntx == 3)
                {
                    Winplayer = true;
                }

                for (int j = 0; j <= 2; j++)
                {
                    if (fld.field[i, j] == 0)
                    {
                        PlPoint[i, j] = PlPoint[i, j] + rat;
                        if (Math.Abs(X - j) == 1 && CX > 1 && fld.diffic == 2)
                        {
                            PlPoint[i, j] = PlPoint[i, j] + 1.5;
                        }
                    }
                }
            }


            //строки

            for (int j = 0; j <= 2; j++)
            {
                int    cnt0 = 0;
                int    cntx = 0;
                double rat  = 0;
                int    Y    = 0;
                for (int i = 0; i <= 2; i++)
                {
                    if (fld.field[i, j] == 1)
                    {
                        cnt0 = cnt0 + 1;
                    }

                    if (fld.field[i, j] == 2)
                    {
                        cntx = cntx + 1;
                        Y    = i;
                    }
                }

                rat = cntx + cnt0;
                if (cntx == 2)
                {
                    rat = 2 + 3;
                }
                if (cnt0 == 2)
                {
                    rat = 2 + 6;
                    if (cntx == 0)
                    {
                        WinAuto = true;
                    }
                }
                if (cnt0 == 1 && cntx == 1)
                {
                    rat = 0;
                }
                if (cntx == 3)
                {
                    Winplayer = true;
                }

                for (int i = 0; i <= 2; i++)
                {
                    if (fld.field[i, j] == 0)
                    {
                        PlPoint[i, j] = PlPoint[i, j] + rat;
                        if (Math.Abs(Y - i) == 1 && CX > 1 && fld.diffic == 2)
                        {
                            PlPoint[i, j] = PlPoint[i, j] + 1.5;
                        }
                    }
                }
            }


            //диагон
            int    cnt0d = 0;
            int    cntxd = 0;
            double ratd  = 0;

            for (int j = 0; j <= 2; j++)
            {
                int i = j;

                if (fld.field[i, j] == 1)
                {
                    cnt0d = cnt0d + 1;
                }

                if (fld.field[i, j] == 2)
                {
                    cntxd = cntxd + 1;
                }
            }
            ratd = cntxd + cnt0d;
            if (cntxd == 2)
            {
                ratd = 2 + 6;
            }
            if (cnt0d == 2)
            {
                ratd = 2 + 1;
                if (cntxd == 0)
                {
                    WinAuto = true;
                }
            }


            if (cntxd == 1)
            {
                ratd = 2;
            }
            if (cntxd == 3)
            {
                Winplayer = true;
            }



            // }
            for (int j = 0; j <= 2; j++)
            {
                int i = j;
                if (fld.field[i, j] == 0)
                {
                    PlPoint[i, j] = PlPoint[i, j] + ratd;
                }
            }



            //diag2
            cnt0d = 0;
            cntxd = 0;
            ratd  = 0;
            for (int j = 2; j >= 0; j--)
            {
                int i = 2 - j;

                if (fld.field[i, j] == 1)
                {
                    cnt0d = cnt0d + 1;
                }

                if (fld.field[i, j] == 2)
                {
                    cntxd = cntxd + 1;
                }
            }
            ratd = cntxd + cnt0d;
            if (cntxd == 2)
            {
                ratd = 2 + 6;
            }
            if (cnt0d == 2)
            {
                ratd = 2 + 1;
                if (cntxd == 0)
                {
                    WinAuto = true;
                }
            }
            if (cnt0d == 1 && cntxd == 1)
            {
                ratd = 0;
            }

            if (cntxd == 1)
            {
                ratd = 2;
            }

            if (cntxd == 3)
            {
                Winplayer = true;
            }


            //  }

            if (WinAuto)
            {
                fld.Winner = 1;// "Вы проиграли! Деньги на бочку!";
            }
            if (Winplayer)
            {
                fld.Winner = 2;// "Вы выиграли, поздравляю!";
            }
            if (Winplayer)
            {
                return(fld);
            }

            for (int j = 2; j >= 0; j--)
            {
                int i = 2 - j;
                if (fld.field[i, j] == 0)
                {
                    PlPoint[i, j] = PlPoint[i, j] + ratd;
                }
            }



            PlacePoint Point = AutoGamer.FindPoint(PlPoint);

            if (Point.Rate > 0)
            {
                fld.field[Point.Numstr, Point.Numcol] = 1;
            }
            return(fld);
        }