// ============================================================== public override void RemoveAPlayer(HockeyPlayer hockeyPlayer) // ============================================================== { //Console.WriteLine("RemoveAPlayer from the visitor team"); _visitorRoster.Remove(hockeyPlayer); hockeyPlayer.AssignedToTeam = false; }
// ===================================================== public override bool Insert(HockeyPlayer hockeyPlayer) // ===================================================== { bool insertSuccess = false; if (Connected()) { var builder = Builders <BsonDocument> .Filter; var filterFN = builder.Eq("FirstName", hockeyPlayer.FirstName); var filterLN = builder.Eq("LastName", hockeyPlayer.LastName); var filter = filterFN & filterLN; // Check to see if the player is already in the database if (_mongoCollection.Find(filter).FirstOrDefault() == null) { // If the player is not then insert him var player = new MongoDbHockeyPlayer(hockeyPlayer); var playerDoc = new BsonDocument(); var bsonWriter = new BsonDocumentWriter(playerDoc); BsonSerializer.Serialize(bsonWriter, player); // Serialize MongoDbHockeyPlayer to BsonDocument _mongoCollection.InsertOne(playerDoc); // Insert the BsonDocument into the database insertSuccess = true; } else { Console.WriteLine("Player is already in the database."); } } return(insertSuccess); }
// ============================================================== private void FetchAvailablePlayers() // // Currently being fetched from teamopolis. // Should be configurable // ============================================================== { DbConnection myDbConnection = HammerMainDb.getInstance(); List <string> _availablePlayers = TeamopolisReader.Instance.AvailablePlayers; foreach (string player in _availablePlayers) { HockeyPlayer dbPlayer = myDbConnection.Read(player); if (dbPlayer != null) { dbPlayer.AssignedToTeam = false; if (dbPlayer.PlayerType == 'F') { _availableFullTimePlayers.Add(dbPlayer); } else { _availableSubPlayers.Add(dbPlayer); } } } }
// ===================================================== //Delete statement public override bool Delete(HockeyPlayer player) // ===================================================== { bool updateStatus = false; string playerName = player.FirstName + " " + player.LastName; MySqlDbHockeyPlayer hockeyPlayer = (MySqlDbHockeyPlayer)Read(playerName); if (OpenConnection() == true) { if (hockeyPlayer != null) { //Create Command string mySqlQuery = $"delete from mondaynighthockey.players where player_id={hockeyPlayer.PlayerId}"; MySqlCommand cmd = new MySqlCommand(mySqlQuery, _connection); // Execute the DELETE int affectedRows = cmd.ExecuteNonQuery(); if (affectedRows == 1) { updateStatus = true; } } // Finished with the command CloseConnection(); } return(updateStatus); }
// ===================================================== //Insert statement public override bool Insert(HockeyPlayer player) // ===================================================== { bool insertStatus = false; MySqlDbHockeyPlayer hockeyPlayer = new MySqlDbHockeyPlayer(player); if (OpenConnection() == true) { string firstName = hockeyPlayer.FirstName; string lastName = hockeyPlayer.LastName; string position = hockeyPlayer.PlayerPos; string playerType = hockeyPlayer.PlayerType.ToString(); string skillLevel; if (hockeyPlayer.Level == HockeyPlayer.PlayerSkill.Level_A) { skillLevel = "A"; } else if (hockeyPlayer.Level == HockeyPlayer.PlayerSkill.Level_B) { skillLevel = "B"; } else if (hockeyPlayer.Level == HockeyPlayer.PlayerSkill.Level_C) { skillLevel = "C"; } else //(hockeyPlayer.Level == HockeyPlayer.PlayerSkill.Level_D) { skillLevel = "D"; } string goalie; if (hockeyPlayer.Goalie == true) { goalie = "Y"; } else { goalie = "N"; } string mySqlQuery = $"insert into mondaynighthockey.players (player_last_name, player_first_name, player_level, player_position, player_goalie, player_type, player_team, player_last_wk) values (\"{lastName}\", \"{firstName}\", '{skillLevel[0]}', \"{position}\", '{goalie[0]}', \"{playerType}\", \"Unaffiliated\", \"Zed\")"; Console.WriteLine(mySqlQuery); //Create Command MySqlCommand cmd = new MySqlCommand(mySqlQuery, _connection); // Execute the INSERT int affectedRows = cmd.ExecuteNonQuery(); // Finished with the command CloseConnection(); if (affectedRows == 1) { insertStatus = true; } } return(insertStatus); }
// ============================================================== public override void AddAPlayer(HockeyPlayer hockeyPlayer) // ============================================================== { //Console.WriteLine("AddAPlayer for the visitor team"); hockeyPlayer.AssignedToTeam = true; hockeyPlayer.PlayerLastWeek = "White"; // This week the player will be on the home "black" team _visitorRoster.Add(hockeyPlayer); }
// ============================================================== private static bool PlayerAttrs() // ============================================================== { bool playerFound = false; //ArrayList credentials = HammerMain.Credentials(); // Log in to server DbConnection dbConnection = HammerMainDb.getInstance(); if (dbConnection.Connected()) { string firstName = null; string lastName = null; do { Console.Write("Player's first name: "); firstName = getKbdInput(); } while (firstName == null); do { Console.Write("Player's last name: "); lastName = getKbdInput(); } while (lastName == null); string player = firstName + " " + lastName; HockeyPlayer dbPlayer = dbConnection.Read(player); if (dbPlayer != null) { playerFound = true; Console.WriteLine(); Console.WriteLine($"Player {player}:"); Console.WriteLine($"\tSkill level: {dbPlayer.Level}"); Console.WriteLine($"\tPosition: {dbPlayer.PlayerPos}"); Console.WriteLine($"\tCan play goalie: {dbPlayer.Goalie}"); Console.WriteLine($"\tFulltime or sub: {dbPlayer.PlayerType}"); Console.WriteLine($"\tTeam affiliation: {dbPlayer.PlayerTeam}"); Console.WriteLine($"\tLast week jersey color: {dbPlayer.PlayerLastWeek}"); Console.WriteLine($"\tCaptain: {dbPlayer.Captain}"); Console.WriteLine($"\tAlternate captain: {dbPlayer.AltCaptain}"); } else { Console.WriteLine($"Player {player} wasn't found in the db."); } } return(playerFound); }
// ============================================================== public HockeyPlayer(HockeyPlayer player) // ============================================================== { LastName = player.LastName; FirstName = player.FirstName; Level = player.Level; PlayerPos = player.PlayerPos; Goalie = player.Goalie; PlayerType = player.PlayerType; PlayerTeam = player.PlayerTeam; PlayerLastWeek = player.PlayerLastWeek; Captain = player.Captain; AltCaptain = player.AltCaptain; AssignedToTeam = player.AssignedToTeam; PlayerScore = player.PlayerScore; }
// ===================================================== public override bool Update(HockeyPlayer hockeyPlayer) // ===================================================== { bool updateSuccess = false; if (Connected()) { // First retrieve the player's current document in the database // Build a query filter. This filter will be used to both find and replace var builder = Builders <BsonDocument> .Filter; var filterFN = builder.Eq("FirstName", hockeyPlayer.FirstName); var filterLN = builder.Eq("LastName", hockeyPlayer.LastName); var filter = filterFN & filterLN; // Find the player in the database var currentPlayerDoc = _mongoCollection.Find(filter).FirstOrDefault(); var currentPlayer = new MongoDbHockeyPlayer(); currentPlayer = BsonSerializer.Deserialize <MongoDbHockeyPlayer>(currentPlayerDoc); // CurrentPlayer is the player as represented in the existing BsonDocument // Need to transfer this player's _id to the new player's _id var newPlayer = new MongoDbHockeyPlayer(hockeyPlayer); newPlayer._id = currentPlayer._id; var newPlayerDoc = new BsonDocument(); var bsonWriter = new BsonDocumentWriter(newPlayerDoc); BsonSerializer.Serialize(bsonWriter, newPlayer); // Serialize the new MongoDbHockeyPlayer to BsonDocument var options = new UpdateOptions(); options.IsUpsert = true; try { var result = _mongoCollection.ReplaceOne(filter, newPlayerDoc, options); // Replace the existing BsonDocument with the new one updateSuccess = true; } catch (BsonSerializationException ex) { Console.WriteLine(); Console.WriteLine($"MongoDbConnection Update failed with error: {ex.Message}"); Console.WriteLine(); } } return(updateSuccess); }
// ============================================================== public override HockeyPlayer GetASkillPlayer(HockeyPlayer.PlayerSkill skillLevel) // ============================================================== { HockeyPlayer skillPlayer = null; foreach (HockeyPlayer player in _visitorRoster) { if ((player.PlayerTeam == "Unaffiliated") && (player.PlayerPos != "Goalie") && (player.Level == skillLevel)) { skillPlayer = player; break; } } return(skillPlayer); }
// ===================================================== public override bool Delete(HockeyPlayer player) // ===================================================== { bool removeSuccess = false; var builder = Builders <BsonDocument> .Filter; var filterFN = builder.Eq("FirstName", player.FirstName); var filterLN = builder.Eq("LastName", player.LastName); var filter = filterFN & filterLN; var result = _mongoCollection.DeleteOne(filter); if (result.DeletedCount == 1) { removeSuccess = true; } return(removeSuccess); }
public int CompareTo(object obj) { HockeyPlayer player = obj as HockeyPlayer; if (player != null) { if (this.PlayerScore > player.PlayerScore) { return(1); } else if (this.PlayerScore < player.PlayerScore) { return(-1); } else { return(0); } } else { throw new NotImplementedException(); } }
// ============================================================== private static bool DeletePlayer() // ============================================================== { bool playerDeleted = false; //ArrayList credentials = HammerMain.Credentials(); // Log in to server DbConnection dbConnection = HammerMainDb.getInstance(); if (dbConnection.Connected()) { string firstName = null; string lastName = null; do { Console.Write("Player's first name: "); firstName = getKbdInput(); } while (firstName == null); do { Console.Write("Player's last name: "); lastName = getKbdInput(); } while (lastName == null); string player = firstName + " " + lastName; HockeyPlayer dbPlayer = dbConnection.Read(player); if (dbPlayer != null) { Console.WriteLine($"Player {player} found in the db."); string deleteThisPlayer = null; do { Console.Write("Delete this player? (Y/N) "); deleteThisPlayer = getKbdInput(); } while ((deleteThisPlayer != "Y") && (deleteThisPlayer != "N")); if (deleteThisPlayer == "Y") { playerDeleted = dbConnection.Delete(dbPlayer); if (playerDeleted) { Console.WriteLine($"Player {player} was deleted from db."); } else { Console.WriteLine($"Player {player} was not deleted from db."); } } } else { Console.WriteLine($"Player {player} wasn't found in the db."); } } return(playerDeleted); }
// ============================================================== public MySqlDbHockeyPlayer(HockeyPlayer player) : base(player) // ============================================================== { PlayerId = 0; }
public abstract void AddAPlayer(HockeyPlayer hockeyPlayer); // Provided in team classes public abstract void RemoveAPlayer(HockeyPlayer hockeyPlayer); // Provided in team classes
// ============================================================== private static bool UpdatePlayer() // ============================================================== { bool updateStatus = false; string position = null; string plyrSkillLevel = null; string canPlayGoalie = null; string playerType = null; string teamAffiliation = null; string jerseyLastWeek = null; string isCaptain = null; string isAltCaptain = null; bool goalie; bool captain = false, altCaptain = false; HockeyPlayer.PlayerSkill skillLevel; // Log in to server DbConnection dbConnection = HammerMainDb.getInstance(); if (dbConnection.Connected()) { string firstName = null; string lastName = null; do { Console.Write("Player's first name: "); firstName = getKbdInput(); } while (firstName == null); do { Console.Write("Player's last name: "); lastName = getKbdInput(); } while (lastName == null); string player = firstName + " " + lastName; HockeyPlayer dbPlayer = dbConnection.Read(player); if (dbPlayer != null) { Console.WriteLine(); Console.WriteLine($"Player {player}:"); Console.WriteLine($"\tSkill level: {dbPlayer.Level}"); Console.WriteLine($"\tPosition: {dbPlayer.PlayerPos}"); Console.WriteLine($"\tCan play goalie: {dbPlayer.Goalie}"); Console.WriteLine($"\tFulltime or sub: {dbPlayer.PlayerType}"); Console.WriteLine($"\tTeam affiliation: {dbPlayer.PlayerTeam}"); Console.WriteLine($"\tLast week jersey color: {dbPlayer.PlayerLastWeek}"); Console.WriteLine(); Console.WriteLine($"Modify player's attributes."); do { Console.Write("Player's skill level (A/B/C/D): "); plyrSkillLevel = getKbdInput(); } while ((plyrSkillLevel != "A") && (plyrSkillLevel != "B") && (plyrSkillLevel != "C") && (plyrSkillLevel != "D")); if (plyrSkillLevel == "A") { skillLevel = HockeyPlayer.PlayerSkill.Level_A; } else if (plyrSkillLevel == "B") { skillLevel = HockeyPlayer.PlayerSkill.Level_B; } else if (plyrSkillLevel == "C") { skillLevel = HockeyPlayer.PlayerSkill.Level_C; } else // (plyrSkillLevel == "D") { skillLevel = HockeyPlayer.PlayerSkill.Level_D; } do { Console.Write("Player's position (D, F, G): "); position = getKbdInput(); } while ((position != "D") && (position != "F") && (position != "G")); if (position == "D") { position = "Defense"; } else if (position == "F") { position = "Forward"; } else { position = "Goalie"; } do { Console.Write("If not a goalie can the player also play as a goalie? (Y/N) "); canPlayGoalie = getKbdInput(); } while ((canPlayGoalie != "Y") && (canPlayGoalie != "N")); if (canPlayGoalie == "Y") { goalie = true; } else { goalie = false; } do { Console.Write("Is the player full time or a sub? (F/S) "); playerType = getKbdInput(); } while ((playerType != "F") && (playerType != "S")); do { Console.Write("Is the player a captain? (Y/N) "); isCaptain = getKbdInput(); } while ((isCaptain != "Y") && (isCaptain != "N")); if (isCaptain == "N") { do { Console.Write("Is the player an alternate captain? (Y/N) "); isAltCaptain = getKbdInput(); } while ((isAltCaptain != "Y") && (isAltCaptain != "N")); if (isAltCaptain == "Y") { altCaptain = true; } } else { captain = true; } do { Console.Write("Player's team affiliation, Unaffiliated ('U'), Ben ('B') or Jared ('J'): "); teamAffiliation = getKbdInput(); } while ((teamAffiliation != "B") && (teamAffiliation != "J") && (teamAffiliation != "U")); if (teamAffiliation == "B") { teamAffiliation = "Ben"; } else if (teamAffiliation == "J") { teamAffiliation = "Jared"; } else { teamAffiliation = "Unaffiliated"; } do { Console.Write("Player's Player's jersey color last week, Black, White or Zed (B/W/Z): "); jerseyLastWeek = getKbdInput(); } while ((jerseyLastWeek != "B") && (jerseyLastWeek != "W") && (jerseyLastWeek != "Z")); if (jerseyLastWeek == "B") { jerseyLastWeek = "Black"; } else if (jerseyLastWeek == "W") { jerseyLastWeek = "White"; } else { jerseyLastWeek = "Zed"; } Console.WriteLine(); Console.WriteLine($"Updating player {player}'s attributes in the db."); Console.WriteLine($"{firstName} is a level {plyrSkillLevel} player who plays {position}."); Console.WriteLine(); HockeyPlayer hockeyPlayer = new HockeyPlayer( lastName, firstName, skillLevel, position, goalie, playerType[0], teamAffiliation, jerseyLastWeek, captain, altCaptain); updateStatus = dbConnection.Update(hockeyPlayer); Console.WriteLine(); } else { Console.WriteLine($"Player {player} wasn't found in the db."); } } return(updateStatus); }
// ===================================================== // ===================================================== //Delete statement public abstract bool Delete(HockeyPlayer player);
// ===================================================== // ===================================================== //Update statement public abstract bool Update(HockeyPlayer player);
// ===================================================== // ===================================================== // CRUD // ===================================================== //Insert/Create statement public abstract bool Insert(HockeyPlayer player);
// ============================================================== private static bool AddNewPlayer() // ============================================================== { bool newPlayerAdded = true; string firstName = null; string lastName = null; string position = null; string plyrSkillLevel = null; string canPlayGoalie = null; string playerType = null; string anotherPlayer = null; string isAltCaptain = null; string isCaptain = null; bool goalie; bool captain = false, altCaptain = false; HockeyPlayer.PlayerSkill skillLevel; // Log in to server DbConnection dbConnection = HammerMainDb.getInstance(); if (dbConnection.Connected()) { do { do { Console.Write("Player's first name: "); firstName = getKbdInput(); } while (firstName == null); do { Console.Write("Player's last name: "); lastName = getKbdInput(); } while (lastName == null); do { Console.Write("Player's skill level (A/B/C/D): "); plyrSkillLevel = getKbdInput(); } while ((plyrSkillLevel != "A") && (plyrSkillLevel != "B") && (plyrSkillLevel != "C") && (plyrSkillLevel != "D")); if (plyrSkillLevel == "A") { skillLevel = HockeyPlayer.PlayerSkill.Level_A; } else if (plyrSkillLevel == "B") { skillLevel = HockeyPlayer.PlayerSkill.Level_B; } else if (plyrSkillLevel == "C") { skillLevel = HockeyPlayer.PlayerSkill.Level_C; } else // (plyrSkillLevel == "D") { skillLevel = HockeyPlayer.PlayerSkill.Level_D; } do { Console.Write("Player's position (D, F, G): "); position = getKbdInput(); } while ((position != "D") && (position != "F") && (position != "G")); if (position == "D") { position = "Defense"; } else if (position == "F") { position = "Forward"; } else { position = "Goalie"; } do { Console.Write("If not a goalie can the player also play as a goalie? (Y/N) "); canPlayGoalie = getKbdInput(); } while ((canPlayGoalie != "Y") && (canPlayGoalie != "N")); if (canPlayGoalie == "Y") { goalie = true; } else { goalie = false; } do { Console.Write("Is the player full time or a sub? (F/S) "); playerType = getKbdInput(); } while ((playerType != "F") && (playerType != "S")); do { Console.Write("Is the player a captain? (Y/N) "); isCaptain = getKbdInput(); } while ((isCaptain != "Y") && (isCaptain != "N")); if (isCaptain == "N") { do { Console.Write("Is the player an alternate captain? (Y/N) "); isAltCaptain = getKbdInput(); } while ((isAltCaptain != "Y") && (isAltCaptain != "N")); if (isAltCaptain == "Y") { altCaptain = true; } } else { captain = true; } Console.WriteLine(); Console.WriteLine($"About to add new player {firstName} {lastName} to the db."); Console.WriteLine($"{firstName} is a level {plyrSkillLevel} player who plays {position}."); Console.WriteLine(); HockeyPlayer player = new HockeyPlayer( lastName, firstName, skillLevel, position, goalie, playerType[0], "Unaffiliated", "Zed", captain, altCaptain); newPlayerAdded = dbConnection.Insert(player); Console.WriteLine(); if (newPlayerAdded) { do { Console.Write("Add another player? (Y/N) "); anotherPlayer = getKbdInput(); } while ((anotherPlayer != "Y") && (anotherPlayer != "N")); } Console.WriteLine(); } while ((newPlayerAdded) && (anotherPlayer == "Y")); Console.WriteLine(); } return(newPlayerAdded); }
// ============================================================== public void TeamAssign(HockeyPlayer player) // ============================================================== { HomeTeam home = HomeTeam.Instance; // The home team is the "black" team VisitorTeam away = VisitorTeam.Instance; // The away team is the "white" team if (player != null) { if (player.Captain == true) { if (player.PlayerLastWeek == "White") // Last week away, this week home { home.AddAPlayer(player); } else if (player.PlayerLastWeek == "Black") // Last week home, this week away { away.AddAPlayer(player); } else { } } else if ((player.AltCaptain == true) && ((home.PlayerCount < 1) || (away.PlayerCount < 1))) { if ((player.PlayerLastWeek == "White") && (home.PlayerCount < 1)) { home.AddAPlayer(player); } else if ((player.PlayerLastWeek == "Black") && (away.PlayerCount < 1)) { away.AddAPlayer(player); } else { if (home.PlayerCount < 1) { home.AddAPlayer(player); } else { away.AddAPlayer(player); } } } else // Players not captains or alt-captains { int[] homeTeamComp = home.TeamComposition; int[] awayTeamComp = away.TeamComposition; bool assignHome = false; int scoreDifferential = 0; if (home.TeamScore <= away.TeamScore) { scoreDifferential = away.TeamScore - home.TeamScore; } else { scoreDifferential = home.TeamScore - away.TeamScore; } switch (player.Level) { case HockeyPlayer.PlayerSkill.Level_A: if ((home.PlayerCount <= away.PlayerCount) && (home.TeamScore <= away.TeamScore) && (homeTeamComp[0] <= awayTeamComp[0])) { assignHome = true; } break; case HockeyPlayer.PlayerSkill.Level_B: if ((home.PlayerCount <= away.PlayerCount) && (home.TeamScore <= away.TeamScore) && ((homeTeamComp[0] <= awayTeamComp[0]) || (homeTeamComp[1] <= awayTeamComp[1]))) { assignHome = true; } break; case HockeyPlayer.PlayerSkill.Level_C: if ((home.PlayerCount <= away.PlayerCount) && (home.TeamScore <= away.TeamScore) && ((homeTeamComp[0] <= awayTeamComp[0]) || (homeTeamComp[1] <= awayTeamComp[1]) || (homeTeamComp[2] <= awayTeamComp[2]))) { assignHome = true; } break; case HockeyPlayer.PlayerSkill.Level_D: /* * if ((homeTeamComp[3] < awayTeamComp[3]) && * (home.TeamScore < away.TeamScore)) */ if ((home.PlayerCount <= away.PlayerCount) && (home.TeamScore <= away.TeamScore) && ((homeTeamComp[0] <= awayTeamComp[0]) || (homeTeamComp[1] <= awayTeamComp[1]) || (homeTeamComp[2] <= awayTeamComp[2]) || (homeTeamComp[3] <= awayTeamComp[3]))) { assignHome = true; } break; } if (assignHome == true) { home.AddAPlayer(player); } else { away.AddAPlayer(player); } } } }
// ============================================================== public MongoDbHockeyPlayer(HockeyPlayer player) : base(player) // ============================================================== { _id = ObjectId.Empty; }
// ============================================================== private void Balance(HockeyTeam strongTeam, HockeyTeam weakTeam) // ============================================================== { HockeyPlayer strongPlayer = null; HockeyPlayer weakPlayer = null; int teamScoreDifferential = strongTeam.TeamScore - weakTeam.TeamScore; if (strongTeam.PlayerCount == weakTeam.PlayerCount) // The player counts are equal so swap one for one { switch (teamScoreDifferential / 2) { case 5: // No swap; move an A Console.WriteLine("BalanceDifferential11/10: Try to move an A player from strong to weak"); HockeyPlayer player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_A); // Perform the swap if a player is available if (player != null) { Console.WriteLine("BalanceDifferential11/10: Perform the move"); weakTeam.AddAPlayer(player); strongTeam.RemoveAPlayer(player); } break; case 4: // No swap; move an A Console.WriteLine("BalanceDifferential9/8: Try to move an A player from strong to weak"); player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_A); // Perform the swap if a player is available if (player != null) { Console.WriteLine("BalanceDifferential9/8: Perform the move"); weakTeam.AddAPlayer(player); strongTeam.RemoveAPlayer(player); } break; case 3: // Swap an A for a D Console.WriteLine("BalanceDifferential7/6: Try to swap an A with a D"); strongPlayer = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_A); weakPlayer = weakTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_D); break; case 2: // Swap an A for a C or a B for a D Console.WriteLine("BalanceDifferential5/4: Try to swap a B with a D"); strongPlayer = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_B); weakPlayer = weakTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_D); if (strongPlayer == null || weakPlayer == null) { // If we can't do that try to swap an A (4) with a C (2) Console.WriteLine("BalanceDifferential5/4: Try to swap an A with a C"); strongPlayer = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_A); weakPlayer = weakTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_C); } break; case 1: // Swap an A for a B, a B for a C, or a C for a D // Try to swap an A with a B Console.WriteLine("BalanceDifferential3/2: Try to swap a C with a D"); strongPlayer = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_C); weakPlayer = weakTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_D); if (strongPlayer == null || weakPlayer == null) { // If we can't do that try to swap a B with a C Console.WriteLine("BalanceDifferential3/2: Try to swap a B with a C"); strongPlayer = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_B); weakPlayer = weakTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_C); } if (strongPlayer == null || weakPlayer == null) { // If we can't do that try to swap a C with a D Console.WriteLine("BalanceDifferential3/2: Try to swap an A with a B"); strongPlayer = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_A); weakPlayer = weakTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_B); } break; } // Perform the swap if the players are available if (strongPlayer != null && weakPlayer != null) { Console.WriteLine("BalanceTeams: Perform the swap"); strongTeam.AddAPlayer(weakPlayer); weakTeam.AddAPlayer(strongPlayer); strongTeam.RemoveAPlayer(strongPlayer); weakTeam.RemoveAPlayer(weakPlayer); } } else // (strongTeam.PlayerCount > weakTeam.PlayerCount) The strong team player count is greater so move a player { HockeyPlayer player = null; switch (teamScoreDifferential / 2) { case 5: Console.WriteLine("BalanceDifferential11/10: Try to move an A player from strong to weak"); player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_A); if (player == null) { Console.WriteLine("BalanceDifferential11/10: Try to move a B player from strong to weak"); player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_B); } break; case 4: Console.WriteLine("BalanceDifferential9/8: Try to move an A player from strong to weak"); player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_A); if (player == null) { Console.WriteLine("BalanceDifferential9/8: Try to move a B player from strong to weak"); player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_B); } break; case 3: Console.WriteLine("BalanceDifferential7/6: Try to move a B player from strong to weak"); player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_B); if (player == null) { Console.WriteLine("BalanceDifferential7/6: Try to move a C player from strong to weak"); player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_C); } break; case 2: Console.WriteLine("BalanceDifferential5/4: Try to move a C player from strong to weak"); player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_C); if (player == null) { Console.WriteLine("BalanceDifferential5/4: Try to move a D player from strong to weak"); player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_D); } break; case 1: Console.WriteLine("BalanceDifferential3/2: Try to move a D player from strong to weak"); player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_D); if (player == null) { Console.WriteLine("BalanceDifferential3/2: FAIL: Try to move a C player from strong to weak"); player = strongTeam.GetASkillPlayer(HockeyPlayer.PlayerSkill.Level_C); } break; } // Perform the swap if a player is available if (player != null) { Console.WriteLine("BalanceTeams: Perform the move"); weakTeam.AddAPlayer(player); strongTeam.RemoveAPlayer(player); } } }