Пример #1
0
        public PlayField(PlayField playField)
        {
            this.GoldAvailableForAttack = playField.GoldAvailableForAttack;
            this.GoldSpentForDefense = playField.GoldSpentForDefense;
            this.ResultScore = playField.ResultScore;
            this.MinesCount = playField.MinesCount;

            for (int x = 0; x < PlayFieldSize; x++)
            {
                for (int y = 0; y < PlayFieldSize; y++)
                {
                    this[x, y] = new DefenseUnit(playField[x, y].Type, playField[x, y].Count);
                }
            }

            for (int x = 0; x < PlayFieldSize; x++)
            {
                for (int y = 0; y < PlayFieldSize; y++)
                {
                    for (int z = 0; z <= MaxBombRadius; z++)
                    {
                        this.playFieldBombsScores[y, x, z] = playField.playFieldBombsScores[y, x, z];
                    }
                }
            }
        }
Пример #2
0
        //More pricey chicken.
        static string GetOutputMPC(PlayField playField, Bomb bomb = null)
        {
            //Decide whether to attack with bomb or not and record to output stringbuilder.
            if (bomb != null)
            {
                playField.AttackWithBomb(bomb.X, bomb.Y, bomb.Radius);
                //algoOutput.AppendLine(String.Format("bomb {0} {1} {2}", bomb.Radius, bomb.X, bomb.Y));
            }

            //Evaluate for pigs.
            playField.EvaluatePlayFieldForPigsMPC();

            //Find highest score and attack with pigs and record to output stringbuilder.
            Point bestPigAttackPoint;
            int pigsNeededForDetonation;

            while (playField.GoldAvailableForAttack >= GameRules.PigPrice && playField.ResultScore < playField.GoldSpentForDefense)
            {
                bestPigAttackPoint = playField.GetMostEffectivePigPoint();
                pigsNeededForDetonation = playField.GetPigsNeededForDetonation(bestPigAttackPoint.X, bestPigAttackPoint.Y);
                playField.AttackWithPigsAndEvaluateMPC(bestPigAttackPoint.X, bestPigAttackPoint.Y, pigsNeededForDetonation);
                //algoOutput.AppendLine(String.Format("pigs {0} {1} {2}", pigsNeededForDetonation, bestPigAttackPoint.X, bestPigAttackPoint.Y));
            }

            //Return output stringbuilder variable.
            return playField.PerformedActions.ToString().TrimEnd();
        }
Пример #3
0
        static void Main(string[] args)
        {
            //Some testing.
            DateTime start = DateTime.Now;

            PlayField playField = new PlayField();
            //playField.InsertMine(1, 2);
            //playField.InsertChicken(0, 0, 1);
            //playField.InsertChicken(5, 5, 1);
            //playField.InsertMine(0, 0);

            for (int x = 0; x < playField.Size; x++)
            {
                for (int y = 0; y < playField.Size; y++)
                {
                    playField.InsertChicken(x, y);
                }
            }

            //playField.AttackWithPigs(100, 100, 10);

            playField.AttackWithBomb(50, 50, 50);

            //for (int i = 0; i < 25; i++)
            //{
            //    playField.EvaluatePlayFieldForPigs();
            //}

            playField.EvaluatePlayFieldForBomb();

            playField.EvaluatePlayFieldForPigs();

            //Console.WriteLine(playField.ToString());
            //Console.WriteLine(result);
            //Console.WriteLine(playField.GetPigsScores());

            //for (int i = 0; i < 90; i++)
            //{
            //    playField.AttackWithPigs(5 + i, 5 + i, 7);
            //}

            //Console.WriteLine(playField.GetPigsScores());

            //int[,] testM = {
            //                   {1,2,5,3},
            //                   {8,1,6,2},
            //                   {1,2,1,2}
            //               };

            //MatrixPartialSumsFinder sf = new MatrixPartialSumsFinder(testM);
            //for (int i = 0; i < 400000; i++)
            //{
            //    sf.GetSum(0, 0, 0, 0);
            //}
            //Console.WriteLine(sf.GetSum(-1, -2, -1, 23));

            Console.WriteLine((DateTime.Now - start).TotalMilliseconds);
        }
Пример #4
0
        static int GetResultScore(PlayField playField)
        {
            int resultScore;

            if (playField.MinesCount == 0)
            {
                resultScore = playField.ResultScore * 2;
            }
            else
            {
                resultScore = playField.ResultScore;
            }

            return resultScore;
        }
Пример #5
0
 static void PrintStatistics(PlayField playField)
 {
     Console.WriteLine("Printing statistics for a playField object: ------------");
     Console.WriteLine("GoldForAttack: {0}", playField.GoldAvailableForAttack);
     Console.WriteLine("GoldForDefense: {0}", playField.GoldSpentForDefense);
     if (playField.MinesCount == 0)
     {
         Console.WriteLine("Result Gold: {0}", playField.ResultScore * 2);
     }
     else
     {
         Console.WriteLine("Result Gold: {0}", playField.ResultScore);
     }
     Console.WriteLine();
 }
Пример #6
0
        static void Main(string[] args)
        {
            PlayField playFieldMaster = new PlayField();

            //Read input.
            InputReader[] commands = GetInput();

            //DateTime start = DateTime.Now;

            if (commands.Length == 0)
            {
                return;
            }

            //Execute commands from input.
            for (int current = 0; current < commands.Length; current++)
            {
                playFieldMaster.InsertDefenseUnit(commands[current].X, commands[current].Y, commands[current].UnitType, commands[current].UnitCount);
            }

            //Evaluate for bomb.
            playFieldMaster.EvaluatePlayFieldForBomb();
            //Console.WriteLine("Bomb scores:");
            //Console.WriteLine(playField.GetBombsScores(2));
            //Console.WriteLine();

            //Console.WriteLine(playFieldMaster.ToString());

            PlayField playFieldBranchPc = new PlayField(playFieldMaster);
            PlayField playFieldBranchMpc = new PlayField(playFieldMaster);
            PlayField playFieldBranchRel = new PlayField(playFieldMaster);
            PlayField playFieldBranchRelPc = new PlayField(playFieldMaster);
            PlayField playFieldBranchRelMpc = new PlayField(playFieldMaster);
            PlayField playFieldBranchNb = new PlayField(playFieldMaster);
            PlayField playFieldBranchNbPc = new PlayField(playFieldMaster);
            PlayField playFieldBranchNbMpc = new PlayField(playFieldMaster);

            //Find highest score for bomb.
            Bomb bombGreedy = playFieldMaster.GetMostEffectiveBombGreedy();
            Bomb bombRelative = playFieldBranchRel.GetMostEffectiveBombRelative();

            GetOutput(playFieldMaster, bombGreedy);
            GetOutputPC(playFieldBranchPc, bombGreedy);
            GetOutputMPC(playFieldBranchMpc, bombGreedy);
            GetOutput(playFieldBranchRel, bombRelative);
            GetOutputPC(playFieldBranchRelPc, bombRelative);
            GetOutputMPC(playFieldBranchRelMpc, bombRelative);
            GetOutput(playFieldBranchNb);
            GetOutputPC(playFieldBranchNbPc);
            GetOutputMPC(playFieldBranchNbMpc);

            //Console.WriteLine(GetOutput(playFieldMaster, bombGreedy));
            //PrintStatistics(playFieldMaster);

            //Console.WriteLine(GetOutputPC(playFieldBranchPc, bombGreedy));
            //PrintStatistics(playFieldBranchPc);

            //Console.WriteLine(GetOutputMPC(playFieldBranchMpc, bombGreedy));
            //PrintStatistics(playFieldBranchMpc);

            //Console.WriteLine(GetOutput(playFieldBranchRel, bombRelative));
            //PrintStatistics(playFieldBranchRel);

            //Console.WriteLine(GetOutputPC(playFieldBranchRelPc, bombRelative));
            //PrintStatistics(playFieldBranchRelPc);

            //Console.WriteLine(GetOutputMPC(playFieldBranchRelMpc, bombRelative));
            //PrintStatistics(playFieldBranchRelMpc);

            //Console.WriteLine(GetOutput(playFieldBranchNb));
            //PrintStatistics(playFieldBranchNb);

            //Console.WriteLine(GetOutputPC(playFieldBranchNbPc));
            //PrintStatistics(playFieldBranchNbPc);

            //Console.WriteLine(GetOutputMPC(playFieldBranchNbMpc));
            //PrintStatistics(playFieldBranchNbMpc);

            Console.WriteLine(GetMaxScoreOutput(playFieldMaster, playFieldBranchPc, playFieldBranchMpc,
                                                playFieldBranchRel, playFieldBranchRelPc, playFieldBranchRelMpc,
                                                playFieldBranchNb, playFieldBranchNbPc, playFieldBranchNbMpc));

            //Console.WriteLine("Time data: {0} ms", (DateTime.Now - start).TotalMilliseconds);
        }