Esempio n. 1
0
        List <Step> GetLinkWhiteSteps(StepBlock block)
        {
            List <Step> whites = new List <Step>();

            foreach (var step in block.Steps)
            {
                LinkSteps(step, StoneColor.White).ForEach(s => {
                    if (!whites.Contains(s))
                    {
                        whites.Add(s);
                    }
                });
            }
            return(whites);
        }
Esempio n. 2
0
        List <Step> GetLinkBlackSteps(StepBlock block)
        {
            List <Step> blacks = new List <Step>();

            foreach (var step in block.Steps)
            {
                LinkSteps(step, StoneColor.Black).ForEach(s => {
                    if (!blacks.Contains(s))
                    {
                        blacks.Add(s);
                    }
                });
            }
            return(blacks);
        }
Esempio n. 3
0
        List <Step> GetLinkEmptySteps(StepBlock block)
        {
            List <Step> empties = new List <Step>();

            foreach (var step in block.Steps)
            {
                LinkSteps(step, StoneColor.Empty).ForEach(s => {
                    if (!empties.Contains(s))
                    {
                        empties.Add(s);
                    }
                });
            }
            block.EmptyCount = empties.Count;
            block.Steps.ForEach(s => s.EmptyCount = block.EmptyCount);

            return(empties);
        }
Esempio n. 4
0
        private Pos GetPos(StepBlock block, List <Step> empties)        // For CanLevy()
        {
            Pos p = m_InvalidPos;

            if (empties.Count != 2)
            {
                return(p);
            }

            foreach (var item in block.Steps)
            {
                var i_empties = LinkSteps(item);
                if (i_empties.Contains(empties[0]) && i_empties.Contains(empties[1]))
                {
                    p = GetPos(item);
                    break;
                }
            }
            return(p);
        }
Esempio n. 5
0
        bool UpdateDeadBlocks(List <StepBlock> selfBlocks)
        {
            bool result = false;

            List <StepBlock> blocks = new List <StepBlock>();

            foreach (var item in selfBlocks)
            {
                blocks.Add(item);                   //copy
            }

            foreach (var block in blocks)
            {
                List <Step> empties = GetLinkEmptySteps(block);
                block.EmptyCount = empties.Count;

                if (empties.Count == 0)
                {
                    if (block.Steps.Count == 1)
                    {
                        var  step       = block.Steps[0];
                        var  otherColor = step.StoneColor == StoneColor.Black ? StoneColor.White : StoneColor.Black;
                        var  links      = LinkSteps(step, otherColor);
                        bool isBanOnce  = true;
                        foreach (var link in links)
                        {
                            // 0:为吃对方时的气数,多子时可以倒扑。
                            if (link.EmptyCount == 0 && LinkSteps(link, link.StoneColor).Count > 1)
                            {
                                isBanOnce = false;
                            }
                        }
                        if (isBanOnce)                           // 为倒扑
                        {
                            m_BanOnce.Row       = block.Steps[0].Row;
                            m_BanOnce.Col       = block.Steps[0].Col;
                            m_BanOnce.StepCount = block.Steps[0].StepCount;
                        }
                    }

                    StepBlock deadInfo = new StepBlock();
                    foreach (var dead in block.Steps)
                    {
                        var d = CloneStep(dead);
                        deadInfo.Steps.Add(d);

                        if (dead.StoneColor == StoneColor.Black)
                        {
                            m_BlackSteps.Remove(dead);
                        }
                        else if (dead.StoneColor == StoneColor.White)
                        {
                            m_WhiteSteps.Remove(dead);
                        }
                        m_EmptySteps.Add(dead);
                        HideStep(dead);
                    }
                    if (m_DeadBlocks.Keys.Contains(m_StepCount))
                    {
                        foreach (var item in deadInfo.Steps)
                        {
                            if (!m_DeadBlocks[m_StepCount].Steps.Contains(item))
                            {
                                m_DeadBlocks[m_StepCount].Steps.Add(item);
                            }
                        }
                    }
                    else
                    {
                        m_DeadBlocks[m_StepCount] = deadInfo;
                    }
                    selfBlocks.Remove(block);
                    result = true;
                }
            }
            return(result);
        }
Esempio n. 6
0
        private void UpdateStepBlocks(List <Step> steps, List <StepBlock> blocks)
        {
            List <Step> copySteps = new List <Step>();

            foreach (var item in steps)
            {
                copySteps.Add(item);
            }

            if (copySteps.Count == 0)
            {
                return;
            }

            var tmp = new List <Step>();

            foreach (var step in copySteps)
            {
                if (tmp.Count == 0)
                {
                    tmp.Add(step);
                }
                var sameLinks = LinkSteps(step, step.StoneColor);
                if (tmp.Intersect(sameLinks).Count() != 0)
                {
                    sameLinks.ForEach(s => { if (!tmp.Contains(s))
                                             {
                                                 tmp.Add(s);
                                             }
                                      });
                }
            }
            for (int i = 0; i < 6; i++)
            {
                foreach (var step in copySteps)                     // 防止遗漏
                {
                    var sameLinks = LinkSteps(step, step.StoneColor);
                    if (tmp.Intersect(sameLinks).Count() != 0)
                    {
                        sameLinks.ForEach(s => { if (!tmp.Contains(s))
                                                 {
                                                     tmp.Add(s);
                                                 }
                                          });
                    }
                }
            }
            if (tmp.Count == 0)
            {
                return;
            }

            StepBlock block = new StepBlock();

            block.Steps = tmp;
            block.UpdateBlockId();
            blocks.Add(block);

            copySteps.RemoveAll(s => tmp.Contains(s));          // next block
            UpdateStepBlocks(copySteps, blocks);                // 递归
        }