示例#1
0
    static List <Move> DetermenMoves()
    {
        List <Move>    moves       = new List <Move>();
        List <Factory> myFactories = Factories.Where(f => f.Value.Owner == 1).Select(f => f.Value).ToList();

        myFactories.Sort((f1, f2) =>
        {
            if (f1.CyborgCount < f2.CyborgCount)
            {
                return(1);
            }
            if (f1.CyborgCount > f2.CyborgCount)
            {
                return(-1);
            }
            return(0);
        });

        Factory factory = myFactories.FirstOrDefault();

        if (factory != null)
        {
            List <FactoryLink> others = factory.Links.Where(f => f.Target.Owner != 1).ToList();

            others.Sort((f1, f2) =>
            {
                if (f1.Score < f2.Score)
                {
                    return(-1);
                }
                if (f1.Score > f2.Score)
                {
                    return(1);
                }
                return(0);
            });

            FactoryLink fl = others.FirstOrDefault();
            if (fl != null)
            {
                Move m = new Move()
                {
                    SourceId = factory.Id,
                    Target   = fl.Target.Id,
                    Troops   = factory.CyborgCount,
                };
                moves.Add(m);
            }
        }
        return(moves);
    }
示例#2
0
    static List <Move> DetermenMoves()
    {
        List <Factory> myFactories = Factories.Where(f => f.Value.Owner == 1).Select(f => f.Value).ToList();
        List <Move>    moves       = new List <Move>();

        foreach (Factory f in myFactories)
        {
            Console.Error.Write($"({f.Id})");
            for (int i = 0; i < 20; i++)
            {
                Console.Error.Write($" {f.CyborgPredictionCount[i]}");
            }
            Console.Error.WriteLine();
            int surplus = f.SurplusCyborgs;
            f.Links.Sort((l1, l2) =>
            {
                if (l1.Score > l2.Score)
                {
                    return(-1);
                }
                if (l1.Score < l2.Score)
                {
                    return(1);
                }

                return(0);
            });
            List <Move> factoryMoves = new List <Move>();
            if ((f.Production < 3) && (surplus > 10))
            {
                FactoryLink fl = f.Links.First();
                if (fl.Target.Owner == 1)
                {
                    moves.Add(new Move()
                    {
                        SourceId = f.Id, Inc = true,
                    });
                    surplus -= 10;
                }
            }

            foreach (FactoryLink fl in f.Links)
            {
                bool sendBomb = false;
                if (RemainingBombs > 1)
                {
                    sendBomb = (fl.Target.Owner == -1)

                               && (fl.Target.Production >= 2);
                }
                else if (RemainingBombs > 0)
                {
                    sendBomb = (fl.Target.Owner == -1) && (fl.Target.Production == 3) && (fl.Target.CyborgCount > 50);
                }

                if (!sendBomb)
                {
                    if (surplus > 0)
                    {
                        if (fl.Target.Owner != 1)
                        {
                            int neededTroops = fl.Target.CyborgCount + fl.Distance * fl.Target.Production;
                            int troops       = (neededTroops < surplus) ? neededTroops + 1 : surplus;
                            int target       = fl.Target.Id;
                            if (fl.AlternativeRoutes.Count > 0)
                            {
                                target = fl.AlternativeRoutes.First().Steps.First();
                            }
                            factoryMoves.Add(new Move()
                            {
                                SourceId = f.Id, Target = target, Troops = troops
                            });
                            surplus -= troops;
                        }
                        else
                        {
                            if (fl.Target.SurplusCyborgs < 0)
                            {
                                int troops = (-fl.Target.SurplusCyborgs < surplus) ? -fl.Target.SurplusCyborgs + 1 : surplus;
                                int target = fl.Target.Id;
                                if (fl.AlternativeRoutes.Count > 0)
                                {
                                    int alternativesIndex = 0;
                                    while ((alternativesIndex < fl.AlternativeRoutes.Count) &&
                                           Factories[fl.AlternativeRoutes[alternativesIndex].Steps.First()].Owner == -1)
                                    {
                                        alternativesIndex++;
                                    }
                                    if (alternativesIndex < fl.AlternativeRoutes.Count)
                                    {
                                        target = fl.AlternativeRoutes[alternativesIndex].Steps.First();
                                    }
                                }
                                factoryMoves.Add(new Move()
                                {
                                    SourceId = f.Id, Target = target, Troops = troops
                                });
                                surplus -= troops;
                            }
                        }                         //*/
                    }
                }
                else
                {
                    moves.Add(new Move()
                    {
                        SourceId = f.Id, Target = fl.Target.Id, SendBomb = true,
                    });
                    RemainingBombs--;
                }
            }
            factoryMoves.Sort((fm1, fm2) =>
            {
                if (fm1.Target < fm2.Target)
                {
                    return(-1);
                }
                if (fm1.Target > fm2.Target)
                {
                    return(1);
                }
                return(0);
            });
            int trc = 0;
            int t   = -1;
            foreach (Move m in factoryMoves)
            {
                if ((t != -1) && (t != m.Target))
                {
                    moves.Add(new Move()
                    {
                        SourceId = m.SourceId, Target = t, Troops = trc
                    });
                    trc = 0;
                }
                trc += m.Troops;
                t    = m.Target;
            }
            if (t != -1)
            {
                moves.Add(new Move()
                {
                    SourceId = f.Id, Target = t, Troops = trc
                });
                trc = 0;
            }
        }
        return(moves);
    }