Beispiel #1
0
 public static List <Pirate> PiratesWithTask(TaskType t) => (from tuple in Main.tasks.Where(pair => pair.Value.Item1 == t) select game.GetMyPirateById(tuple.Key)).ToList();
        //--------------------------------------------


        public void DoTurn(PirateGame game)
        {
            Main.game = game;

            ///*
            game.Debug("Kol od baleivav penimah");
            game.Debug("Nefesh Yehudi homiyah,");
            game.Debug("Ul(e)faatei mizrach kadimah,");
            game.Debug("Ayin leTziyon tzofiyah;");
            game.Debug("");
            game.Debug("Od lo avdah tikvateinu,");
            game.Debug("Hatikvah bat sh(e)not alpayim,");
            game.Debug("Lihyot am chofshi b(e)artzeinu,");
            game.Debug("Eretz-Tziyon virushalayim.");
            game.Debug("");
            //*/

            if (goStick.Any() && !game.GetMyPirateById(goStick.First().Id).IsAlive())
            {
                goStick.Clear();
            }

            // Clearing objects
            didTurn.Clear();
            sailToworm.Clear();
            capsulesTargetted.Clear();
            asteroidsPushed.Clear();
            piratesPushed.Clear();
            wormsPushed.Clear();

            // Gettings the mines
            if (game.GetMyCapsules().Any() && game.Turn == 1)
            {
                game.GetMyCapsules().Where(cap => cap.Holder == null && !mines.Contains(cap.Location)).ToList().ForEach(cap => mines.Add(cap.Location));
            }

            if (game.GetEnemyCapsules().Any() && game.Turn == 1)
            {
                game.GetEnemyCapsules().Where(cap => cap.Holder == null && !enemyMines.Contains(cap.Location)).ToList().ForEach(cap => enemyMines.Add(cap.Location));
            }

            unemployedPirates = game.GetMyLivingPirates().ToList();
            HandTasks();

            foreach (Pirate pirate in game.GetMyLivingPirates().Where(p => p.StateName != game.STATE_NAME_HEAVY).OrderByDescending(p => tasks[p.Id].Item2.HeavyWeight()))
            {
                if (tasks[pirate.Id].Item2.HeavyWeight() <= 0)
                {
                    break;
                }

                var switchWith = game.GetMyLivingPirates().Where(p => p.Id != pirate.Id &&
                                                                 tasks[p.Id].Item2.HeavyWeight() < tasks[pirate.Id].Item2.HeavyWeight() &&
                                                                 p.StateName == game.STATE_NAME_HEAVY)
                                 .OrderBy(p => tasks[p.Id].Item2.HeavyWeight());

                bool shouldNotSwitch = game.__livingAsteroids.Any(a => pirate.Distance(a) < pirate.MaxSpeed * 5) || game.GetEnemyLivingPirates().Any(e => pirate.Distance(e) < pirate.MaxSpeed * 3.5);

                if (shouldNotSwitch)
                {
                    break;
                }

                if (switchWith.Any() && pirate.StateName != game.STATE_NAME_HEAVY)
                {
                    switchWith.First().SwapStates(pirate);
                    didTurn.Add(switchWith.First().Id);
                    break;
                }
            }

            foreach (KeyValuePair <int, Tuple <TaskType, Task> > pair in tasks.OrderByDescending(pair => pair.Value.Item2.Priority()))
            {
                try {
                    var preform = pair.Value.Item2.Preform();

                    if (debug)
                    {
                        game.Debug(preform);
                    }
                } catch (System.Exception e) {
                    game.Debug(e.Message);
                }
            }

            if (stopStick == true)
            {
                Main.goStick.Clear();
            }
        }