public static ErrorCode UploadReplay(MatchReplay replay, Guid gameID) { try { Guid replayID = Guid.NewGuid(); string uniqueBlobName = string.Format("{0}", replayID.ToString()); CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName); blob.UploadByteArray(SerializationHelper.Serialize(replay)); Game game = (from g in db.Game where g.Game_ID == gameID select g).FirstOrDefault <Game>(); game.Replay = uniqueBlobName; //if(replay.WinnerTeam == Guid.Empty) //{ // db.AddToTeams(Team.CreateTeam(replay.WinnerTeam, gameID)); //} db.AddToGameDetails(GameDetails.CreateGameDetails(gameID, (int)replay.Steps, replay.WinnerTeam)); db.SaveChanges(); return(new ErrorCode(ErrorType.Ok, "Replay has been uploaded.")); } catch (Exception e) { return(new ErrorCode(ErrorType.DataBaseProblems, "Blob problems: \n" + e.ToString())); } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override async void OnNavigatedTo(NavigationEventArgs e) { try { /*_localFolder = KnownFolders.DocumentsLibrary; * * MatchReplay replay; * * using (Stream s = await _localFolder.OpenStreamForReadAsync("replay.out")) * { * var serializer = new DataContractSerializer(typeof(MatchReplay)); * replay = serializer.ReadObject(s) as MatchReplay; * }*/ var locator = new ServiceLocator(); MatchReplay replay = locator.Rep.Data; ReplayDescription rD = locator.RepDesc; ReplayName.Text += rD.Name; _worldParams = replay.Events.OfType <SystemEventWorldCreated>().First(); _worldWidth = _worldParams.Width; _worldHeight = _worldParams.Height; _turns = MakeTurns(replay.Events); } catch (Exception ex) { } }
/// <summary> ///Высчитывание и вывод истории матча при заданных командах интеллектов. /// </summary> /// <param name="listIntellect">Список для загрузки всех интеллектов командами.</param> public Computer(IEnumerable <TeamIntellectList> listIntellect) { _objects = new List <Being>(); _actions = new List <GameAction>(); _eventsHistory = new MatchReplay(); _turnNumber = 0; _world = new World(); var _mapGenerator = new MapGenerator(_world.Width); //Переписать весь класс для создания прямоугольных миров _mapGenerator.Generate(100.0f, 5); //100 энергии максимально в клетке for (int i = 0; i < _world.Width; i++) { for (int j = 0; j < _world.Height; j++) { _world[i, j].Ci = _mapGenerator._map[i, j]; } } int c = 5; //Константа площади начального расположения, не знаю, куда её запихнуть int minDist = c * 2; // минимально возможное расстояние между стойбищами при генерации var center = new List <Tuple <int, int> >(); for (int i = 0; i < _world.Width; i++) { for (int j = 0; j < _world.Height; j++) { center.Add(new Tuple <int, int>(i, j)); } } RandomShuffle(center); _eventsHistory.Events.Add(new SystemEventWorldCreated(_world.Width, _world.Height)); _eventsHistory.Events.Add(new SystemEventTurnStarted(_turnNumber)); //Записываем в историю начало хода. int curNum = 0; foreach (TeamIntellectList team in listIntellect) { while (curNum < center.Count) { for (int i = 0; i < curNum; i++) { if (Math.Abs(center[i].Item1 - center[curNum].Item1) + Math.Abs(center[i].Item2 - center[curNum].Item2) < minDist) { continue; } } curNum++; break; } if (curNum == center.Count) { throw new Exception(); } int center_x = center[curNum].Item1, center_y = center[curNum].Item2; List <Tuple <int, int> > pos = new List <Tuple <int, int> >(); for (int i = -c / 2; i <= c / 2; i++) { for (int j = -c / 2; j < c / 2; j++) { pos.Add(new Tuple <int, int>(i + center_x, j + center_y)); } } RandomShuffle(pos); for (int i = 0; i < team.Members.Count; i++) { if (team.Members[i] == null) { continue; } var newBeing = new Being(team.Members[i]); newBeing.Construct(0, 100); //На рождение начального существа даётся 100 энергии. if (100 >= newBeing.Characteristics.Cost()) //Проверка, можно ли создать начальное существо с такими характеристиками { newBeing.Characteristics.Team = team.TeamId; newBeing.Characteristics.X = pos[i].Item1; newBeing.Characteristics.Y = pos[i].Item2; _world[pos[i].Item1, pos[i].Item2].BeingValue = newBeing; _objects.Add(newBeing); _eventsHistory.Events.Add(new GameEventBirth(newBeing.Characteristics.Id, newBeing.Characteristics));//Рождение записываем в историю. } } curNum++; } _turnNumber++; }