public async Task<bool> ResolveMatchUp(int matchIndex, string _winner, int scoreWinner = 0, int scoreLoser = 0, List<int> matchList = null) { var matchup = matchUpList[matchIndex]; matchup.winner = _winner; if (matchup.player1 == matchup.winner) { matchup.player1Score = scoreWinner; matchup.player2Score = scoreLoser; matchup.loser = matchup.player2; } else if (matchup.player2 == matchup.winner) { matchup.player1Score = scoreLoser; matchup.player2Score = scoreWinner; matchup.loser = matchup.player1; } else return false; if (matchList != null) matchup.matchList = await GetMatchesFromIndexes(matchList); indexOfUnresolvedMatches.Remove(matchIndex); if (indexOfUnresolvedMatches.Count == 0) tourneyState = TournamentStates.Running; await SaveDataToDb(); return true; }
public async Task<bool> AddPlayer(UserData user) { if (participantList.Exists(u => u.ethAddress == user.id)) return false; if (maxPlayers == -1 || participantList.Count < maxPlayers) { var participant = new ParticipantData(user); participantList.Add(participant); participant.challongeId = await Challonge.ChallongeModule.AddPlayer(challongeId, user.id, user.userName); if (participantList.Count == maxPlayers) tourneyState = TournamentStates.Ready_For_Seeding; await SaveDataToDb(); return true; } else return false; }
public SingleEliminationTournament(int seconds, string creator, int bo, int max, string name) { id = ""; for (int i = 0; i < 15; i++) id += _rand.Next(16).ToString("X"); id = id.ToLower(); creatorAddress = creator; creatorName = name; participantList = new List<ParticipantData>(); tourneyState = TournamentStates.Accepting_Players; secondsBetweenRounds = seconds; boFormat = bo; maxPlayers = max; totalRoundNumber = 0; currentRoundTime = 0; currentRound = 1; matchUpList = new List<MatchUp>(); //matchUpHistoryList = new List<List<MatchUp>>(); indexOfUnresolvedMatches = new List<int>(); winner = ""; }
public void Start() => tourneyState = TournamentStates.Ready_For_Seeding;