예제 #1
0
        public bool Who(TCell Pos, out TCheck who)
        {
            who = null;

            if (Pos == null)
            {
                return(false);
            }

            for (int k = 0; k < CW.Count; k++)
            {
                if (CW[k].Pos.Eq(Pos))
                {
                    who = CW[k];
                    return(true);
                }
            }

            for (int k = 0; k < CB.Count; k++)
            {
                if (CB[k].Pos.Eq(Pos))
                {
                    who = CB[k];
                    return(true);
                }
            }

            return(true);
        }
예제 #2
0
 public void Set(TCell Pos)
 {
     this.i = Pos.i;
     this.j = Pos.j;
     this.B = Pos.B;
     this.n = Pos.n;
 }
예제 #3
0
 public TNode(TNode Parent, TCell Pos, TCheck Killed, int dir)
 {
     this.Parent = Parent;
     this.Pos    = Pos;
     this.Killed = Killed;
     this.dir    = dir;
 }
예제 #4
0
        public void SetPos(TCell Pos)
        {
            double L     = g.Width; // сохранить размер игрового поля
            double L8    = L / 8.0;
            double kappa = 0.8;

            this.Pos.Set(Pos);

            if (((Pos.n == 1) && (C == WB.B)) || ((Pos.n == 8) && (C == WB.W)))
            {
                Dama = true;

                O[1]                 = new Ellipse();
                O[1].Stroke          = Brushes.Red;
                O[1].StrokeThickness = 3;
                O[1].Width           = kappa * L8 / 2;
                O[1].Height          = kappa * L8 / 2;
                g.Children.Add(O[1]);
            }

            O[0].Margin = new Thickness(Pos.i * L8 + L8 * (1 - kappa) / 2, Pos.j * L8 + L8 * (1 - kappa) / 2, 0, 0);

            if (O[1] != null)
            {
                O[1].Margin = new Thickness(Pos.i * L8 + (L8 - O[1].Width) / 2, Pos.j * L8 + (L8 - O[1].Height) / 2, 0, 0);
            }
        }
예제 #5
0
 public TCheck(Canvas g, WB C, TCell Pos)
 {
     this.g   = g;
     this.C   = C;
     this.Pos = Pos;
     O        = new Ellipse[2];
     O[0]     = null;
     O[1]     = null;
 }
예제 #6
0
 public bool Eq(TCell Pos)
 {
     if ((B == Pos.B) && (n == Pos.n))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #7
0
        Ellipse DrawCheck(TCell Pos, WB C)
        {
            double L     = g.Width; // сохранить размер игрового поля
            double L8    = L / 8.0;
            double kappa = 0.8;

            Ellipse O = new Ellipse();

            if (C == WB.W)
            {
                O.Fill = Brushes.White;
            }
            else
            {
                O.Fill = Brushes.Black;
            }
            O.Width  = kappa * L8;
            O.Height = kappa * L8;

            O.Margin = new Thickness(Pos.i * L8 + L8 * (1 - kappa) / 2, Pos.j * L8 + L8 * (1 - kappa) / 2, 0, 0);
            g.Children.Add(O);

            return(O);
        }
예제 #8
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);
                    }
                }
            }
        }
예제 #9
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);
        }
예제 #10
0
 public TRun(TCheck Check, TCell PosTo)
 {
     this.Check = Check;
     this.PosTo = PosTo;
     Killed     = new ArrayList();
 }
예제 #11
0
        public void Move(int n, TCell Pos)
        {
            TCheck Check = this[n];

            Check.SetPos(Pos);
        }
예제 #12
0
        void AddRunKill(TCell StartPos, int dir, TNode Parent)
        {
            TCell  Near;
            TCheck Who;
            TCheck W2;

            if (StartPos == null)
            {
                Near = Pos.Near(dir);
            }
            else
            {
                Near = StartPos.Near(dir);
            }


            if (Pole.Who(Near, out Who))
            {
                if (Who == null)
                {
                }
                else
                {
                    if (Who.C != C)
                    {
                        Near = Who.Pos.Near(dir);

                        if (Pole.Who(Near, out W2))
                        {
                            if (W2 == null)
                            {
                                TNode Cur = new TNode(Parent, Near, Who, dir);

                                if (Tree == null)
                                {
                                    Tree = new TTree(Cur, Pole);
                                }
                                Tree.Count++;

                                int Count = Tree.Count;

                                for (int i = 1; i <= 4; i++)
                                {
                                    if (((dir == 1) && (i == 4)) || ((dir == 2) && (i == 3)) ||
                                        ((dir == 3) && (i == 2)) || ((dir == 4) && (i == 1)))
                                    {
                                        continue;
                                    }

                                    AddRunKill(Near, i, Cur);
                                }

                                if (Count == Tree.Count)
                                {
                                    Tree.Lists.Add(Cur);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #13
0
        void AddRunKillDama(TCell StartPos, int dir, TNode Parent)
        {
            ArrayList arr = new ArrayList();

            TCell Near;

            if (StartPos == null)
            {
                Near = Pos.NearDama(dir, Pole);
            }
            else
            {
                Near = StartPos.NearDama(dir, Pole);
            }

            TCheck Who;

            Pole.Who(Near, out Who);

            if (Who == null)
            {
                return;
            }

            if (Who.C == C)
            {
                return;
            }

            Near = Near.Near(dir);

            TCheck W2;

            if (Pole.Who(Near, out W2))
            {
                if (W2 == null)
                {
                    TNode Cur = new TNode(Parent, Near, Who, dir);

                    if (Tree == null)
                    {
                        Tree = new TTree(Cur, Pole);
                    }
                    Tree.Count++;

                    int Count = Tree.Count;

                    TCell[] Nears;

                    for (int i = 1; i <= 4; i++)
                    {
                        if (((dir == 1) && (i == 4)) || ((dir == 2) && (i == 3)) ||
                            ((dir == 3) && (i == 2)) || ((dir == 4) && (i == 1)))
                        {
                            continue;
                        }

                        Nears = Near.NearsDama(dir, Pole);

                        for (int k = 0; k < Nears.Count(); k++)
                        {
                            AddRunKillDama(Nears[k], i, Cur);
                        }
                    }

                    if (Count == Tree.Count)
                    {
                        Tree.Lists.Add(Cur);
                    }
                }
            }
        }