コード例 #1
0
        public void RunCode(string[] firstPlayerCode, string[] secondPlayerCode, string pathToField, GameFinishType finishType, IEnumerable <BLL.Models.Bot> bots1, IEnumerable <BLL.Models.Bot> bots2, int finalX = 0, int finalY = 0)
        {
            CompilationResult compResult1 = compiler.CompileCode(TaskParameters.Build(firstPlayerCode.Length), firstPlayerCode);
            CompilationResult compResult2 = compiler.CompileCode(TaskParameters.Build(secondPlayerCode.Length), secondPlayerCode);

            if (!compResult1.IsCodeCorrect || !compResult2.IsCodeCorrect)
            {
                throw new ArgumentException("Unable to compile code");
            }

            FieldBuilder fieldBuilder = new FieldBuilder(pathToField);

            Runner.CodeRunners.Models.Field field = fieldBuilder.GetFieldForRunner();
            field = fieldBuilder.PlaceBots(field, bots1.Select(b => new Models.Bot(b.X, b.Y, b.Name)), 1);
            field = fieldBuilder.PlaceBots(field, bots2.Select(b => new Models.Bot(b.X, b.Y, b.Name)), 2);

            FinishGameCondition finishCondition = null;

            if (finishType == GameFinishType.CommandsNumber)
            {
                finishCondition = new CommandNumberCondition();
            }
            else
            {
                finishCondition = new BotOnPointCondition(finalX, finalY);
            }

            IEnumerable <Runner.CodeRunners.Models.Bot> runnerBots1 = bots1.Select(mapper.Map <Runner.CodeRunners.Models.Bot>);
            IEnumerable <Runner.CodeRunners.Models.Bot> runnerBots2 = bots2.Select(mapper.Map <Runner.CodeRunners.Models.Bot>);

            runner.RunCodeGame(compResult1.InformationForCodeRunner, compResult2.InformationForCodeRunner, field, runnerBots1, runnerBots2, finishCondition);

            runner.GameFinished += Runner_GameFinished;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Unnamed1984/BotsChallenge
        private static Field getRealField()
        {
            FieldBuilder builder = new FieldBuilder(@"D:\Projects\C#\BotsChallenge\Server\BotChallenge\Content\levels\map1.json");

            Field f = builder.GetFieldForRunner();

            f = builder.PlaceBots(f, bots1, 1);

            f = builder.PlaceBots(f, bots2, 2);

            return(f);
        }
コード例 #3
0
        public static void TestJsonLoad()
        {
            FieldBuilder builder = new FieldBuilder(@"D:\Projects\C#\BotsChallenge\Server\BotChallenge\Content\levels\map1.json");

            Field f = builder.GetFieldForRunner();

            f = builder.PlaceBots(f, new List <BotChallenge.BLL.Models.Bot>()
            {
                new BLL.Models.Bot(5, 6, "Bot1"), new BLL.Models.Bot(8, 2, "Bot2")
            }, 1);

            f = builder.PlaceBots(f, new List <BotChallenge.BLL.Models.Bot>()
            {
                new BLL.Models.Bot(9, 6, "Bot1"), new BLL.Models.Bot(8, 7, "Bot2")
            }, 2);

            printField(f);

            Console.ReadKey();
        }