Exemplo n.º 1
0
        public void TestLoadingScores()
        {
            var recorded = new List <ScoreAtTime>
            {
                new ScoreAtTime(10, new[] { 10, 20 }),
                new ScoreAtTime(30, new[] { 20, 10 })
            };
            var penalties = new List <Penalty>
            {
                new Penalty
                {
                    Time        = 10,
                    Value       = -10,
                    RobotNumber = 2
                }
            };
            var sl = new ScoreLoader(Copy(recorded), Copy(penalties), 2);
            var scoreCollection = sl.LoadedScoreCollection;

            for (int i = 0; i < 31; i++)
            {
                sl.UpdateScores(i);
                var expectedScores   = recorded.LastOrDefault(x => x.Time <= i);
                var expectedTempSums = (expectedScores != null) ? expectedScores.TempScores : new int[sl.LoadedScoreCollection.RobotCount];

                CollectionAssert.AreEqual(expectedTempSums, new[] { scoreCollection.GetTemp(0), scoreCollection.GetTemp(1) });
                int i1 = i;
                var expectedPenalties = new List <Penalty>(penalties.Where(x => x.Time <= i1));

                CollectionAssert.AreEquivalent(expectedPenalties.Select(x => x.Value),
                                               sl.LoadedScoreCollection.Penalties.Select(x => x.Value));
            }
        }
Exemplo n.º 2
0
        public ReplayPlayer(SerializationRoot serializationRoot)
        {
            _serializationRoot = serializationRoot;
            RootBody = new Body();
            DT = _serializationRoot.DT;
			_objectLoaders = new List<ObjectLoader>(
				_serializationRoot.LoggingObjects
								.Select(x => new ObjectLoader(x, RootBody)));
			_scoreLoader = new ScoreLoader(_serializationRoot.Scores, _serializationRoot.Penalties, _serializationRoot.RobotCountForScores);
        }
Exemplo n.º 3
0
 public ReplayPlayer(SerializationRoot serializationRoot)
 {
     _serializationRoot = serializationRoot;
     RootBody           = new Body();
     DT             = _serializationRoot.DT;
     _objectLoaders = new List <ObjectLoader>(
         _serializationRoot.LoggingObjects
         .Select(x => new ObjectLoader(x, RootBody)));
     _scoreLoader = new ScoreLoader(_serializationRoot.Scores, _serializationRoot.Penalties, _serializationRoot.RobotCountForScores);
 }
Exemplo n.º 4
0
		/// <summary>
		/// Создает новый проигрыватель на основе строки с содержимым реплея
		/// </summary>
		/// <param name="replayContent"> строка с содержимым реплея</param>
		public ReplayPlayer(string replayContent)
		{
			RootBody = new Body();
			const string header = "<Feedback>";
			if(string.Equals(replayContent.Substring(0, header.Length), header, StringComparison.InvariantCultureIgnoreCase))
				replayContent = replayContent.Substring(header.Length, replayContent.Length - header.Length * 2 - 1);
			using(Stream memoryStream = new MemoryStream(Convert.FromBase64String(replayContent)),
						zipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
				_serializationRoot = DeserializeInternal(zipStream);
			DT = _serializationRoot.DT;
			_objectLoaders = new List<ObjectLoader>(
				_serializationRoot.LoggingObjects
								.Select(x => new ObjectLoader(x, RootBody)));
			_scoreLoader = new ScoreLoader(_serializationRoot.Scores, _serializationRoot.Penalties, _serializationRoot.RobotCountForScores);
		}
Exemplo n.º 5
0
        /// <summary>
        /// Создает новый проигрыватель на основе строки с содержимым реплея
        /// </summary>
        /// <param name="replayContent"> строка с содержимым реплея</param>
        public ReplayPlayer(string replayContent)
        {
            RootBody = new Body();
            const string header = "<Feedback>";

            if (string.Equals(replayContent.Substring(0, header.Length), header, StringComparison.InvariantCultureIgnoreCase))
            {
                replayContent = replayContent.Substring(header.Length, replayContent.Length - header.Length * 2 - 1);
            }
            using (Stream memoryStream = new MemoryStream(Convert.FromBase64String(replayContent)),
                   zipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
                _serializationRoot = DeserializeInternal(zipStream);
            DT             = _serializationRoot.DT;
            _objectLoaders = new List <ObjectLoader>(
                _serializationRoot.LoggingObjects
                .Select(x => new ObjectLoader(x, RootBody)));
            _scoreLoader = new ScoreLoader(_serializationRoot.Scores, _serializationRoot.Penalties, _serializationRoot.RobotCountForScores);
        }