public void ChangeStatus(int tour_id, TournamentStatus status) { int st = 0; switch (status) { case TournamentStatus.Registration: st = 1; break; case TournamentStatus.Annonced: st = 2; break; case TournamentStatus.Playing: st = 3; break; case TournamentStatus.Finished: st = 4; break; case TournamentStatus.Canceled: st = 5; break; } api.MakeSQLQueryWithoutResult("UPDATE `tournaments` SET `status` = " + st + " WHERE `tour_id` = " + tour_id); }
// Load tournament state from disk bool LoadTournamentState(string stateFile = "") { if (stateFile != "") { this.stateFile = stateFile; } tournamentState = new TournamentState(); if (tournamentState.LoadState(this.stateFile)) { message = "Tournament state loaded from " + this.stateFile; tournamentID = tournamentState.tournamentID; tournamentType = tournamentState.tournamentType; vesselCount = tournamentState.vesselCount; teamCount = tournamentState.teamCount; teamsPerHeat = tournamentState.teamsPerHeat; vesselsPerTeam = tournamentState.vesselsPerTeam; fullTeams = tournamentState.fullTeams; numberOfRounds = tournamentState.rounds.Count; numberOfHeats = numberOfRounds > 0 ? tournamentState.rounds[0].Count : 0; heatsRemaining = tournamentState.rounds.Select(r => r.Value.Count).Sum() - tournamentState.completed.Select(c => c.Value.Count).Sum(); } else { message = "Failed to load tournament state."; } Debug.Log("[BDATournament]: " + message); // if (BDACompetitionMode.Instance != null) // BDACompetitionMode.Instance.competitionStatus.Add(message); tournamentStatus = heatsRemaining > 0 ? TournamentStatus.Stopped : TournamentStatus.Completed; return(true); }
private void UpdateDropDown(TournamentStatus status, bool inDropDown) { if (inDropDown) { switch (status) { case TournamentStatus.ReadyToStart: _tournamentsDropDownList.AddRange(_readyToStartTournaments); break; case TournamentStatus.InProgress: _tournamentsDropDownList.AddRange(_inProgressTournaments); break; case TournamentStatus.Finished: _tournamentsDropDownList.AddRange(_finishedTournaments); break; default: throw new ArgumentOutOfRangeException(nameof(status), status, null); } } else { foreach (TournamentPreviewModel tournament in _allTournaments) { if (tournament.Status == status) { _tournamentsDropDownList.Remove(tournament); } } } RefreshView(); }
IEnumerator ExecuteHeat(int roundIndex, int heatIndex) { VesselSpawner.Instance.SpawnAllVesselsOnce(tournamentState.rounds[roundIndex][heatIndex]); while (VesselSpawner.Instance.vesselsSpawning) { yield return(new WaitForFixedUpdate()); } if (!VesselSpawner.Instance.vesselSpawnSuccess) { tournamentStatus = TournamentStatus.Stopped; yield break; } yield return(new WaitForFixedUpdate()); // NOTE: runs in separate coroutine if (BDArmorySettings.RUNWAY_PROJECT) { switch (BDArmorySettings.RUNWAY_PROJECT_ROUND) { case 33: BDACompetitionMode.Instance.StartRapidDeployment(0); break; default: BDACompetitionMode.Instance.StartCompetitionMode(BDArmorySettings.COMPETITION_DISTANCE); break; } } else { BDACompetitionMode.Instance.StartCompetitionMode(BDArmorySettings.COMPETITION_DISTANCE); } yield return(new WaitForFixedUpdate()); // Give the competition start a frame to get going. // start timer coroutine for the duration specified in settings UI var duration = Core.BDArmorySettings.COMPETITION_DURATION * 60f; message = "Starting " + (duration > 0 ? "a " + duration.ToString("F0") + "s" : "an unlimited") + " duration competition."; Debug.Log("[BDArmory.BDATournament]: " + message); BDACompetitionMode.Instance.competitionStatus.Add(message); while (BDACompetitionMode.Instance.competitionStarting || BDACompetitionMode.Instance.sequencedCompetitionStarting) { yield return(new WaitForFixedUpdate()); // Wait for the competition to actually start. } if (!BDACompetitionMode.Instance.competitionIsActive) { var message = "Competition failed to start."; BDACompetitionMode.Instance.competitionStatus.Add(message); Debug.Log("[BDArmory.BDATournament]: " + message); tournamentStatus = TournamentStatus.Stopped; yield break; } competitionStarted = true; while (BDACompetitionMode.Instance.competitionIsActive) // Wait for the competition to finish. { yield return(new WaitForSeconds(1)); } }
public void StopTournament() { if (runTournamentCoroutine != null) { StopCoroutine(runTournamentCoroutine); runTournamentCoroutine = null; } tournamentStatus = heatsRemaining > 0 ? TournamentStatus.Stopped : TournamentStatus.Completed; }
public Tournament(bool? enableLogging = false) { EnableLogging = enableLogging.HasValue && enableLogging.Value; if (EnableLogging) { Logger = new Logger(); } Participants = new List<Participant>(); TournamentMode = TournamentMode.PlayerVsComputer; TournamentStatus = TournamentStatus.NotStarted; BattlesByRound = new Dictionary<int, List<BattleDetails>>(); Round = 0; }
int current_match = 1; //номер текущего матча public Tournament(int tour_id) { tm.ChangeStatus(tour_id, TournamentStatus.Playing); this.tour_id = tour_id; //load info from DB var info = api.GetSQLQueryResult("SELECT * FROM `tournaments` WHERE `tour_id` = " + tour_id); if (info.Count != 1) { return; } game_id = int.Parse(info[0]["game_id"]); name = info[0]["name"]; //players_count = int.Parse(info[0]["players_cnt"]); status = (TournamentStatus)int.Parse(info[0]["status"]); start = DateTime.Parse(info[0]["date_start"]); //create first stage stages.Add(new TournamentStage()); //load players var players = api.GetSQLQueryResult("SELECT `user_id` FROM `tour_req` WHERE `tour_id` = " + tour_id); players_count = players.Count; int pos = (int)Math.Pow(2, Math.Ceiling(Math.Log(players_count) / Math.Log(2)) - 1); current_stage = pos; foreach (var player in players) { var pl = new Player(); pl.tour_id = tour_id; pl.user_id = int.Parse(player["user_id"]); stages[0].players.Add(pl); this.players.Add(pl); stages[0].position = pos; } Console.WriteLine("Начало турнира"); }
public void SetupTournament(string folder, int rounds, int vesselsPerHeat = 0, int teamsPerHeat = 0, int vesselsPerTeam = 0, int numberOfTeams = 0, string stateFile = "") { if (stateFile != "") { this.stateFile = stateFile; } tournamentState = new TournamentState(); if (numberOfTeams == 0) // FFA { if (!tournamentState.Generate(folder, rounds, vesselsPerHeat)) { return; } } else // Folders or random teams { if (!tournamentState.Generate(folder, rounds, teamsPerHeat, vesselsPerTeam, numberOfTeams)) { return; } } tournamentID = tournamentState.tournamentID; tournamentType = tournamentState.tournamentType; vesselCount = tournamentState.vesselCount; teamCount = tournamentState.teamCount; this.teamsPerHeat = tournamentState.teamsPerHeat; this.vesselsPerTeam = tournamentState.vesselsPerTeam; fullTeams = tournamentState.fullTeams; numberOfRounds = tournamentState.rounds.Count; numberOfHeats = numberOfRounds > 0 ? tournamentState.rounds[0].Count : 0; heatsRemaining = tournamentState.rounds.Select(r => r.Value.Count).Sum() - tournamentState.completed.Select(c => c.Value.Count).Sum(); tournamentStatus = heatsRemaining > 0 ? TournamentStatus.Stopped : TournamentStatus.Completed; message = "Tournament generated for " + vesselCount + " craft found in AutoSpawn" + (folder == "" ? "" : "/" + folder); BDACompetitionMode.Instance.competitionStatus.Add(message); Debug.Log("[BDATournament]: " + message); SaveTournamentState(); }
private void UpdateTournamentStatus() { if (Participants.Count(i => i.Status == ParticipantStatus.Active) == 1) { TournamentStatus = TournamentStatus.Finished; Winner = Participants.First(i => i.Status == ParticipantStatus.Active); } }
public void Start() { Participants .ToList() .ForEach(p => { if (!(p.Character is Player)) { p.Character.LevelUp(); p.Character.AddCash(100); p.Character.BuyItems(); } }); TournamentStatus = TournamentStatus.InProgress; StartNextRound(); }
IEnumerator RunTournamentCoroutine() { yield return(new WaitForFixedUpdate()); foreach (var roundIndex in tournamentState.rounds.Keys) { currentRound = roundIndex; foreach (var heatIndex in tournamentState.rounds[roundIndex].Keys) { currentHeat = heatIndex; if (tournamentState.completed.ContainsKey(roundIndex) && tournamentState.completed[roundIndex].Contains(heatIndex)) { continue; // We've done that heat. } message = "Running heat " + heatIndex + " of round " + roundIndex + " of tournament " + tournamentState.tournamentID; BDACompetitionMode.Instance.competitionStatus.Add(message); Debug.Log("[BDATournament]: " + message); int attempts = 0; competitionStarted = false; while (!competitionStarted && attempts++ < 3) // 3 attempts is plenty { tournamentStatus = TournamentStatus.Running; yield return(ExecuteHeat(roundIndex, heatIndex)); if (!competitionStarted) { switch (VesselSpawner.Instance.spawnFailureReason) { case VesselSpawner.SpawnFailureReason.None: // Successful spawning, but competition failed to start for some reason. BDACompetitionMode.Instance.competitionStatus.Add("Failed to start heat due to " + BDACompetitionMode.Instance.competitionStartFailureReason + ", trying again."); break; case VesselSpawner.SpawnFailureReason.VesselLostParts: // Recoverable spawning failure. case VesselSpawner.SpawnFailureReason.TimedOut: // Recoverable spawning failure. BDACompetitionMode.Instance.competitionStatus.Add("Failed to start heat due to " + VesselSpawner.Instance.spawnFailureReason + ", trying again."); break; default: // Spawning is unrecoverable. BDACompetitionMode.Instance.competitionStatus.Add("Failed to start heat due to " + VesselSpawner.Instance.spawnFailureReason + ", aborting."); attempts = 3; break; } } } if (!competitionStarted) { Debug.Log("[BDATournament]: Failed to run heat, failure reasons: " + VesselSpawner.Instance.spawnFailureReason + ", " + BDACompetitionMode.Instance.competitionStartFailureReason); tournamentStatus = TournamentStatus.Stopped; yield break; } // Register the heat as completed. if (!tournamentState.completed.ContainsKey(roundIndex)) { tournamentState.completed.Add(roundIndex, new HashSet <int>()); } tournamentState.completed[roundIndex].Add(heatIndex); SaveTournamentState(); heatsRemaining = tournamentState.rounds.Select(r => r.Value.Count).Sum() - tournamentState.completed.Select(c => c.Value.Count).Sum(); if (heatsRemaining > 0) { // Wait a bit for any user action tournamentStatus = TournamentStatus.Waiting; double startTime = Planetarium.GetUniversalTime(); while ((Planetarium.GetUniversalTime() - startTime) < BDArmorySettings.TOURNAMENT_DELAY_BETWEEN_HEATS) { BDACompetitionMode.Instance.competitionStatus.Add("Waiting " + (BDArmorySettings.TOURNAMENT_DELAY_BETWEEN_HEATS - (Planetarium.GetUniversalTime() - startTime)).ToString("0") + "s, then running next heat."); yield return(new WaitForSeconds(1)); } } } message = "All heats in round " + roundIndex + " have been run."; BDACompetitionMode.Instance.competitionStatus.Add(message); Debug.Log("[BDATournament]: " + message); } message = "All rounds in tournament " + tournamentState.tournamentID + " have been run."; BDACompetitionMode.Instance.competitionStatus.Add(message); Debug.Log("[BDATournament]: " + message); tournamentStatus = TournamentStatus.Completed; }
private void Tourney_OnTournamentStatus(TournamentStatus status) { lblStatusBar.Text = status.CompletedGames + "/" + status.TotalGames + " games completed" + (status.Timeouts > 0 ? $" ({status.Timeouts} timeouts)" : ""); progStatus.Value = (int)status.PercentageComplete; }
private void Tourney_OnTournamentStatus(TournamentStatus status) { lblStatusBar.Text = status.CompletedGames + "/" + status.TotalGames + " games completed"; progStatus.Value = (int)status.PercentageComplete; }