コード例 #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 state)
        {
            // Initing stuff
            List <Island> islands     = state.NotMyIslands();
            List <Pirate> myPirates   = state.MyPirates();
            List <Pirate> copyPirates = new List <Pirate>(myPirates);
            Dictionary <Pirate, Island> pirateToIsland = new Dictionary <Pirate, Island>();

            for (int i = 0; i < islands.Count; i++)
            {
                Pirate closestPirate = GetClosestPirate(state, islands[i], myPirates);

                //state.Debug($"closest: {closestPirate.Id.ToString()} to island: {islands[i]}");
                if (closestPirate != null)
                {
                    myPirates.Remove(closestPirate);
                    pirateToIsland.Add(closestPirate, islands[i]);
                }
            }

            copyPirates.ForEach(pirate =>
            {
                if (pirateToIsland.ContainsKey(pirate) && pirateToIsland[pirate] != null)
                {
                    Island island = pirateToIsland[pirate];
                    state.Debug($"Pirate {pirate.Id.ToString()} to island {island.Id.ToString()}");
                    List <Direction> movingDirections = state.GetDirections(pirate, island);

                    if (movingDirections.Count > 0 && !pirate.IsLost)
                    {
                        state.Debug($"Pirate: {pirate.Id.ToString()}");
                        movingDirections.ForEach(direc =>
                        {
                            state.Debug($"{direc}");
                        });
                        state.SetSail(pirate, movingDirections[0]);
                    }
                }
                else // Bot that has no island
                {
                    state.Debug($"Nothing {pirate.Id.ToString()}");
                    Island closestIsland = GetClosestIsland(state, pirate, state.NotMyIslands());
                    if (closestIsland != null)
                    {
                        List <Direction> movingDirections = state.GetDirections(pirate, closestIsland);
                        state.SetSail(pirate, movingDirections[0]);
                    }
                }
            });
        }
コード例 #3
0
        }         // calculates the closest powerups to ps[i]

        // can we move the given Pirate to the given Location according to the number of moves?
        // if so --> move it!
        private static int move(PirateContainer p, Location t, int moves, IPirateGame game, bool dontHitEnemies = false)
        {
            if (moves == 0 || (!p.AVALIBLE && p.S != PirateContainer.State.moved) || p.P.Location.Equals(t))
            {
                return(0);
            }

            var X = from l in game.GetSailOptions(p.P, t, moves)
                    where (!QueuedMotion.isOccupied(l, game, dontHitEnemies) && p.move1(l, game, moves))
                    select l;

            if (X.Count() > 0)
            {
                PirateContainer.free.Remove(p);

                Location loc = X.ElementAt(rand.Next(X.Count()));

                game.SetSail(p.P, loc);
                new QueuedMotion(p.P, loc);
                return(game.Distance(p.P, loc));
            }

            game.Debug("Failed to find a move for " + p.P.Id + " to " + t);
            return(0);
        }
コード例 #4
0
 private void TakeAction(IPirateGame game, PirateTactics tactics)
 {
     if (TryDefend(game, tactics.Pirate) == true)
     {
         return;
     }
     if (TryAttack(game, tactics.Pirate) == true)
     {
         return;
     }
     game.SetSail(tactics.Pirate, tactics.TempDestination);
 }
コード例 #5
0
        public void DoTurn(IPirateGame game)
        {
            int reamaining = 6;

            Pirate[] ps = new Pirate[4];
            for (int i = 0; i < 4; i++)
            {
                ps[i] = game.GetMyPirate(i);
            }

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

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

            for (int i = 0; i < 4; i++)
            {
                if (!ps[i].HasTreasure)
                {
                    Treasure cull = null;
                    int      minD = int.MaxValue;

                    foreach (Treasure t in game.Treasures())
                    {
                        if (game.Distance(ps[i], t) < minD)
                        {
                            minD = game.Distance(ps[i], t);
                            cull = t;
                        }
                    }

                    game.SetSail(ps[i], game.GetSailOptions(ps[i], cull, reamaining)[0]);
                    reamaining = 0;
                    break;
                }
            }
        }
コード例 #6
0
 private static bool move(Pirate p, Location t, int moves, IPirateGame game)
 {
     foreach (Location l in game.GetSailOptions(p, t, moves))
     {
         if (!game.IsOccupied(l))
         {
             game.SetSail(p, l);
             return(true);
         }
     }
     game.Debug("Failed to find a move for " + p.Id);
     return(false);
 }
コード例 #7
0
ファイル: YitzhakBot.cs プロジェクト: yitzhaks/MSRulZ
		public int DoTurn(IPirateGame game)
		{
			int movesConsumed = 0;

			var pirates = game.MyPirates().Where(pirate => pirate.Id % 2 == 0).ToArray();

			var firingPirates = new HashSet<Pirate>();
			var firedUponTargets = new HashSet<Pirate>();
			var shootingTuples =
				from pirate in pirates
				from enemy in game.EnemyPiratesWithTreasures()
				where pirate.ReloadTurns == 0
				where pirate.TurnsToSober == 0
				where enemy.TurnsToSober == 0
				where game.Distance(pirate, enemy) <= 4
				select new { Pirate = pirate, Target = enemy };
			if (shootingTuples.Any())
			{
				foreach (var shootingTuple in shootingTuples)
				{
					if (!firingPirates.Contains(shootingTuple.Pirate) && !firedUponTargets.Contains(shootingTuple.Target))
					{
						firingPirates.Add(shootingTuple.Pirate);
						firedUponTargets.Add(shootingTuple.Target);
						game.Attack(shootingTuple.Pirate, shootingTuple.Target);
						movesConsumed++;
					}
				}
			}

			var piratesAndEnemies = pirates.Except(firingPirates).Select(pirate => Tuple.Create(pirate, game.GetEnemyPirate(pirate.Id))).ToList();

			if (piratesAndEnemies.Any())
			{
				// if any pirate needs to move, move only the first pirate
				var movingTuple = piratesAndEnemies.Where(pair => game.Distance(pair.Item1, pair.Item2.InitialLocation) > 2).FirstOrDefault();

				if (movingTuple != null)
				{
					var movingPirate = movingTuple.Item1;
					var enemyHomeBase = movingTuple.Item2.InitialLocation;
					int distance = Math.Min(4, game.Distance(movingPirate, enemyHomeBase) - 2);
					var sailOptions = game.GetSailOptions(movingPirate, enemyHomeBase, distance);
					game.SetSail(movingPirate, sailOptions[random.Next(sailOptions.Count)]);
					movesConsumed += distance;
				}
			}

			return movesConsumed;
		}
コード例 #8
0
        // can we move the given Pirate to the given Location according to the number of moves?
        // if so --> move it!
        private static int move(PirateContainer p, Location t, int moves, IPirateGame game, bool dontHitEnemies = false)
        {
            if (moves == 0 || !p.AVALIBLE || p.P.Location.Equals(t))
            {
                return(0);
            }

            // calculate the best route

            /*foreach (Location l in game.GetSailOptions(p.P, t, moves))
             * {
             *      if (!QueuedMotion.isOccupied(l, game, dontHitEnemies) && p.move(l, game))
             *              return game.Distance(p.P, l);
             * }*/
            var X = from l in game.GetSailOptions(p.P, t, moves)
                    where (!QueuedMotion.isOccupied(l, game, dontHitEnemies) && p.move1(l, game))
                    select l;

            if (X.Count() > 0)
            {
                PirateContainer.free.Remove(p);

                Location loc = X.ElementAt(rand.Next(X.Count()));

                game.SetSail(p.P, loc);
                new QueuedMotion(p.P, loc);
                return(game.Distance(p.P, loc));
            }

            else if (X.Count() == 0)
            {
                if (PirateContainer.GetRemainingMoves() > 2)
                {
                    Location loc = p.P.Location;
                    p.move(loc, game);
                }
            }

            game.Debug("Failed to find a move for " + p.P.Id + " to " + t);
            return(0);
        }
コード例 #9
0
        public bool move(Location l, IPirateGame game)
        {
            if (s != State.none && s != State.treasure)
            {
                game.Debug("State on Pirate " + P.Id + " cannot shift from " + s.ToString() + " to moved!");
                return(false);
            }
            int d = game.Distance(P, l);

            if (d > remainingMoves || (P.HasTreasure && d > 1))
            {
                game.Debug("Pirate " + P.Id + " cannot move, not enough moves!");
                return(false);
            }

            free.Remove(this);
            s = State.moved;
            game.SetSail(P, l);
            new QueuedMotion(P, l);
            return(true);
        }
コード例 #10
0
ファイル: MyBot.cs プロジェクト: yitzhaks/MSRulZ
 private void MoveToBase(IPirateGame game, Pirate pirate)
 {
     game.Debug("Move pirate {0} home", pirate.Id);
     List<Location> possibleLocations = game.GetSailOptions(pirate, pirate.InitialLocation, 1);
     game.SetSail(pirate, possibleLocations[0]);
 }
コード例 #11
0
ファイル: MyBot.cs プロジェクト: yitzhaks/MSRulZ
        private void MoveToTreasure(IPirateGame game, PirateAndCandidate candiadte, int moves)
        {
            if (candiadte.Treasure == null)
            {
                return;
            }

            List<Location> possibleLocations = game.GetSailOptions(candiadte.Pirate, candiadte.Treasure.Location, moves);
            game.Debug("Move pirate {0} to treasure {1} with {2}", candiadte.Pirate.Id, candiadte.Treasure.Id, moves);
            game.SetSail(candiadte.Pirate, possibleLocations[0]);
        }
コード例 #12
0
ファイル: MyBotV2.cs プロジェクト: chananyameth/AnonymouseBot
        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;
                    }
                }
            }
        }