Example #1
0
        public override void TimCacNuocDi()
        {
            int _x = this._vitri.x;
            int _y = this._vitri.y;

            CacNuocDi.Clear();
            for (int i = _x - 1; i < _x + 2; i++)
            {
                for (int j = _y - 1; j < _y + 2; j++)
                {
                    if ((Math.Abs(i - _x) + Math.Abs(j - _y) == 1) && i >= 0 && i < 8 && j >= 0 && j < 8)
                    {
                        ViTri vt = new ViTri(i, j);
                        CacNuocDi.Add(vt);
                    }
                }
            }

            // bỏ những nước đi không hợp lệ...
            List <ViTri> CacNuocDiCanLoaiRa = new List <ViTri>();

            ViTri[] CacNuocDi_arr = new ViTri[CacNuocDi.Count];
            CacNuocDi.CopyTo(CacNuocDi_arr);
            for (int i = 0; i < CacNuocDi_arr.Length; i++)
            {
                int vtx = CacNuocDi_arr[i].x;
                int vty = CacNuocDi_arr[i].y;
                if (banco.Table[vtx, vty] == _flag)
                {
                    CacNuocDi.Remove(CacNuocDi_arr[i]);
                }
            }
        }
Example #2
0
        public override void TimCacNuocDi()
        {
            int _x = this._vitri.x;
            int _y = this._vitri.y;

            CacNuocDi.Clear();
            for (int i = _x - 2; i < _x + 3; i++)
            {
                for (int j = _y - 2; j < _y + 3; j++)
                {
                    if ((Math.Abs(i - _x) + Math.Abs(j - _y) == 3) && i > -1 && i < 8 && j > -1 && j < 8)
                    {
                        if (banco.Table[i, j] != _flag)
                        {
                            ViTri vt = new ViTri(i, j);
                            CacNuocDi.Add(vt);
                        }
                    }
                }
            }
        }
Example #3
0
        public override void TimCacNuocDi()
        {
            int _x = this._vitri.x;
            int _y = this._vitri.y;

            CacNuocDi.Clear();
            if (_flag == 1)
            {
                HeSo = 1;
            }
            if (_flag == 2)
            {
                HeSo = -1;
            }


            if (LuotDi == 0)
            {
                if (banco.Table[_x, HeSo * 1 + _y] != _flag)
                {
                    ViTri vt = new ViTri(_x, HeSo * 1 + _y);
                    CacNuocDi.Add(vt);
                }

                if (banco.Table[_x, HeSo * 2] != _flag)
                {
                    if (banco.Table[_x, HeSo * 1 + _y] == 0)
                    {
                        ViTri vt = new ViTri(_x, HeSo * 2 + _y);
                        CacNuocDi.Add(vt);
                    }
                }

                if (_x < 7)
                {
                    if ((banco.Table[_x + 1, HeSo * 1 + _y] != 0) && (banco.Table[_x + 1, HeSo * 1 + _y] != _flag))
                    {
                        ViTri vtAn = new ViTri(_x + 1, HeSo * 1 + _y);
                        CacNuocDi.Add(vtAn);
                    }
                }
                if (_x > 0)
                {
                    if ((banco.Table[_x - 1, HeSo * 1 + _y] != 0) && (banco.Table[_x - 1, HeSo * 1 + _y] != _flag))
                    {
                        ViTri vtAn = new ViTri(_x + 1, HeSo * 1 + _y);
                        CacNuocDi.Add(vtAn);
                    }
                }


                LuotDi++;
            }
            else
            {
                if ((banco.Table[_x, HeSo * 1 + _y] != _flag) && (HeSo * 1 + _y < 8))
                {
                    ViTri vt = new ViTri(_x, HeSo * 1 + _y);
                    CacNuocDi.Add(vt);

                    if (_x < 7)
                    {
                        if ((banco.Table[_x + 1, HeSo * 1 + _y] != 0) && (banco.Table[_x + 1, HeSo * 1 + _y] != _flag))
                        {
                            ViTri vtAn = new ViTri(_x + 1, HeSo * 1 + _y);
                            CacNuocDi.Add(vtAn);
                        }
                    }
                    if (_x > 0)
                    {
                        if ((banco.Table[_x - 1, HeSo * 1 + _y] != 0) && (banco.Table[_x - 1, HeSo * 1 + _y] != _flag))
                        {
                            ViTri vtAn = new ViTri(_x + 1, HeSo * 1 + _y);
                            CacNuocDi.Add(vtAn);
                        }
                    }
                }
                LuotDi++;
            }
        }
Example #4
0
        public override void TimCacNuocDi()
        {
            int _x = this._vitri.x;
            int _y = this._vitri.y;

            CacNuocDi.Clear();
            int k = 0;

            for (int i = _x + 1; i < 8; i++)
            {
                k = 0;
                for (int j = _y + 1; j < 8; j++)
                {
                    if (banco.Table[j, j] == _flag)
                    {
                        break;
                    }
                    else
                    {
                        if (banco.Table[j, j] == 0)
                        {
                            ViTri vt = new ViTri(j, j);
                            CacNuocDi.Add(vt);
                        }
                        else
                        {
                            if (k == 0)
                            {
                                ViTri vt = new ViTri(j, j);
                                CacNuocDi.Add(vt);
                                k++;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                k = 0;
                for (int j = _y - 1; j >= 0; j--)
                {
                    if (banco.Table[j, j] == _flag)
                    {
                        break;
                    }
                    else
                    {
                        if (banco.Table[j, j] == 0)
                        {
                            ViTri vt = new ViTri(j, j);
                            CacNuocDi.Add(vt);
                        }
                        else
                        {
                            if (k == 0)
                            {
                                ViTri vt = new ViTri(j, j);
                                CacNuocDi.Add(vt);
                                k++;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
            for (int i = _x - 1; i >= 0; i--)
            {
                k = 0;
                for (int j = _y + 1; j < 8; j++)
                {
                    if (banco.Table[j, j] == _flag)
                    {
                        break;
                    }
                    else
                    {
                        if (banco.Table[j, j] == 0)
                        {
                            ViTri vt = new ViTri(j, j);
                            CacNuocDi.Add(vt);
                        }
                        else
                        {
                            if (k == 0)
                            {
                                ViTri vt = new ViTri(j, j);
                                CacNuocDi.Add(vt);
                                k++;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                k = 0;
                for (int j = _y - 1; j >= 0; j--)
                {
                    if (banco.Table[j, j] == _flag)
                    {
                        break;
                    }
                    else
                    {
                        if (banco.Table[j, j] == 0)
                        {
                            ViTri vt = new ViTri(j, j);
                            CacNuocDi.Add(vt);
                        }
                        else
                        {
                            if (k == 0)
                            {
                                ViTri vt = new ViTri(j, j);
                                CacNuocDi.Add(vt);
                                k++;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }