Пример #1
0
        public void UpdateMeshWorths(Pos next, bool isBlack = true, List <Pos> blackPoses = null, List <Pos> whitePoses = null)
        {
            if (blackPoses == null)
            {
                blackPoses = BlackPoses.ToList();
            }
            if (whitePoses == null)
            {
                whitePoses = WhitePoses.ToList();
            }
            for (int i = 0; i < 19; i++)
            {
                for (int j = 0; j < 19; j++)
                {
                    m_MeshWorths[i, j] = 0;
                }
            }

            foreach (var p in blackPoses)
            {
                SetMeshWorth(p, true);
            }
            foreach (var p in whitePoses)
            {
                SetMeshWorth(p, false);
            }

            if (EmptyPoses.Contains(next) && isBlack)
            {
                SetMeshWorth(next, true);
            }
            else if (EmptyPoses.Contains(next) && !isBlack)
            {
                SetMeshWorth(next, false);
            }

            m_BlackMeshes.Clear();
            m_WhiteMeshes.Clear();
            for (int i = 0; i < 19; i++)
            {
                for (int j = 0; j < 19; j++)
                {
                    if (m_MeshWorths[i, j] > 0)
                    {
                        m_BlackMeshes.Add(new Pos(i, j));
                    }
                    else if (m_MeshWorths[i, j] < 0)
                    {
                        m_WhiteMeshes.Add(new Pos(i, j));
                    }
                }
            }

            FillMeshEmpty(1);
        }
Пример #2
0
        Pos BestPos()
        {
            m_BestPoses.Clear();
            var empties = EmptyPoses.ToList();

            foreach (var e in empties)
            {
                UpdateMeshWorths(e);
                int worth = m_BlackMeshes.Count - m_WhiteMeshes.Count;
                var p     = new Pos(e.Row, e.Col, e.StoneColor, e.StepCount, worth);
                if (!m_BestPoses.Contains(p))
                {
                    m_BestPoses.Add(p);
                }
            }

            var poses  = m_BestPoses.OrderByDescending(p => p.Worth);
            int repeat = 0;

            foreach (var p in poses)
            {
                if (m_ThinkPoses.Contains(p))
                {
                    return(p);
                }
                if (repeat++ < 10)
                {
                    m_ShapeThink.CurrentPos = p;
                    var temp = m_ShapeThink.Think(R.Game);
                    m_ShapeThink.CurrentPos = Helper.InvalidPos;
                    if (temp.Contains(p))
                    {
                        return(p);
                    }
                }
            }

            if (m_StepCount > 260)
            {
                ShowMeshes();                  // game over
            }

            return(poses.First());
        }
Пример #3
0
 void FillMeshEmpty(int repeat = 1)
 {
     for (int i = 0; i < repeat; i++)
     {
         var blacks  = m_BlackMeshes.ToList();
         var whites  = m_WhiteMeshes.ToList();
         var empties = EmptyPoses.Except(blacks).Except(whites);
         foreach (var e in empties)
         {
             var links      = LinkPoses(e);
             var linkBlacks = links.Intersect(blacks);
             var linkWhites = links.Intersect(whites);
             if (linkBlacks.Count() >= 2 && linkWhites.Count() == 0)
             {
                 m_BlackMeshes.Add(e);
             }
             else if (linkWhites.Count() >= 2 && linkBlacks.Count() == 0)
             {
                 m_WhiteMeshes.Add(e);
             }
         }
     }
 }