Example #1
0
        public override void OnYourTurn(棋子[][] positions, List <Position> blacks, List <Position> whites)
        {
            AIResult result = MakeTurn(positions, blacks, whites);

            result.Side = selfSide;
            FinishTurn(result.X, result.Y);
        }
Example #2
0
        public override AIResult MakeTurn(棋子[][] positions, List <Position> blacks, List <Position> whites)
        {
            AIResult result = new AIResult();
            List <KeyValuePair <int, int> > list = new List <KeyValuePair <int, int> >();

            float selfVal = 0f;
            float oppVal  = 0f;

            selfVal = CalculateValue(positions, selfSide, list);
            oppVal  = CalculateValue(positions, Utility.GetOppside(selfSide), list);

            KeyValuePair <int, int> best = new KeyValuePair <int, int>();
            float bestVal = 0f;

            if (list.Count <= 0)
            {
                for (int c = 1; c <= positions.Length / 2; c++)
                {
                    for (int i = 0; i < c * 2 + 1; i++)
                    {
                        for (int j = 0; j < c * 2 + 1; j++)
                        {
                            int coordX = positions.Length / 2 - c + i;
                            int coordY = positions.Length / 2 - c + j;
                            if (positions[i][j] == 棋子.无)
                            {
                                result.X = coordX;
                                result.Y = coordY;
                                if (Utility.IsDebugOpen)
                                {
                                    Messager.Instance.SendMessageLater(MessageKey.RefreshDebug, new object[] { selfTest, oppTest });
                                }
                                return(result);
                            }
                        }
                    }
                }
            }
            else
            {
                if (Utility.IsDebugOpen)
                {
                    ClearTest(ref selfTest);
                    ClearTest(ref oppTest);
                }
                for (int i = 0; i < list.Count; i++)
                {
                    KeyValuePair <int, int> pair = list[i];
                    if (IsInChess(pair.Key, pair.Value) && positions[pair.Key][pair.Value] == 棋子.无)
                    {
                        positions[pair.Key][pair.Value] = selfSide;
                        selfVal = CalculateValue(positions, selfSide, null);
                        positions[pair.Key][pair.Value] = Utility.GetOppside(selfSide);
                        oppVal = CalculateValue(positions, Utility.GetOppside(selfSide), null);

                        if (Utility.IsDebugOpen)
                        {
                            selfTest[pair.Key][pair.Value] = selfVal;
                            oppTest[pair.Key][pair.Value]  = oppVal;
                        }

                        float factor = _dna.Factor;

                        if (i == 0)
                        {
                            bestVal = selfVal * factor + oppVal;
                            best    = pair;
                        }
                        else
                        {
                            if (selfVal * factor + oppVal > bestVal)
                            {
                                bestVal = selfVal * factor + oppVal;
                                best    = pair;
                            }
                        }

                        positions[pair.Key][pair.Value] = 棋子.无;
                    }
                }
                result.X = best.Key;
                result.Y = best.Value;
            }



            if (Utility.IsDebugOpen)
            {
                Messager.Instance.SendMessageLater(MessageKey.RefreshDebug, new object[] { selfTest, oppTest });
            }
            return(result);
        }