Example #1
0
        // returns a list of all the enemies who can shoot the given Pirate
        private List <Pirate> findEnemiesFor(Pirate p, IPirateGame game)
        {
            List <Pirate> res = new List <Pirate>();

            foreach (Pirate e in game.EnemySoberPirates())
            {
                if (e.ReloadTurns == 0 && game.InRange(e, p))
                {
                    res.Add(e);
                }
            }
            return(res);
        }
Example #2
0
        // returns a prioritised queue of targets for the given Pirate
        private List <Pirate> findTargetsFor(Pirate p, IPirateGame game)
        {
            // TODO: if kamikaze and in enemy InitialLocation, don't shoot the Pirate with the id for the location
            List <Pirate> res = new List <Pirate>();

            foreach (Pirate e in game.EnemySoberPirates())
            {
                if (game.InRange(p, e) && e.DefenseExpirationTurns == 0)
                {
                    if (!panic && e.ReloadTurns == 0)                    // if we aren't in panic, and we have no target, shoot the one that has ammo; TODO: alter ReloadTurns value
                    {
                        res.Add(e);
                    }
                    else if (e.HasTreasure)                    // always prioritise Pirates with Treasures
                    {
                        res.Insert(0, e);
                    }
                }
            }
            return(res);
        }
Example #3
0
        public void DoTurn(IPirateGame game)
        {
            int remaining = 6;

            Pirate[]   ps  = new Pirate[4];
            Location[] l   = new Location[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;
                foreach (Treasure t in game.Treasures())
                {
                    if (game.Distance(ps[i], t) < ds[i])
                    {
                        ds[i] = game.Distance(ps[i], t);
                        l[i]  = t.Location;
                    }
                }
            }

            // 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);
            }

            List <Pirate> ltp = game.MyPiratesWithTreasures();

            remaining -= ltp.Count;
            foreach (Pirate p in ltp)
            {
                game.SetSail(p, game.GetSailOptions(p, p.InitialLocation, 1)[0]);
            }

            if (game.Treasures().Count == 0)
            {
                return;
            }
            for (int j = 0; j < 4; j++)
            {
                int i = dss[j];
                if (!ps[i].HasTreasure)
                {
                    bool attacked = false;
                    if (ps[i].ReloadTurns == 0)
                    {
                        foreach (Pirate e in game.EnemySoberPirates())
                        {
                            if (game.InRange(ps[i], e))
                            {
                                game.Attack(ps[i], e);
                                attacked = true;
                                break;
                            }
                        }
                    }

                    if (!attacked && ps[i].TurnsToSober == 0 && ps[i].TurnsToRevive == 0)
                    {
                        game.SetSail(ps[i], game.GetSailOptions(ps[i], /*cull*/ l[i], remaining)[0]);
                        remaining = 0;
                    }
                }
            }
        }
Example #4
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);
            }
        }