private void ParseWarriors()
 {
     foreach (var player in players)
     {
         player.Warrior = warriorParser.Parse(player.Program);
     }
 }
Example #2
0
        private void Run(string program, string expectedResultMem)
        {
            Console.WriteLine();
            Console.WriteLine(program);
            Console.WriteLine("result:");
            string[] lines        = expectedResultMem.Trim().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();
            string   expectedDump = string.Join("\n", lines);
            Warrior  warrior      = parser.Parse(program);
            var      engine       = new GameEngine(new WarriorStartInfo(warrior, 0));

            engine.Step();
            string dump = engine.Memory.Dump(0, lines.Count());

            Console.WriteLine(dump);
            Assert.AreEqual(expectedDump, dump);
        }
Example #3
0
        public Game([NotNull] ProgramStartInfo[] programStartInfos)
        {
            this.programStartInfos = programStartInfos;

            var r      = new RandomAllocator(Parameters.CoreSize, Parameters.MinWarriorsDistance);
            var parser = new WarriorParser();

            var lastAddress = 0;

            warriors = new List <WarriorStartInfo>();
            foreach (var psi in programStartInfos)
            {
                var warrior = parser.Parse(psi.Program);
                warriors.Add(new WarriorStartInfo(
                                 warrior,
                                 psi.StartAddress.HasValue ? (int)psi.StartAddress : r.NextLoadAddress(lastAddress, warrior.Length)
                                 ));
                lastAddress = warriors.Last().LoadAddress + warriors.Last().Warrior.Length;
            }

            Init();
        }
Example #4
0
        public void TestImp()
        {
            var warrior = parser.Parse(imp);

            Assert.AreEqual(1, warrior.Statements.Count);
            Assert.AreEqual(false, warrior.Statements[0].HasLabel);
            Assert.AreEqual(StatementType.Mov, warrior.Statements[0].Type);
        }