private bool ValidarJogada(MatchControl matchControl, MatchMoviment matchMoviment) { MatchMap matchMap = new MatchMap() { X = matchMoviment.Position.x, Y = matchMoviment.Position.y }; foreach (var item in matchControl.GamePositions) { if (item.Value.X.Equals(matchMap.X) && item.Value.Y.Equals(matchMap.Y)) { int key = item.Key; if (item.Value.Player != null) { this.msg = "Campo já foi selecionado em outra rodada"; return(false); } matchControl.GamePositions[key].Player = matchMoviment.Player; break; } } return(true); }
void CalculateAllPlayerRatings(MatchMap map) { /* Any match regardless of team size is getting treated as a 1v1v1v1v1... * In order to calculate the elo changes for a match, each resulting pair of scores for the imaginary 1v1s is created */ double kfactor = 35 / map.scores.Count; //scale kfactor with team size to avoid matches with more players overly affecting rating compared to actual 1v1s - this is currently set on each players' first map. List <Scorepair> scorepairs = new List <Scorepair>(); for (int i = 0; i < map.scores.Count - 1; i++) { for (int j = i + 1; j < map.scores.Count; j++) { scorepairs.Add(new Scorepair(map.scores[i], map.scores[j])); } } //The projected wins (as per Elo-Rating algorithm) have to be calculated for each imaginary 1v1 and added up for each player in the match along with the actual wins foreach (Scorepair pair in scorepairs) { //If one of the player hasn't been initialized yet, do that if (!players.Any(p => p.PlayerID == pair.Score1.PlayerID)) { players.Add(FetchPlayer(pair.Score1.PlayerID, kfactor)); } if (!players.Any(p => p.PlayerID == pair.Score2.PlayerID)) { players.Add(FetchPlayer(pair.Score2.PlayerID, kfactor)); } //get the players of the scorepair from the list of players MatchPlayer p1 = players.Where(p => p.PlayerID == pair.Score1.PlayerID).ToList().First(); MatchPlayer p2 = players.Where(p => p.PlayerID == pair.Score2.PlayerID).ToList().First(); //add expected wins, maps played, and actual wins p1.ExpectedWins += (1 / (1 + Math.Pow(10, (p2.Elo - p1.Elo) / 400))); p1.MapsPlayed += 1 / ((double)map.scores.Count - 1); p2.ExpectedWins += 1 - (1 / (1 + Math.Pow(10, (p2.Elo - p1.Elo) / 400))); p2.MapsPlayed += 1 / ((double)map.scores.Count - 1); if (pair.Score1.Score > pair.Score2.Score) { p1.ActualWins += 1; } else if (pair.Score2.Score > pair.Score1.Score) { p2.ActualWins += 1; } else { p1.ActualWins += 0.5; p2.ActualWins += 0.5; } } }
internal TokenMatch AddMatch(int index, TokenMatch?match) { if (MatchMap == null || match == null) { return(match !); } if (!MatchMap.TryGetValue(index, out var matches)) { MatchMap[index] = matches = new List <TokenMatch>(); } matches.Add(match); return(match); }
internal void ClearData(int?index = null) { if (MatchMap == null) { return; } if (index is int i) { if (MatchMap.TryGetValue(i, out var matches)) { matches.Clear(); } } else { MatchMap.Clear(); } }
public MirrorCtrl() { m_MatchMap = new MatchMap(); }
void OnEnable() { m_MatchMap = new MatchMap(); }