private static string GetMatchAsString(MatchGroup match) { var sb = new StringBuilder(); MatchUtils.AppendMatchToStringBuilder(sb, match); return(sb.ToString()); }
private static int AddPlayerToMatch(int playersAdded, MatchGroup match, TempAccumulator accumulator, Player player) { MatchUtils.UpdateMatchCounters(accumulator, player); playersAdded++; match.Players.Add(player); return(playersAdded); }
private static void CreateMatch(Queue <Player> queue, IHostingEnvironment hostingEnvironment) { int playersAdded = 0; var match = new MatchGroup(); var accumulator = new TempAccumulator(); // 1) Add players from priority queue (if any) while (playersAdded < playersPerMatch && topPriorityQueue.Count > 0) { var player = topPriorityQueue.Dequeue(); playersAdded = AddPlayerToMatch(playersAdded, match, accumulator, player); } // 2) Add players from proper queue while (playersAdded < playersPerMatch) { var player = queue.Dequeue(); playersAdded = AddPlayerToMatch(playersAdded, match, accumulator, player); } MatchUtils.UpdateMatchStats(accumulator, match, playersAdded, currentMatchNumber); matches.Add(match); WriteMatchToFile(match, hostingEnvironment); currentMatchNumber++; }
//刷新玩家 public void RefreshMatchPlayerInfo(bool isRefresh, bool resetIndex) { if (!isRefresh) { //从副本(除战神赛)中回到主城不需要刷新拼配伙伴 if (m_CurrentChallengeGroupIndex > 0 && m_CurrentChallengeGroupIndex <= 3) { m_CurrentChallengeGroupIndex--; } } if (resetIndex) { m_CurrentChallengeGroupIndex = 0; //从服务器取的新数据 } if (m_CurrentChallengeGroupIndex == 3) { //缓存数据已更新完 需要重新发送消息更新缓存数据 LogicSystem.EventChannelForGfx.Publish("ge_ui_connect_hint", "ui", true, true); m_CurrentChallengeGroupIndex = 0; LogicSystem.PublishLogicEvent("query_match_group", "arena"); return; } else { RoleInfo role_info = LobbyClient.Instance.CurrentRole; if (role_info != null && role_info.ArenaStateInfo != null) { ArenaStateInfo arena_info = role_info.ArenaStateInfo; if (m_CurrentChallengeGroupIndex < arena_info.MatchGroups.Count) { //默认arena_info.MatchGroups一直顺序存放着数据且数据正确 MatchGroup match_group = arena_info.MatchGroups[m_CurrentChallengeGroupIndex]; if (match_group == null) { return; } if (arenaPlayerArr.Length == 3) { if (arenaPlayerArr[0] != null) { arenaPlayerArr[0].InitPlayerInfo(match_group.One); } if (arenaPlayerArr[1] != null) { arenaPlayerArr[1].InitPlayerInfo(match_group.Two); } if (arenaPlayerArr[2] != null) { arenaPlayerArr[2].InitPlayerInfo(match_group.Three); } } } m_CurrentChallengeGroupIndex++; } } }
private static void WriteMatchToFile(MatchGroup match, IHostingEnvironment hostingEnvironment) { // The file gets temporarily saved into application directory string path = hostingEnvironment.ContentRootPath + "/ongoing_match_grouping.txt"; using (var tw = new StreamWriter(path, true)) { tw.WriteLine(GetMatchAsString(match)); } }
internal static void UpdateMatchStats(TempAccumulator accum, MatchGroup match, int playersAdded, int currentMatchNumber) { match.MinSkillIndex = accum.minSkill; match.MaxSkillIndex = accum.maxSkill; match.AvgSkillIndex = accum.accumSkill / playersAdded; match.MinRemotenessIndex = accum.minRemoteness; match.MaxRemotenessIndex = accum.maxRemoteness; match.AvgRemotenessIndex = accum.accumRemoteness / playersAdded; match.MinWaitingTime = accum.minWaitingTime; match.MaxWaitingTime = accum.maxWaitingTime; match.AvgWaitingTime = accum.accumWaitingTime / playersAdded; match.MatchNumber = currentMatchNumber; match.NumberOfPlayers = playersAdded; }
public NiTriShapeData(NiFile niFile) : base(niFile) { var indexCount = niFile.Reader.ReadInt32(); Mesh.triangles = niFile.Reader.ReadTriangles(indexCount); matchGroupCount = niFile.Reader.ReadInt16(); matchGroups = new MatchGroup[matchGroupCount]; for (var i = 0; i < matchGroups.Length; i++) { matchGroups[i] = new MatchGroup(niFile.Reader); } }
//请求玩家匹配数据 private void QueryMatchGroup() { RoleInfo role_info = LobbyClient.Instance.CurrentRole; if (role_info != null && role_info.ArenaStateInfo != null) { if (role_info.ArenaStateInfo.IsNeedQueryMatchGroup()) { UIDataCache.Instance.curPlayerFightingScore = role_info.FightingScore; LogicSystem.EventChannelForGfx.Publish("ge_ui_connect_hint", "ui", true, true); LogicSystem.PublishLogicEvent("query_match_group", "arena"); return; } ArenaStateInfo arena_info = role_info.ArenaStateInfo; if (arena_info.MatchGroups.Count <= 0) { LogicSystem.EventChannelForGfx.Publish("ge_ui_connect_hint", "ui", true, true); LogicSystem.PublishLogicEvent("query_match_group", "arena"); return; } MatchGroup match_group = arena_info.MatchGroups[0]; if (match_group == null) { LogicSystem.EventChannelForGfx.Publish("ge_ui_connect_hint", "ui", true, true); LogicSystem.PublishLogicEvent("query_match_group", "arena"); return; } if (match_group != null && match_group.One == null) { LogicSystem.EventChannelForGfx.Publish("ge_ui_connect_hint", "ui", true, true); LogicSystem.PublishLogicEvent("query_match_group", "arena"); return; } } //打完战神赛需要刷新一次 bool needRefresh = (UIDataCache.Instance.prevSceneType == SceneSubTypeEnum.TYPE_PVAP); if (uiPartnerPvpRightInfo != null) { uiPartnerPvpRightInfo.RefreshMatchPlayerInfo(needRefresh, false); } }
internal static void AppendMatchToStringBuilder(StringBuilder sb, MatchGroup group) { sb.AppendLine($"~===== Match {group.MatchNumber} =====~"); sb.AppendLine($"Number of players: {group.NumberOfPlayers}"); sb.AppendLine($"Min. skill index: {group.MinSkillIndex}"); sb.AppendLine($"Max. skill index: {group.MaxSkillIndex}"); sb.AppendLine($"Avg. skill index: {group.AvgSkillIndex}"); sb.AppendLine($"Min. remoteness index: {group.MinRemotenessIndex}"); sb.AppendLine($"Max. remoteness index: {group.MaxRemotenessIndex}"); sb.AppendLine($"Avg. remoteness index: {group.AvgRemotenessIndex}"); sb.AppendLine($"Min. waiting time: {group.MinWaitingTime} ms"); sb.AppendLine($"Max. waiting time: {group.MaxWaitingTime} ms"); sb.AppendLine($"Avg. waiting time: {group.AvgWaitingTime} ms"); // TODO: Also print players in each match group? sb.AppendLine(); }
/// <summary> /// (Recursivo) Construye y guarda en la instancia XElement pasada como parámetro /// el árbol de condiciones completo de una condición /// </summary> /// <param name="matchGroup"> /// grupo de condiciones sobre el que empezar a construir el árbol, normalmente es el raíz /// </param> /// <param name="rulesElement"> /// XElement donde se almacenará el árbol de condiciones completo de la condición /// </param> /// <returns>el árbol de condiciones completo de una condición</returns> private static XElement CreateXmlConditionRules(MatchGroup matchGroup, XElement rulesElement) { // Escribimos las condiciones del grupo actual foreach (var match in matchGroup.Matches) { var matchElement = new XElement("Match", match.Text); matchElement.SetAttributeValue("Operator", Operator.GetOperatorInternalName(match.ConditionalOperator)); rulesElement.Add(matchElement); } if (matchGroup.ChildMatchGroups == null) { return(rulesElement); } // Escribimos los grupos de condiciones hijos del grupo de condiciones actual foreach (var childMatchGroup in matchGroup.ChildMatchGroups) { var matchGroupElementName = childMatchGroup is OrMatchGroup ? "OrGroup" : childMatchGroup is AndMatchGroup ? "AndGroup" : null; if (matchGroupElementName == null) { continue; } var matchGroupElement = new XElement(matchGroupElementName); matchGroupElement = CreateXmlConditionRules(childMatchGroup, matchGroupElement); rulesElement.Add(matchGroupElement); } return(rulesElement); }
private async void ExtractDirbResult(ScanRequest request) { DirectoryInfo outputDirectoryInfo = new DirectoryInfo(_possibleScans.ScanOuputLocation); var requestDirectoryInfo = outputDirectoryInfo.GetDirectories() .FirstOrDefault(x => x.Name == request.Id.ToString()); if (requestDirectoryInfo == null || !requestDirectoryInfo.Exists) { return; } var nmapDirectoryInfo = requestDirectoryInfo.GetDirectories().FirstOrDefault(x => x.Name == "secsoul_dirb"); if (nmapDirectoryInfo == null || !nmapDirectoryInfo.Exists) { return; } var filesDirectoryInfo = nmapDirectoryInfo.GetDirectories().FirstOrDefault(); if (filesDirectoryInfo == null || !filesDirectoryInfo.Exists) { return; } var resultFile = filesDirectoryInfo.GetFiles().FirstOrDefault(); if (resultFile == null || !resultFile.Exists) { return; } using (var st = new StreamReader(resultFile.FullName)) { var regxDir = new Regex("^==> DIRECTORY: (.+)$"); var regxPage = new Regex("^\\+ (.+?) \\(CODE:([0-9]+)"); string line; while ((line = st.ReadLine()) != null) { var matchDir = regxDir.Match(line); var matchPage = regxPage.Match(line); if (matchDir.Success) { var matchGroup = matchDir.Groups[1]; request.ScanDirb.Add(new ScanDirb() { IsDirectory = true, FoundUrl = matchGroup.Value }); continue; } if (matchPage.Success) { var matchGroup = matchPage.Groups[1]; var matchStatus = matchPage.Groups[2]; request.ScanDirb.Add(new ScanDirb() { IsDirectory = false, FoundUrl = matchGroup.Value, HttpStatus = matchStatus.Value }); //_logger.LogInformation(matchGroup.Value); } } } var content = File.ReadAllText(resultFile.FullName); var regxListable = new Regex( "---- Entering directory: (.+) ----\n\\(!\\) WARNING: Directory IS LISTABLE. No need to scan it."); var regexMatches = regxListable.Matches(content); foreach (Match regexMatch in regexMatches) { foreach (var MatchGroup in regexMatch.Groups) { var foundDir = request.ScanDirb.Where(x => x.IsDirectory) .FirstOrDefault(x => x.FoundUrl == MatchGroup.ToString()); if (foundDir != null) { foundDir.IsListable = true; } } } }
// go through the board and analyze all the tiles, looking for matches private void UpdateMatches() { // match groups are being updated so they're no longer dirty matchGroupsAreDirty = false; // since sliding columns/rows can mess up everything, we need to get rid of the old match groups and start over. // keep in mind there's probably a way to use the algorithm where we don't have to get rid of all the matches and // start over every time (say, just update the matches that are disrupted by a shift), but that can come later if // you need to improve performance foreach (MatchGroup matchGroup in matchGroups) matchGroup.Destroy(); matchGroups.Clear(); // we'll start analyzing the board from the bottom left tile. the current base tile will be the one // that we are currently starting from and building match groups off of. LineTile currentBaseTile = tileMap[0][0]; List<LineTile> tileSurrounders; // variable that will store surrounding tiles of various base tiles List<LineTile> checkedTiles = new List<LineTile>(); // we'll store base tiles here once they've been analyzed so we don't reanalyze them MatchGroup currentMatchGroup; // the match group we're analyzing that includes the current base tile // loop continuously through the board, making match groups until there are no more tiles to make match groups from while (currentBaseTile != null) { // create a new match group, add the current base tile as its first tile currentMatchGroup = new MatchGroup(); currentMatchGroup.tiles.Add(currentBaseTile); // loop through the tiles starting on the current base tile, analyze their connections, find a new base tile, // and loop again, and so on until you find no more possible connections any of the tiles in the match group bool stillWorkingOnMatchGroup = true; while (stillWorkingOnMatchGroup) { // populate the tileSurrounders list with all the tiles surrounding the current base tile tileSurrounders = GetTilesSurroundingTile(currentBaseTile); // iterate through all the surrounding tiles and check if their solid sides are aligned with the base tile's solid sides foreach (LineTile surroundingTile in tileSurrounders) { TileConnectionType connectionType = TileConnectionTypeBetweenTiles(currentBaseTile, surroundingTile); // if there's a solid match, add the surrounder to the match group. // if there's a mismatch, the matchgroup is not a perfect "closed" match group. // if there's a mismatch because of an open side of the base tile, that doesn't actually matter // since there's not a solid side being cut off (this is called TileConnectionType.ValidWithOpenSide) if (connectionType == TileConnectionType.ValidWithSolidMatch) currentMatchGroup.tiles.Add(surroundingTile); else if (TileConnectionTypeBetweenTiles(currentBaseTile, surroundingTile) == TileConnectionType.Invalid) currentMatchGroup.isClosed = false; } // if the base tile has a closed/solid side that touches the edge of the board, the match group can't be closed if (((currentBaseTile.bitmask & LineTile.kBitmaskTop) != 0 && currentBaseTile.tileIndex.yIndex == tileMapHeight - 1) || ((currentBaseTile.bitmask & LineTile.kBitmaskRight) != 0 && currentBaseTile.tileIndex.xIndex == tileMapWidth - 1) || ((currentBaseTile.bitmask & LineTile.kBitmaskBottom) != 0 && currentBaseTile.tileIndex.yIndex == 0) || ((currentBaseTile.bitmask & LineTile.kBitmaskLeft) != 0 && currentBaseTile.tileIndex.xIndex == 0)) currentMatchGroup.isClosed = false; // add our base tile to an array so we don't check it again later if (!checkedTiles.Contains(currentBaseTile)) checkedTiles.Add(currentBaseTile); // find a new base tile that we've added to the match gropu but haven't analyzed yet for (int i = 0; i < currentMatchGroup.tiles.Count; i++) { LineTile tile = currentMatchGroup.tiles[i]; // if the checkedTiles array has the tile in it already, check to see if we're on the last // tile in the match group. if we are, then there are no more base tile possibilities so // done with the match group. if checkedTiles DOESN'T have a tile in the array, it means // that tile is in the match group but hasn't been analyzed yet, so we need to set it as // the next base tile. if (checkedTiles.Contains(tile)) { if (i == currentMatchGroup.tiles.Count - 1) { stillWorkingOnMatchGroup = false; matchGroups.Add(currentMatchGroup); } } else { currentBaseTile = tile; break; } } } // we're done with a match group, so now we need to find a new un-analyzed tile that's // not in any match groups to start a new one off of. so we'll set currentBaseTile to // null then see if we can find a new one. currentBaseTile = null; for (int i = 0; i < tileMapWidth; i++) { for (int j = 0; j < tileMapHeight; j++) { LineTile newTile = tileMap[i][j]; if (!TileIsAlreadyInMatchGroup(newTile)) { currentBaseTile = newTile; break; } } if (currentBaseTile != null) break; } } }
// go through the board and analyze all the tiles, looking for matches private void UpdateMatches() { // match groups are being updated so they're no longer dirty matchGroupsAreDirty = false; // since sliding columns/rows can mess up everything, we need to get rid of the old match groups and start over. // keep in mind there's probably a way to use the algorithm where we don't have to get rid of all the matches and // start over every time (say, just update the matches that are disrupted by a shift), but that can come later if // you need to improve performance foreach (MatchGroup matchGroup in matchGroups) { matchGroup.Destroy(); } matchGroups.Clear(); // we'll start analyzing the board from the bottom left tile. the current base tile will be the one // that we are currently starting from and building match groups off of. LineTile currentBaseTile = tileMap[0][0]; List <LineTile> tileSurrounders; // variable that will store surrounding tiles of various base tiles List <LineTile> checkedTiles = new List <LineTile>(); // we'll store base tiles here once they've been analyzed so we don't reanalyze them MatchGroup currentMatchGroup; // the match group we're analyzing that includes the current base tile // loop continuously through the board, making match groups until there are no more tiles to make match groups from while (currentBaseTile != null) { // create a new match group, add the current base tile as its first tile currentMatchGroup = new MatchGroup(); currentMatchGroup.tiles.Add(currentBaseTile); // loop through the tiles starting on the current base tile, analyze their connections, find a new base tile, // and loop again, and so on until you find no more possible connections any of the tiles in the match group bool stillWorkingOnMatchGroup = true; while (stillWorkingOnMatchGroup) { // populate the tileSurrounders list with all the tiles surrounding the current base tile tileSurrounders = GetTilesSurroundingTile(currentBaseTile); // iterate through all the surrounding tiles and check if their solid sides are aligned with the base tile's solid sides foreach (LineTile surroundingTile in tileSurrounders) { TileConnectionType connectionType = TileConnectionTypeBetweenTiles(currentBaseTile, surroundingTile); // if there's a solid match, add the surrounder to the match group. // if there's a mismatch, the matchgroup is not a perfect "closed" match group. // if there's a mismatch because of an open side of the base tile, that doesn't actually matter // since there's not a solid side being cut off (this is called TileConnectionType.ValidWithOpenSide) if (connectionType == TileConnectionType.ValidWithSolidMatch) { currentMatchGroup.tiles.Add(surroundingTile); } else if (TileConnectionTypeBetweenTiles(currentBaseTile, surroundingTile) == TileConnectionType.Invalid) { currentMatchGroup.isClosed = false; } } // if the base tile has a closed/solid side that touches the edge of the board, the match group can't be closed if (((currentBaseTile.bitmask & LineTile.kBitmaskTop) != 0 && currentBaseTile.tileIndex.yIndex == tileMapHeight - 1) || ((currentBaseTile.bitmask & LineTile.kBitmaskRight) != 0 && currentBaseTile.tileIndex.xIndex == tileMapWidth - 1) || ((currentBaseTile.bitmask & LineTile.kBitmaskBottom) != 0 && currentBaseTile.tileIndex.yIndex == 0) || ((currentBaseTile.bitmask & LineTile.kBitmaskLeft) != 0 && currentBaseTile.tileIndex.xIndex == 0)) { currentMatchGroup.isClosed = false; } // add our base tile to an array so we don't check it again later if (!checkedTiles.Contains(currentBaseTile)) { checkedTiles.Add(currentBaseTile); } // find a new base tile that we've added to the match gropu but haven't analyzed yet for (int i = 0; i < currentMatchGroup.tiles.Count; i++) { LineTile tile = currentMatchGroup.tiles[i]; // if the checkedTiles array has the tile in it already, check to see if we're on the last // tile in the match group. if we are, then there are no more base tile possibilities so // done with the match group. if checkedTiles DOESN'T have a tile in the array, it means // that tile is in the match group but hasn't been analyzed yet, so we need to set it as // the next base tile. if (checkedTiles.Contains(tile)) { if (i == currentMatchGroup.tiles.Count - 1) { stillWorkingOnMatchGroup = false; matchGroups.Add(currentMatchGroup); } } else { currentBaseTile = tile; break; } } } // we're done with a match group, so now we need to find a new un-analyzed tile that's // not in any match groups to start a new one off of. so we'll set currentBaseTile to // null then see if we can find a new one. currentBaseTile = null; for (int i = 0; i < tileMapWidth; i++) { for (int j = 0; j < tileMapHeight; j++) { LineTile newTile = tileMap[i][j]; if (!TileIsAlreadyInMatchGroup(newTile)) { currentBaseTile = newTile; break; } } if (currentBaseTile != null) { break; } } } }