Пример #1
0
        public void DoTurn(IPirateGame game)
        {
            List <Pirate>   full_ships        = game.MyPiratesWithTreasures();
            List <Pirate>   empty_ships       = game.MyPiratesWithoutTreasures();
            List <Treasure> current_treasures = game.Treasures();
            int             min   = game.Distance(empty_ships[0], current_treasures[0]);
            Pirate          S     = empty_ships[0];
            Treasure        T     = current_treasures[0];
            int             steps = 6;
            bool            valid = false;

            if (full_ships != null)
            {
                foreach (Pirate s in full_ships)
                {
                    game.SetSail(s, game.GetSailOptions(s, s.InitialLocation, 1)[0]);
                    steps--;
                }
            }

            if (current_treasures != null && empty_ships != null)
            {
                while (steps != 0)
                {
                    foreach (Pirate s in empty_ships)
                    {
                        if (s.ReloadTurns != 0)
                        {
                            empty_ships.Remove(S);
                            continue;
                        }
                        valid = true;
                        foreach (Treasure t in current_treasures)
                        {
                            if (game.Distance(s, t) < min && game.Distance(s, t) != 0)
                            {
                                min = game.Distance(s, t);
                                S   = s;
                                T   = t;
                            }
                        }
                    }
                    if (valid)
                    {
                        game.SetSail(S, game.GetSailOptions(S, T, (steps < min) ? steps : min)[0]);
                        steps -= min;
                        empty_ships.Remove(S);
                    }
                }
            }
        }
Пример #2
0
        public void DoTurn(IPirateGame game)
        {
            try
            {
                int remaining = 6;

                Pirate[]   ps  = new Pirate[4];
                int[]      ds  = new int[4];
                List <int> dss = new List <int>();// should always be size 4
                for (int i = 0; i < 4; i++)
                {
                    ps[i] = game.GetMyPirate(i);
                    ds[i] = int.MaxValue;
                    if (game.Treasures().Contains(ts[i]))
                    {
                        continue;
                    }
                    foreach (Treasure t in game.Treasures())
                    {
                        if (game.Distance(ps[i], t) < ds[i])
                        {
                            ds[i] = game.Distance(ps[i], t);
                            //ts[i] = t;
                        }
                    }
                }


                // sort the ds into the dss
                {
                    bool add;
                    do
                    {
                        add = false;
                        int min = -1;
                        for (int i = 0; i < ds.Length; i++)
                        {
                            if (!dss.Contains(i))
                            {
                                if (min == -1 || ds[i] <= ds[min])
                                {
                                    min = i;
                                    add = true;
                                }
                            }
                        }
                        if (add)
                        {
                            dss.Add(min);
                        }
                    } while (add);
                }


                if (kamikaze)
                {
                    if (ps[0].InitialLocation.Equals(new Location(23, 1)))
                    {
                        ts[3] = new Treasure(19, new Location(17, 19));
                        ts[1] = new Treasure(20, new Location(24, 30));
                        ts[2] = new Treasure(20, new Location(25, 29));
                        ts[0] = new Treasure(20, new Location(26, 28));
                    }
                    else
                    {
                        ts[3] = new Treasure(19, new Location(17, 13));
                        ts[1] = new Treasure(20, new Location(24, 2));
                        ts[2] = new Treasure(20, new Location(25, 3));
                        ts[0] = new Treasure(20, new Location(26, 4));
                    }
                    ds[0] = 0;
                    ds[1] = 0;
                    ds[2] = 0;
                    ds[3] = 0;
                }


                List <Pirate> ltp = game.MyPiratesWithTreasures();
                remaining -= ltp.Count;
                foreach (Pirate p in ltp)
                {
                    move(p, p.InitialLocation, 1, game);
                }


                Pirate k = null, tar = null;
                if (game.Treasures().Count == 0 && game.EnemyPiratesWithTreasures().Count > 0)
                {
                    int d = int.MaxValue;
                    tar = game.EnemyPiratesWithTreasures()[0];
                    foreach (Pirate p in game.MyPiratesWithoutTreasures())
                    {
                        if (p.TurnsToSober == 0 && p.ReloadTurns < 6 && d > game.Distance(p, tar))
                        {
                            d = game.Distance(p, tar);
                            k = p;
                        }
                    }
                }


                for (int j = 0; j < 4; j++)
                {
                    int i = dss[j];
                    if (!ps[i].HasTreasure)
                    {
                        bool attacked = false;
                        if (ps[i].ReloadTurns == 0)
                        {
                            Pirate t = null;
                            foreach (Pirate e in game.EnemySoberPirates())
                            {
                                if (game.InRange(ps[i], e))
                                {
                                    if (e.ReloadTurns == 0)
                                    {
                                        t = e;
                                        break;
                                    }
                                    else if (e.HasTreasure)
                                    {
                                        if (t == null || t.HasTreasure || t.ReloadTurns > 0)
                                        {
                                            t = e;
                                        }
                                    }
                                    else if (e.ReloadTurns > 0 && !e.HasTreasure)
                                    {
                                        continue;
                                    }
                                }
                            }
                            if (t != null)
                            {
                                game.Attack(ps[i], t);
                                attacked = true;
                            }
                        }
                        if (!attacked && ps[i].TurnsToSober == 0 && ps[i].TurnsToRevive == 0)
                        {
                            if ((game.Treasures().Count > 0 && move(ps[i], ts[i].Location, remaining, game) || (game.EnemyPiratesWithTreasures().Count > 0 && ps[i] == k && move(ps[i], tar.Location, remaining, game))))
                            {
                                remaining = 0;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                game.Debug("Crashed!");
                game.Debug(e.Message);
                game.Debug(e.StackTrace);
            }
        }