Exemple #1
0
        // ==============================================================
        // This is the team balancer.
        // It will balance the teams based upon score and
        // numbers of players on each roster.
        // NOTE: Goalies are added after the balance.
        // ==============================================================
        public void Balance()
        // ==============================================================
        {
            HomeTeam    home    = HomeTeam.Instance;
            VisitorTeam visitor = VisitorTeam.Instance;

            Console.WriteLine($"Balancer: home.PlayerCount    = {home.PlayerCount}");
            Console.WriteLine($"Balancer: visitor.PlayerCount = {visitor.PlayerCount}");
            Console.WriteLine($"Balancer: home.TeamScore    = {home.TeamScore}");
            Console.WriteLine($"Balancer: visitor.TeamScore = {visitor.TeamScore}");

            int teamScoreDiff = 0;
            int runaway       = 0;

            do
            {
                if (home.TeamScore >= visitor.TeamScore)
                {
                    Balance(home, visitor);
                }
                else
                {
                    Balance(visitor, home);
                }

                if (home.TeamScore >= visitor.TeamScore)
                {
                    teamScoreDiff = home.TeamScore - visitor.TeamScore;
                }
                else
                {
                    teamScoreDiff = visitor.TeamScore - home.TeamScore;
                }
            } while (teamScoreDiff > 1 && runaway++ < 5);

            if (runaway >= 5)
            {
                Console.WriteLine("Runaway halted.");
            }

            Console.WriteLine("Select goalies.");
            if (home.TeamScore >= visitor.TeamScore)
            {
                home.AddAGoalie(true); // Strong team
                visitor.AddAGoalie(false);
            }
            else
            {
                visitor.AddAGoalie(true); // Strong team
                home.AddAGoalie(false);
            }
        }
Exemple #2
0
        // ==============================================================
        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);
                    }
                }
            }
        }