예제 #1
0
        }         // calculates the closest treasure to ps[i]

        private void search_n_destroy(IPirateGame game, ref Pirate tar, ref Pirate k)
        {
            int mx = (game.GetRows() + game.GetCols() - game.GetAttackRadius()) / game.GetActionsPerTurn();            // turns it takes to get from a corner to its opposing corner
            int d  = int.MaxValue;

            tar = game.EnemyPiratesWithTreasures()[0];            // TODO: focus on closest to enemy base
            // find closest Pirate
            foreach (PirateContainer p in PirateContainer.free)   // notice all pirates with Treasure already moved, see: ltp
            {
                if (p.AVALIBLE && p.P.ReloadTurns < mx && d > game.Distance(p.P, tar))
                {
                    d = game.Distance(p.P, tar);
                    k = p.P;
                }
            }
            if (k == null)                                                         // no Pirate with ammo, so choose the closest to the InitialLocation then move to there
            {
                foreach (PirateContainer p in PirateContainer.free)                // notice all pirates with Treasure already moved, see: ltp
                {
                    if (p.AVALIBLE && d > game.Distance(p.P, tar.InitialLocation)) // TODO: make the "6" generic to board size
                    {
                        d = game.Distance(p.P, tar.InitialLocation);
                        k = p.P;
                    }
                }
            }
        }         //manages panic mode
예제 #2
0
        private static int remainingMoves;                 // number of remaining allowed moves

        public static void init(IPirateGame game)
        {
            free           = new List <PirateContainer>();
            kamikazes      = new List <PirateContainer>();
            withTreasure   = new List <PirateContainer>();
            remainingMoves = game.GetActionsPerTurn();
        }
        private PirateTactics AssignTargets(IPirateGame game, BoardStatus status)
        {
            PirateTactics tactics = new PirateTactics()
            {
                Pirate = status.Pirate
            };

            tactics.Moves = game.GetActionsPerTurn();
            if (status.Script != null)
            {
                tactics.FinalDestination = status.Script.Location;
            }
            else if (!tactics.Pirate.HasTreasure)
            {
                tactics.FinalDestination = status.Treasure.Location;
            }
            else
            {
                tactics.Moves            = 1;
                tactics.FinalDestination = status.Pirate.InitialLocation;
            }
            List <Location> possibleLocations = game.GetSailOptions(tactics.Pirate, tactics.FinalDestination, tactics.Moves);
            List <Location> safeLocations     = GetSafeLocations(game, possibleLocations);

            if (safeLocations.Count > 0)
            {
                tactics.TempDestination = safeLocations[0];
            }
            return(tactics);
        }
예제 #4
0
 public void DoTurn(IPirateGame game)
 {
     this.game = game;
     turns     = game.GetActionsPerTurn();
     PlayZero(turns);
     PlayZero(turns, 1);
     PlayZero(turns, 2);
     PlayZero(turns, 3);
 }
예제 #5
0
 public void DoTurn(IPirateGame game)
 {
     try
     {
         this.game = game;
         turns     = game.GetActionsPerTurn();
         CheckBase();
         StopEnemies();
         ManagePlayZero();
     }
     catch
     {
     }
 }
예제 #6
0
 public void DoTurn(IPirateGame game)
 {
     if (game.GetTurn() == 1)
     {
         int s = 891;                //DateTime.Now.Millisecond;
         rand = new Random(s);
         game.Debug("seed: " + s);
     }
     try
     {
         this.game = game;
         turns     = game.GetActionsPerTurn();
         CheckBase();
         StopEnemies();
         ManagePlayZero();
     }
     catch (Exception e)
     {
         game.Debug(e.ToString());
     }
 }
예제 #7
0
        private PirateTactics AssignTargets(IPirateGame game, BoardStatus status)
        {
            PirateTactics tactics = new PirateTactics()
            {
                Pirate = status.Pirate
            };

            if (!tactics.Pirate.HasTreasure)
            {
                tactics.Moves            = game.GetActionsPerTurn();
                tactics.FinalDestination = status.Treasure.Location;
            }
            else
            {
                tactics.Moves            = 1;
                tactics.FinalDestination = status.Pirate.InitialLocation;
            }
            List <Location> possibleLocations = game.GetSailOptions(tactics.Pirate, tactics.FinalDestination, tactics.Moves);

            tactics.TempDestination = possibleLocations[0];
            return(tactics);
        }
예제 #8
0
        // this is the actual turn
        public void DoTurn(IPirateGame game)
        {
            if (game.GetTurn() == 1)
            {
                rand = new Random(42934837);                 //,,79409223
                if (game.AllEnemyPirates().Count > game.AllMyPirates().Count)
                {
                    rand = new Random(31400000);
                }
                Location l = new Location(1, 1);
                if (game.Treasures().Count == 1 && game.AllMyPirates().Count == game.AllEnemyPirates().Count)
                {
                    deadMap = true;
                }

                game.Debug((deadMap ? "DEADMAP!!!" : "NIE!"));
                if (deadMap)
                {
                    return;                    // this stops some fighting over treasures
                }
            }

            nowhere = (game.GetEnemyScore() == game.GetMyScore() && game.GetTurn() == (game.GetMaxTurns() / 3));
            if (nowhere)
            {
                game.Debug("ACTIVATING NOWHERE MODE!!!");
            }

            panic = (((game.Treasures().Count == 0 || game.GetEnemyScore() >= (game.GetMaxPoints() - 2))) && game.EnemyPiratesWithTreasures().Count > 0);
            if (panic)
            {
                game.Debug("ACTIVATING PANIC MODE!!!");
            }

            PirateContainer.init(game);
            QueuedAttack.init();
            QueuedMotion.init();
            int remaining = game.GetActionsPerTurn();
            int ships     = game.AllMyPirates().Count;

            try
            {
                // calculate the closest treasure to ps[i]
                PirateContainer[] ps = new PirateContainer[ships];
                int[]             ds = new int[ships];
                Treasure[]        ts = new Treasure[ships];
                for (int i = 0; i < ships; i++)
                {
                    ps[i] = new PirateContainer(game.GetMyPirate(i), (i % 2) == 1);
                    ds[i] = int.MaxValue;
                    foreach (Treasure t in game.Treasures())
                    {
                        if (game.Distance(ps[i].P, t) < ds[i])
                        {
                            ds[i] = game.Distance(ps[i].P, t);
                            ts[i] = t;
                        }
                    }
                }

                // control the kamikazes
                calcKamikazes(ps, ref ts, ref ds, game);

                // move Pirates that have treasures towards the base
                {
                    List <PirateContainer> ltp = PirateContainer.withTreasure;
                    foreach (PirateContainer p in ltp)
                    {
                        List <Pirate> es = findEnemiesFor(p.P, game);
                        if (es.Count > 0 && p.P.ReloadTurns == 0)
                        {
                            p.defend(game);
                        }
                        else
                        {
                            remaining -= move(p, p.P.InitialLocation, 1, game, true);
                        }
                    }
                }

                // search and destroy, TODO: prioritise this!!!
                Pirate k = null, tar = null;
                if (panic)
                {
                    int mx = (game.GetRows() + game.GetCols() - game.GetAttackRadius()) / game.GetActionsPerTurn(); // turns it takes to get from a corner to its opposing corner
                    int d  = int.MaxValue;
                    tar = game.EnemyPiratesWithTreasures()[0];                                                      // TODO: focus on closest to enemy base
                    // find closest Pirate
                    foreach (PirateContainer p in PirateContainer.free)                                             // notice all pirates with Treasure already moved, see: ltp
                    {
                        game.Debug("panic->k testing for " + p.P.Id + " | " + d);
                        game.Debug(p.AVALIBLE + " && " + (p.P.ReloadTurns < mx) + " && " + (d > game.Distance(p.P, tar)));
                        if (p.AVALIBLE && p.P.ReloadTurns < mx && d > game.Distance(p.P, tar))
                        {
                            d = game.Distance(p.P, tar);
                            k = p.P;
                            game.Debug("panic->k = " + p.P.Id + " | " + d);
                        }
                    }
                    if (k == null)                                                         // no Pirate with ammo, so choose the closest to the InitialLocation then move to there
                    {
                        foreach (PirateContainer p in PirateContainer.free)                // notice all pirates with Treasure already moved, see: ltp
                        {
                            if (p.AVALIBLE && d > game.Distance(p.P, tar.InitialLocation)) // TODO: make the "6" generic to board size
                            {
                                d = game.Distance(p.P, tar.InitialLocation);
                                k = p.P;
                            }
                        }
                    }
                }

                List <int> dss = sortInto(ds);               // sort the ds into the dss

                // AAAAATTTTTTTTTTTTAAAAAAAAAAACCCCCCCCKKKKKKKKKKKKKKK!!!!!!!!!!!!!!!! (or defend...)
                for (int i = PirateContainer.free.Count; i > 0;)
                {
                    PirateContainer p = PirateContainer.free[--i];
                    if (p.P.ReloadTurns == 0 && !p.P.HasTreasure && p.AVALIBLE)
                    {
                        List <Pirate> es = findTargetsFor(p.P, game);
                        if (es.Count > 0)
                        {
                            new QueuedAttack(p, es);
                        }
                    }
                }
                QueuedAttack.doAttacks(game, deadMap);

                // move
                for (int j = 0; j < ships; j++)
                {
                    int i = dss[j];
                    if (ps[i].S == PirateContainer.State.none && ps[i].AVALIBLE && !ps[i].P.HasTreasure)
                    {
                        if (game.Treasures().Count > 0)                        // use typical motion
                        {
                            int mv = move(ps[i], ts[i].Location, remaining, game);
                            if (mv > 0)
                            {
                                remaining -= mv;
                                continue;
                            }
                        }
                        if (game.EnemyPiratesWithTreasures().Count > 0 && ps[i].P == k)                        // activate search and destroy
                        {
                            remaining -= move(ps[i], tar.Location, remaining, game);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                game.Debug("Crashed!");
                game.Debug(e.Message);
                game.Debug(e.StackTrace);
            }
            game.Debug("turn " + game.GetTurn() + ": ran " + (game.GetActionsPerTurn() - remaining) + " motions");
        }
예제 #9
0
        // this is the actual turn
        public void DoTurn(IPirateGame game)
        {
            int remaining = game.GetActionsPerTurn();

            if (game.GetTurn() == 1)
            {
                game.Debug("moves per turn: " + remaining);
            }

            try
            {
                #region init
                if (game.GetTurn() == 1)
                {
                    chooseMap(game);
                }
                nowhere = inNowhereMode(game);
                if (nowhere)
                {
                    game.Debug("ACTIVATING NOWHERE MODE");
                }
                panic = inPanicMode(game);
                if (panic)
                {
                    game.Debug("ACTIVATING PANIC MODE");
                }

                PirateContainer.init(game);
                QueuedAttack.init();
                QueuedMotion.init();
                int ships            = game.AllMyPirates().Count;
                PirateContainer[] ps = new PirateContainer[ships];
                int[]             ds = new int[ships];
                Treasure[]        ts = new Treasure[ships];
                #endregion

                calcBestTreasure(game, ships, ref ps, ref ds, ref ts);  // calculate the closest treasure to ps[i]
                BringBackTreasure(game, ref remaining);                 // move Pirates that have treasures towards the base
                calcKamikazes(ps, ref ts, ref ds, game);                // control the kamikazes

                //BringBackTreasure(game, ref remaining); // move Pirates that have treasures towards the base
                //Powerup pt = new SpeedPowerup(-1, new Location(0, 0), 0, 0, 0);

                #region power up calculations
                Powerup[] pu = (from l in game.Powerups()
                                where l.Type == "Speed"
                                select l).ToArray();

                if (pu.Count() > 0)
                {
                    Powerup[] puu = new Powerup[ships];
                    for (int i = pu.Count() - 1; i >= 0; i--)
                    {
                        puu[i] = pu[i];
                    }
                    game.Debug("A speed powerup was found");
                    int[] dis = new int[ships];



                    locatePowerups(game, ships, ref ps, ref dis, ref puu);

                    int chosen = -1;
                    for (int i = 0, min = int.MaxValue; i < ships; ++i)
                    {
                        if (dis[i] < min && ps[i].AVALIBLE && dis[i] != 0)                        //&& !ps[i].P.HasTreasure
                        {
                            min    = dis[i];
                            chosen = i;
                        }
                    }
                    game.Debug("Moving pirate " + chosen + " towards powerup");

                    if (chosen != -1)
                    {
                        game.Debug("Distance of chosen powerup - " + dis[chosen]);
                        if (puu[chosen] == null)
                        {
                            game.Debug("we found the problem");
                        }

                        remaining -= move(ps[chosen], puu[chosen].Location, remaining, game);
                    }
                }
                #endregion

                #region panic mode
                Pirate k = null, tar = null;
                if (panic)
                {
                    search_n_destroy(game, ref tar, ref k);                     // search and destroy, TODO: prioritise this!!!
                }
                #endregion

                List <int> dss = sortInto(ds);               // sort the ds into the dss


                attack(game);
                QueuedAttack.doAttacks(game, deadMap);

                #region move
                // move
                for (int j = 0; j < ships; j++)
                {
                    int i = dss[j];
                    if (ps[i].S == PirateContainer.State.none && ps[i].AVALIBLE && !ps[i].P.HasTreasure)
                    {
                        if (game.Treasures().Count > 0)                        // use typical motion
                        {
                            Location l = powerup(ps[i].P.Location, ts[i].Location, game);
                            int      mv;
                            if (l != null)
                            {
                                mv = move(ps[i], l, remaining, game);
                            }
                            else
                            {
                                mv = move(ps[i], ts[i].Location, remaining, game);
                            }

                            if (mv > 0)
                            {
                                remaining -= mv;
                                continue;
                            }
                        }
                        if (game.EnemyPiratesWithTreasures().Count > 0 && ps[i].P == k)                        // activate search and destroy
                        {
                            remaining -= move(ps[i], tar.Location, remaining, game);
                        }
                    }
                }
                #endregion
            }
            catch (Exception e)
            {
                game.Debug("Crashed!");
                game.Debug(e.Message);
                game.Debug(e.StackTrace);
            }
            finally
            {
                WastedTurnsCounter += remaining;

                game.Debug("________");
                game.Debug("turn " + game.GetTurn() + " - moves summary");
                game.Debug("turns used: " + (game.GetActionsPerTurn() - remaining));
                game.Debug("turns wasted: " + remaining);
                game.Debug("________");
                game.Debug("game summary");
                game.Debug("turns used: " + (game.GetTurn() * game.GetActionsPerTurn() - WastedTurnsCounter) + "/" + (game.GetTurn() * game.GetActionsPerTurn()) + ", " + Math.Round((100 - (float)WastedTurnsCounter * 100 / (float)(game.GetTurn() * game.GetActionsPerTurn())), 2) + "% efficiency");
                game.Debug("turns wasted: " + WastedTurnsCounter);
            }
        }