Пример #1
0
        public MainWindow()
        {
            InitializeComponent();

            Pole = new TPole(gPole);
            Rand = new TRand(64);
        }
Пример #2
0
        public TRuns GetRuns(TPole Pole)
        {
            this.Pole = Pole;

            TRuns Res = new TRuns();

            if (Dama)
            {
                AddRunDama(Res, 1);

                AddRunDama(Res, 2);

                AddRunDama(Res, 3);

                AddRunDama(Res, 4);
            }
            else
            {
                if (C == WB.W)
                {
                    AddRun(Res, 1);

                    AddRun(Res, 2);
                }
                else
                {
                    AddRun(Res, 3);

                    AddRun(Res, 4);
                }
            }


            return(Res);
        }
Пример #3
0
        void RunChecks(TChecks C)
        {
            TRuns Runs;
            TRuns RunsKill;

            Rand.Clear();

            for (int n = 0; n < C.Count; n++)
            {
                RunsKill = C[n].GetRunsKill(Pole);

                if (RunsKill.Count > 0)
                {
                    Rand.Add(n);
                }
            }

            if (Rand.Count > 0)
            {
                C[Rand.Get].Run(Pole, null);
                return;
            }

            Rand.Clear();

            for (int n = 0; n < C.Count; n++)
            {
                Runs = C[n].GetRuns(Pole);

                if (Runs.Count > 0)
                {
                    Rand.Add(n);
                }
            }

            if (Rand.Count > 0)
            {
                C[Rand.Get].Run(Pole, null);
            }
            else
            {
                IsGame = false;

                WB Cx;

                if (IsW)
                {
                    Cx = WB.W;
                }
                else
                {
                    Cx = WB.B;
                }

                Pole.GameOver(Cx);

                Pole = new TPole(gPole);
            }
        }
Пример #4
0
        public TTree(TNode Root, TPole Pole)
        {
            this.Root = Root;
            this.Pole = Pole;

            Lists = new ArrayList(12);

            Count = 0;
        }
Пример #5
0
        public bool Run(TPole Pole, TRun R)
        {
            TRuns RunsKill = GetRunsKill(Pole);

            if (RunsKill.Count > 0)
            {
                TRun Run;
                if (R == null)
                {
                    Run = RunsKill.GetR();
                }
                else
                {
                    Run = R;
                }

                SetPos(Run.PosTo);

                for (int i = 0; i < Run.Killed.Count; i++)
                {
                    TCheck K = (TCheck)Run.Killed[i];
                    g.Children.Remove(K.O[0]);
                    g.Children.Remove(K.O[1]);
                    if (K.C == WB.W)
                    {
                        Pole.CW.Remove(K);
                    }
                    else
                    {
                        Pole.CB.Remove(K);
                    }
                }

                return(true);
            }

            TRuns Runs = GetRuns(Pole);

            if (Runs.Count > 0)
            {
                TRun Run;
                if (R == null)
                {
                    Run = Runs.GetR();
                }
                else
                {
                    Run = R;
                }

                SetPos(Run.PosTo);
                return(true);
            }

            return(false);
        }
Пример #6
0
        private void cmClick(object sender, MouseButtonEventArgs e)
        {
            Point XY = e.GetPosition(gPole);

            TCell Z = Pole.GetCell(XY);

            if (CheckFor == null)
            {
                Pole.Who(Z, out CheckFor);

                if (CheckFor == null)
                {
                    return;
                }

                if (CheckFor.C != WB.W)
                {
                    CheckFor = null;
                    return;
                }
            }
            else
            {
                ArrayList arr = new ArrayList();

                TRun Run = new TRun(CheckFor, Z);

                TRuns Runs;
                TRuns RunsKill;

                for (int n = 0; n < Pole.CW.Count; n++)
                {
                    RunsKill = Pole.CW[n].GetRunsKill(Pole);

                    for (int k = 0; k < RunsKill.Count; k++)
                    {
                        arr.Add(RunsKill[k]);
                    }
                }
                if (arr.Count > 0)
                {
                    for (int k = 0; k < arr.Count; k++)
                    {
                        TRun R = (TRun)arr[k];

                        if ((Run.Check.Pos.Eq(R.Check.Pos)) && (Run.PosTo.Eq(R.PosTo)))
                        {
                            R.Check.Run(Pole, R);

                            IsW = !IsW;
                            cmRun(null, null);
                            CheckFor = null;
                            return;
                        }
                    }

                    CheckFor = null;
                    return;
                }
                else
                {
                    arr.Clear();

                    for (int n = 0; n < Pole.CW.Count; n++)
                    {
                        Runs = Pole.CW[n].GetRuns(Pole);

                        for (int k = 0; k < Runs.Count; k++)
                        {
                            arr.Add(Runs[k]);
                        }
                    }

                    if (arr.Count > 0)
                    {
                        for (int k = 0; k < arr.Count; k++)
                        {
                            TRun R = (TRun)arr[k];

                            if ((Run.Check.Pos.Eq(R.Check.Pos)) && (Run.PosTo.Eq(R.PosTo)))
                            {
                                R.Check.Run(Pole, R);

                                IsW = !IsW;
                                cmRun(null, null);
                                CheckFor = null;
                                return;
                            }
                        }

                        CheckFor = null;
                        return;
                    }
                    else
                    {
                        IsGame = false;

                        WB Cx;

                        if (IsW)
                        {
                            Cx = WB.W;
                        }
                        else
                        {
                            Cx = WB.B;
                        }

                        Pole.GameOver(Cx);

                        Pole = new TPole(gPole);
                    }
                }
            }
        }
Пример #7
0
        public TCell NearDama(int dir, TPole Pole)
        {
            TNote  B_ = B;
            int    n_ = n;
            TCheck Who;

            if (dir == 1)
            {
                while ((B_ != TNote.A) && (n_ != 8))
                {
                    B_ = B_ - 1;
                    n_ = n_ + 1;
                    Pole.Who(new TCell(B_, n_), out Who);
                    if (Who != null)
                    {
                        return(new TCell(B_, n_));
                    }
                }
            }

            if (dir == 2)
            {
                while ((B_ != TNote.H) && (n_ != 8))
                {
                    B_ = B_ + 1;
                    n_ = n_ + 1;
                    Pole.Who(new TCell(B_, n_), out Who);
                    if (Who != null)
                    {
                        return(new TCell(B_, n_));
                    }
                }
            }

            if (dir == 3)
            {
                while ((B_ != TNote.A) && (n_ != 1))
                {
                    B_ = B_ - 1;
                    n_ = n_ - 1;
                    Pole.Who(new TCell(B_, n_), out Who);
                    if (Who != null)
                    {
                        return(new TCell(B_, n_));
                    }
                }
            }

            if (dir == 4)
            {
                while ((B_ != TNote.H) && (n_ != 1))
                {
                    B_ = B_ + 1;
                    n_ = n_ - 1;
                    Pole.Who(new TCell(B_, n_), out Who);
                    if (Who != null)
                    {
                        return(new TCell(B_, n_));
                    }
                }
            }

            return(null);
        }
Пример #8
0
        public TCell[] NearsDama(int dir, TPole Pole)
        {
            ArrayList arr = new ArrayList(8);

            TNote B_ = B;
            int   n_ = n;

            arr.Add(new TCell(B_, n));

            TCheck Who;

            if (dir == 1)
            {
                while ((B_ != TNote.A) && (n_ != 8))
                {
                    B_ = B_ - 1;
                    n_ = n_ + 1;

                    Pole.Who(new TCell(B_, n_), out Who);
                    if (Who == null)
                    {
                        arr.Add(new TCell(B_, n_));
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (dir == 2)
            {
                while ((B_ != TNote.H) && (n_ != 8))
                {
                    B_ = B_ + 1;
                    n_ = n_ + 1;
                    Pole.Who(new TCell(B_, n_), out Who);
                    if (Who == null)
                    {
                        arr.Add(new TCell(B_, n_));
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (dir == 3)
            {
                while ((B_ != TNote.A) && (n_ != 1))
                {
                    B_ = B_ - 1;
                    n_ = n_ - 1;
                    Pole.Who(new TCell(B_, n_), out Who);
                    if (Who == null)
                    {
                        arr.Add(new TCell(B_, n_));
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (dir == 4)
            {
                while ((B_ != TNote.H) && (n_ != 1))
                {
                    B_ = B_ + 1;
                    n_ = n_ - 1;
                    Pole.Who(new TCell(B_, n_), out Who);
                    if (Who == null)
                    {
                        arr.Add(new TCell(B_, n_));
                    }
                    else
                    {
                        break;
                    }
                }
            }

            TCell[] Res = null;

            if (arr.Count > 0)
            {
                Res = new TCell[arr.Count];

                for (int i = 0; i < arr.Count; i++)
                {
                    Res[i] = (TCell)arr[i];
                }
            }

            return(Res);
        }
Пример #9
0
        public TRuns GetRunsKill(TPole Pole)
        {
            this.Pole = Pole;

            TRuns Res = new TRuns();

            if (Dama)
            {
                Tree = null;
                AddRunKillDama(null, 1, null);
                if (Tree != null)
                {
                    Tree.AddRuns(this, ref Res);
                    Tree = null;
                }


                AddRunKillDama(null, 2, null);
                if (Tree != null)
                {
                    Tree.AddRuns(this, ref Res);
                    Tree = null;
                }

                AddRunKillDama(null, 3, null);
                if (Tree != null)
                {
                    Tree.AddRuns(this, ref Res);
                    Tree = null;
                }

                AddRunKillDama(null, 4, null);
                if (Tree != null)
                {
                    Tree.AddRuns(this, ref Res);
                    Tree = null;
                }
            }
            else
            {
                Tree = null;
                AddRunKill(null, 1, null);
                if (Tree != null)
                {
                    Tree.AddRuns(this, ref Res);
                    Tree = null;
                }


                AddRunKill(null, 2, null);
                if (Tree != null)
                {
                    Tree.AddRuns(this, ref Res);
                    Tree = null;
                }

                AddRunKill(null, 3, null);
                if (Tree != null)
                {
                    Tree.AddRuns(this, ref Res);
                    Tree = null;
                }

                AddRunKill(null, 4, null);
                if (Tree != null)
                {
                    Tree.AddRuns(this, ref Res);
                    Tree = null;
                }
            }

            return(Res);
        }