public FifaLadderNode ComputeWorldCup() { while (TeamCollection.Any()) { var tmpNode = new FifaLadderNode(); tmpNode.TeamA = RandTeam(); tmpNode.TeamB = RandTeam(); tmpNode.PlayMatch(); Root.LadderNodes.Add(tmpNode); } while (Root.LadderNodes.Count > 1) { var tmpRoot = new FifaLadderNode(); for (int i = 0; i < Root.LadderNodes.Count; i += 2) { var tmpNode = new FifaLadderNode(); tmpNode.TeamA = Root.LadderNodes[i].WinningTeam; tmpNode.LadderNodes.Add(Root.LadderNodes[i]); tmpNode.TeamB = Root.LadderNodes[i + 1].WinningTeam; tmpNode.LadderNodes.Add(Root.LadderNodes[i + 1]); tmpNode.PlayMatch(); tmpRoot.LadderNodes.Add(tmpNode); } Root = tmpRoot.Clone() as FifaLadderNode; } return(Root.LadderNodes[0]); }
public IActionResult OnPostAsync(int id) { TeamCollection teamCollection = new TeamCollection(); try { DisplayTeam = teamCollection.ReadTeam(id); teamCollection.DeleteTeam(DisplayTeam); } catch (MySqlException e) { var code = e.ErrorCode; if (code == -2147467259) { return(RedirectToPage("/DatabaseConnectionError")); } else { return(RedirectToPage("/Error")); } } finally { DisplayTeam = teamCollection.ReadTeam(id); } return(RedirectToPage("/Team")); }
private static void DisplayRating(TeamCollection teams, string teamName) { var team = teams.SingleOrDefault(x => x.Name == teamName); bool isMissingTeam = team == null; Console.WriteLine(isMissingTeam ? $"Team {teamName} does not exist." : $"{team.Name} - {team.Rating:f0}"); }
public static void Main() { string input = string.Empty; var teams = new TeamCollection(); while ((input = Console.ReadLine()) != "END") { var data = input.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); var command = data[0]; var teamName = data[1]; switch (command.ToLower()) { case "team": InsertTeam(teams, teamName); break; case "add": AddPlayerToTeam(teams, data, teamName); break; case "remove": RemovePlayer(teams, data, teamName); break; case "rating": DisplayRating(teams, teamName); break; default: break; } } }
public MainPage() { this.InitializeComponent (); this.teams = new TeamCollection (); this.attacks = new AttackCollection (this.LayoutCanvas); this.allocators = new AllocatorClassifier (new [] { typeof (CircleAllocator), typeof (RectangleAllocator), typeof (GridAllocator) }); this.monitor = new Monitor (); this.lock_object = new object (); this.service_names = new List <string> (); this.windowSize = new Size (this.LayoutCanvas.Width, this.LayoutCanvas.Height); this.speed = (int) this.speedSlider.Value + 1; this.realtimeMode = this.realtime.IsChecked == true; this.begin_with_realtime = false; this.play_iter = 0; this.update_interval = 10; foreach (var allocator in this.allocators) this.Allocation.Items.Add (allocator.Name); this.Allocation.SelectedIndex = this.allocators.Index; }
public IActionResult OnGet() { PlayerCollection playerCollection = new PlayerCollection(); TeamCollection teamCollection = new TeamCollection(); try { playerCollection.GetAllPlayers(); teamCollection.GetAllTeams(); } catch (MySqlException e) { var code = e.ErrorCode; if (code == -2147467259) { return(RedirectToPage("/DatabaseConnectionError")); } else { return(RedirectToPage("/Error")); } } finally { Players = playerCollection.GetPlayers(); Teams = teamCollection.GetTeams(); } return(Page()); }
public LeagueTeamCollection CreateLeagueTeamCollection(string leagueName, string leagueKey) { var league = new League(1, leagueName, leagueKey, 1, 16); var teamCollection = new TeamCollection(); teamCollection.Add(new Team(1, "team_key", "team_name")); return new LeagueTeamCollection(league, teamCollection); }
private Team RandTeam() { var randomIndex = new Random().Next(0, TeamCollection.Count); var tmpTeam = TeamCollection[randomIndex].Clone() as Team; TeamCollection.RemoveAt(randomIndex); return(tmpTeam); }
private static void RemovePlayer(TeamCollection teams, string[] data, string teamName) { var playerName = data[2]; var team = teams.SingleOrDefault(x => x.Name == teamName); var player = new Player(playerName); team.Remove(player); }
public void CalculateRanksTest() { var team1 = new Team(1); var team2 = new Team(2); var team3 = new Team(3); var target = new TeamCollection { team1, team2, team3 }; team1.Score = 3; team2.Score = 2; team3.Score = 1; target.CalculateRanks(); Assert.AreEqual(1, team1.Rank); Assert.AreEqual(2, team2.Rank); Assert.AreEqual(3, team3.Rank); team1.Score = 2; team2.Score = 3; team3.Score = 1; target.CalculateRanks(); Assert.AreEqual(2, team1.Rank); Assert.AreEqual(1, team2.Rank); Assert.AreEqual(3, team3.Rank); team1.Score = 1; team2.Score = 2; team3.Score = 3; target.CalculateRanks(); Assert.AreEqual(3, team1.Rank); Assert.AreEqual(2, team2.Rank); Assert.AreEqual(1, team3.Rank); team1.Score = 1; team2.Score = 0; team3.Score = -1; target.CalculateRanks(); Assert.AreEqual(1, team1.Rank); Assert.AreEqual(2, team2.Rank); Assert.AreEqual(3, team3.Rank); team1.Score = 1; team2.Score = 1; team3.Score = 0; target.CalculateRanks(); Assert.AreEqual(1, team1.Rank); Assert.AreEqual(1, team2.Rank); Assert.AreEqual(3, team3.Rank); team1.Score = 0; team2.Score = 0; team3.Score = 1; target.CalculateRanks(); Assert.AreEqual(2, team1.Rank); Assert.AreEqual(2, team2.Rank); Assert.AreEqual(1, team3.Rank); }
private static void InsertTeam(TeamCollection teams, string teamName) { var team = new Team(teamName); if (team.Name == null) { return; } teams.AddTeam(team); }
public static TradeEscrow Create(TeamCollection teamCollection, PlayerGroup playerGroup) { TradeEscrow command = new TradeEscrow(); command._playerGroup = playerGroup; command._teamCollection = teamCollection; command.transactionCompleted = false; return(command); }
public void CalculateRanksTest() { var team1 = new Team(1); var team2 = new Team(2); var team3 = new Team(3); var target = new TeamCollection {team1, team2, team3}; team1.Score = 3; team2.Score = 2; team3.Score = 1; target.CalculateRanks(); Assert.AreEqual(1, team1.Rank); Assert.AreEqual(2, team2.Rank); Assert.AreEqual(3, team3.Rank); team1.Score = 2; team2.Score = 3; team3.Score = 1; target.CalculateRanks(); Assert.AreEqual(2, team1.Rank); Assert.AreEqual(1, team2.Rank); Assert.AreEqual(3, team3.Rank); team1.Score = 1; team2.Score = 2; team3.Score = 3; target.CalculateRanks(); Assert.AreEqual(3, team1.Rank); Assert.AreEqual(2, team2.Rank); Assert.AreEqual(1, team3.Rank); team1.Score = 1; team2.Score = 0; team3.Score = -1; target.CalculateRanks(); Assert.AreEqual(1, team1.Rank); Assert.AreEqual(2, team2.Rank); Assert.AreEqual(3, team3.Rank); team1.Score = 1; team2.Score = 1; team3.Score = 0; target.CalculateRanks(); Assert.AreEqual(1, team1.Rank); Assert.AreEqual(1, team2.Rank); Assert.AreEqual(3, team3.Rank); team1.Score = 0; team2.Score = 0; team3.Score = 1; target.CalculateRanks(); Assert.AreEqual(2, team1.Rank); Assert.AreEqual(2, team2.Rank); Assert.AreEqual(1, team3.Rank); }
public static TeamCollection Get(TeamCollection collection) { if (collection == null || collection.CollectionNode == null) throw new Exception("Collection needs to be initialized."); collection.Projects.Clear(); foreach (var projectNode in collection.CollectionNode.QueryChildren(new[] { CatalogResourceTypes.TeamProject }, false, CatalogQueryOptions.None)) { collection.Projects.Add(new TeamProject(projectNode)); } return collection; }
public ActionResult IndexViewModel() { ViewModel model = new ViewModel(); PlayerCollection playerCollection = new PlayerCollection(); TeamCollection teamCollection = new TeamCollection(); playerCollection.GetAllPlayers(); teamCollection.GetAllTeams(); model.Players = playerCollection.GetPlayers(); model.Teams = teamCollection.GetTeams(); return(View(model)); }
public static TeamCollection Create(List <PlayerState> playerStates) { TeamCollection teamCollection = new TeamCollection(); teamCollection.teams = new List <List <PlayerState> >(kTeamCount); teamCollection.teams.Add(new List <PlayerState>()); teamCollection.teams.Add(new List <PlayerState>()); foreach (PlayerState player in playerStates) { teamCollection.teams[player.teamIndex].Add(player); } return(teamCollection); }
public static TuckMatchState Create( List <PlayerState> playerList, CardDeck cardDeck) { TuckMatchState state = new TuckMatchState(); state.cardDeck = cardDeck; state.playerGroup = PlayerGroup.Create(playerList, cardDeck); state.board = Board.Create(playerList); state.teams = TeamCollection.Create(playerList); state.escrow = TradeEscrow.Create(state.teams, state.playerGroup); state.validator = MoveValidator.Create(state.board); state.gameMatchMode = GameMatchMode.INITIAL; return(state); }
public Team ReadTeam(string id) { try { var results = TeamCollection.Find(t => t.Id == id); return(results.First <Team>()); } catch (TimeoutException e) { Log.Error("Received time out for reading team => ", e); return(null); } catch (Exception e) { Log.Error("Failed to read team => ", e); return(null); } }
public List <Team> Teams() { try { List <Team> teams = TeamCollection.Find(_ => true).ToList(); return(teams); } catch (TimeoutException e) { Log.Error("Received time out for retrieving teams => ", e); return(null); } catch (Exception e) { Log.Error("Failed to retrieve teams => ", e); return(null); } }
public bool DeleteTeam(string id) { try { TeamCollection.DeleteOne(a => a.Id == id); return(true); } catch (TimeoutException e) { Log.Error("Received time out for deleting team => ", e); return(false); } catch (Exception e) { Log.Error("Failed to delete team => ", e); return(false); } }
public bool CreateTeam(string name) { try { TeamCollection.InsertOne(new Team(name)); return(true); } catch (TimeoutException e) { Log.Error("Received time out for creating team => ", e); return(false); } catch (Exception e) { Log.Error("Failed to create team => ", e); return(false); } }
public async Task <Team> ReadTeamAsync(string id) { try { var results = await TeamCollection.FindAsync(t => t.Id == id); return(results.First()); } catch (TimeoutException e) { Log.Error("Received time out for reading team async => ", e); return(null); } catch (Exception e) { Log.Error("Failed to read team async => ", e); return(null); } }
public async Task <bool> DeleteTeamAsync(string id) { try { await TeamCollection.DeleteOneAsync(a => a.Id == id).TimeoutAfter(TimeoutMilisec); return(true); } catch (TimeoutException e) { Log.Error("Received time out for deleting team async => ", e); return(false); } catch (Exception e) { Log.Error("Failed to delete team async => ", e); return(false); } }
public async Task <bool> CreateTeamAsync(string name) { try { await TeamCollection.InsertOneAsync(new Team(name)).TimeoutAfter(TimeoutMilisec); return(true); } catch (TimeoutException e) { Log.Error("Received time out for creating team => async ", e); return(false); } catch (Exception e) { Log.Error("Failed to create team async => ", e); return(false); } }
public async Task <List <Team> > TeamsAsync() { try { var teams = await TeamCollection.FindAsync(_ => true); return(teams.ToList()); } catch (TimeoutException e) { Log.Error("Received time out for retrieving teams async => ", e); return(null); } catch (Exception e) { Log.Error("Failed to retrieve teams async => ", e); return(null); } }
private void ImportButton_Click(object sender, EventArgs e) { var fileName = GetSelectedSavedGame(); var filePath = BuildSavedGameFilePath(fileName); using (var savedGameConnection = new SavedGameConnection(filePath)) { // Import from file var teams = new TeamCollection(); for (var id = 0; id < TeamCount; id++) { var valueMapping = new Data.ValueMapping.SavedGame.Team.Team(id); var team = new Team { Id = id, Name = Encoding.ASCII.GetString(savedGameConnection.ReadByteArray(valueMapping.Name, Data.ValueMapping.SavedGame.Team.Team.NameLength)), Department1Motivation = savedGameConnection.ReadInteger(valueMapping.Department1Motivation), Department1Happiness = savedGameConnection.ReadInteger(valueMapping.Department1Happiness), Department2Motivation = savedGameConnection.ReadInteger(valueMapping.Department2Motivation), Department2Happiness = savedGameConnection.ReadInteger(valueMapping.Department2Happiness), Department3Motivation = savedGameConnection.ReadInteger(valueMapping.Department3Motivation), Department3Happiness = savedGameConnection.ReadInteger(valueMapping.Department3Happiness), Department4Motivation = savedGameConnection.ReadInteger(valueMapping.Department4Motivation), Department4Happiness = savedGameConnection.ReadInteger(valueMapping.Department4Happiness), Department5Motivation = savedGameConnection.ReadInteger(valueMapping.Department5Motivation), Department5Happiness = savedGameConnection.ReadInteger(valueMapping.Department5Happiness) }; teams.Add(team); } var player1TeamId = savedGameConnection.ReadInteger(Data.ValueMapping.SavedGame.Player.Player.GetPlayer1TeamIdOffset()) - 1; var player1TeamRecord = teams.Single(x => x.Id == player1TeamId); // Populate controls PopulateHeaderControls(player1TeamId, player1TeamRecord.Name); PopulateBasicControls(player1TeamRecord); PopulateAdvancedControls(teams); MessageBox.Show("Import complete!"); } }
public JsonResult GetProjectInfo(string collectionName) { Session["SelectedCollection"] = collectionName; var tfsCol = Session["TeamCollection"]; IEnumerable <TeamCollection> collection = (IEnumerable <TeamCollection>)tfsCol; if (tfsCol == null) { throw new Exception(); } TeamCollection selectedCollection = collection.First(m => m.Name == collectionName); selectedCollection = TeamProjectRepository.Get(selectedCollection); var projectList = selectedCollection.Projects; GetWorkItemStore(); return(Json(projectList, JsonRequestBehavior.AllowGet)); }
internal SelectTeamsWindow(TeamCollection teams) { this.InitializeComponent (); this.Title = LocalizedStrings.TeamsFilterWindow; this.teams = teams; var all = new List <Team> (this.teams.All); for (var i = 0; i < all.Count; ++ i) { this.NotShowedList.Items.Add (new ListBoxItem { Content = all [i].Name, Visibility = this.teams [i] != null ? Visibility.Collapsed : Visibility.Visible }); this.ShowedList.Items.Add (new ListBoxItem { Content = all [i].Name, Visibility = this.teams [i] == null ? Visibility.Collapsed : Visibility.Visible }); } }
public void HandleCreateTeamCollection(ApiRequest request) { string repoFolderParentPath = null; try { if (!TeamCollection.PromptForSufficientRegistrationIfNeeded()) { request.PostSucceeded(); return; } repoFolderParentPath = request.RequiredPostString(); _tcManager.ConnectToTeamCollection(repoFolderParentPath, _settings.CollectionId); _callbackToReopenCollection?.Invoke(); Analytics.Track("TeamCollectionCreate", new Dictionary <string, string>() { { "CollectionId", _settings?.CollectionId }, { "CollectionName", _settings?.CollectionName }, { "Backend", _tcManager?.CurrentCollection?.GetBackendType() }, { "User", CurrentUser } }); request.PostSucceeded(); } catch (Exception e) { var msgEnglish = "Error creating Team Collection {0}: {1}"; var msgFmt = LocalizationManager.GetString("TeamCollection.ErrorCreating", msgEnglish); ErrorReport.NotifyUserOfProblem(e, msgFmt, repoFolderParentPath, e.Message); Logger.WriteError(String.Format(msgEnglish, repoFolderParentPath, e.Message), e); NonFatalProblem.ReportSentryOnly(e, $"Something went wrong for {request.LocalPath()}"); // Since we have already informed the user above, it is better to just report a success here. // Otherwise, they will also get a toast. request.PostSucceeded(); } }
public IActionResult OnPostAsync(Team team) { TeamCollection teamCollection = new TeamCollection(); try { teamCollection.CreateTeam(team); } catch (MySqlException e) { var code = e.ErrorCode; if (code == -2147467259) { return(RedirectToPage("/DatabaseConnectionError")); } else { return(RedirectToPage("/Error")); } } return(RedirectToPage("/Team")); }
private static void AddPlayerToTeam(TeamCollection teams, string[] data, string teamName) { var team = teams.SingleOrDefault(x => x.Name.Equals(teamName)); if (team == null) { Console.WriteLine($"Team {teamName} does not exist."); return; } var playerName = data[2]; var endurance = int.Parse(data[3]); var spirit = int.Parse(data[4]); var dribble = int.Parse(data[5]); var passing = int.Parse(data[6]); var shooting = int.Parse(data[7]); var player = new Player(playerName, endurance, spirit, dribble, passing, shooting); if (!player.IsValid()) { return; } team.Add(player); }
public void OnGet(int id) { TeamCollection teamCollection = new TeamCollection(); DisplayTeam = teamCollection.ReadTeam(id); }
void _initialize() { _invalidError = _invalidError.Replace("{0}", "XvT or BoP"); FlightGroups = new FlightGroupCollection(); Messages = new MessageCollection(); Globals = new GlobalsCollection(); Teams = new TeamCollection(); Briefings = new BriefingCollection(); }
void _initialize() { _invalidError = _invalidError.Replace("{0}", "XWA"); _globalGroupNameIndexer = new Indexer<string>(_globalGroup, 56); _regionNameIndexer = new Indexer<string>(_region, 0x83); _iffNameIndexer = new Indexer<string>(_iff, 19, new bool[]{true, true, false, false, false, false}); FlightGroups = new FlightGroupCollection(); Messages = new MessageCollection(); Globals = new GlobalsCollection(); Teams = new TeamCollection(); Briefings = new BriefingCollection(); }
private static int GetNextRankReportTeamNumber(int currentTeamNumber, int maxTeamNumber, TeamCollection teams) { var nextTeamNumber = currentTeamNumber + 1; var checkedTeamCount = 0; Team team = null; while (true) { if (nextTeamNumber > maxTeamNumber) nextTeamNumber = 1; team = teams.Team(nextTeamNumber); checkedTeamCount++; if (team != null && team.Players != null && team.Players.Count > 0) break; if (checkedTeamCount >= maxTeamNumber) { nextTeamNumber = 0; break; } } return nextTeamNumber; }
public LeagueTeamCollection(League league, TeamCollection teams) { if (league == null) { throw new ArgumentNullException("league"); } if (teams == null) { throw new ArgumentNullException("teams"); } this.League = league; this.Teams = teams; }