예제 #1
0
        internal void PlayGame()
        {
            GameFactory(_set);

            while (!Game.IsFinished())
            {
                //TODO: Use dependancy injection container to inject IRallyAllocator to RallyManager
                IRallyAllocator rallyAllocator = new RandomAllocator();
                RallyManager = new RallyManager(rallyAllocator, Game);
                RallyManager.PlayRally();
            }

            _set.Games.Add(Game);
            Game.Winner = Game.Rallies.Last().Winner;
            Game.Score  = Game.Set.GetCurrentGameScore();
        }
예제 #2
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();
        }