Example #1
0
        static TournamentUsers GetTournamentPreliminaryWinners(Cxt cxt, int tournamentID, int round, DataTable dtTournamentUsers)
        {
            TournamentUsers tuWinners = new TournamentUsers();
            TournamentUsers tuLosers  = GetTournamentLosers(cxt, tournamentID, round);

            if (tuLosers.Count > 0)
            {
                foreach (DataRow item in dtTournamentUsers.Rows)
                {
                    TournamentUser tu1 = new TournamentUser(cxt, item);

                    if (!tuLosers.Contains("UserID = " + tu1.UserID))
                    {
                        tuWinners.Add(tu1);
                    }
                }
            }
            return(tuWinners);
        }
Example #2
0
        static TournamentUsers TournamentUserResult(Cxt cxt, DataTable dtTUser, TournamentMatch tournamentMatch, TournamentMatches matches, DataTable dtGames)
        {
            #region Find UserID 2

            TournamentUsers tournamentUsers = new TournamentUsers();

            int wUserID = tournamentMatch.WhiteUserID;
            int bUserID = tournamentMatch.BlackUserID;

            DataRow[] drWhite = dtTUser.Select("UserID = " + wUserID);
            DataRow[] drBlack = dtTUser.Select("UserID = " + bUserID);

            if (drWhite.Length == 0)
            {
                drWhite = dtTUser.Select("UserID2 = " + wUserID);
            }

            if (drBlack.Length == 0)
            {
                drBlack = dtTUser.Select("UserID2 = " + bUserID);
            }

            TournamentUser tournamentWUser = new TournamentUser(cxt, drWhite[0]);
            TournamentUser tournamentBUser = new TournamentUser(cxt, drBlack[0]);


            TournamentMatch tm = matches.GetByID(tournamentMatch.TournamentMatchID);

            #endregion

            if (tm.TournamentMatchStatusE == TournamentMatchStatusE.Scheduled ||
                tm.TournamentMatchStatusE == TournamentMatchStatusE.InProgress)
            {
                #region Points Calculation
                decimal wPoints = 0;
                decimal bPoints = 0;

                switch (tournamentMatch.TournamentMatchStatusE)
                {
                case TournamentMatchStatusE.Draw:
                    wPoints = 0.5m;
                    bPoints = 0.5m;
                    break;

                case TournamentMatchStatusE.WhiteBye:
                    wPoints = 0;
                    bPoints = 1;
                    break;

                case TournamentMatchStatusE.BlackBye:
                    wPoints = 1;
                    bPoints = 0;
                    break;

                case TournamentMatchStatusE.ForcedWhiteWin:
                    wPoints = 1;
                    bPoints = 0;
                    break;

                case TournamentMatchStatusE.ForcedWhiteLose:
                    wPoints = 0;
                    bPoints = 1;
                    break;

                case TournamentMatchStatusE.ForcedDraw:
                    wPoints = 0.5m;
                    bPoints = 0.5m;
                    break;

                default:
                    break;
                }

                tournamentBUser.TournamentPoints = tournamentBUser.TournamentPoints + bPoints;
                tournamentWUser.TournamentPoints = tournamentWUser.TournamentPoints + wPoints;
                #endregion
            }
            else
            {
                #region Points Calculation
                switch (tm.GameResultIDE)
                {
                case GameResultE.WhiteWin:
                    WhiteWin(tournamentMatch, tournamentWUser, tournamentBUser);
                    break;

                case GameResultE.WhiteLose:
                    WhiteLose(tournamentMatch, tournamentWUser, tournamentBUser);
                    break;

                case GameResultE.ForcedWhiteWin:
                    ForcedWhiteWin(tournamentMatch, tournamentWUser, tournamentBUser);
                    break;

                case GameResultE.ForcedWhiteLose:
                    ForcedWhiteLose(tournamentMatch, tournamentWUser, tournamentBUser);
                    break;

                case GameResultE.WhiteBye:
                    WhiteBye(tournamentMatch, tournamentWUser, tournamentBUser);
                    break;

                case GameResultE.BlackBye:
                    BlackBye(tournamentMatch, tournamentWUser, tournamentBUser);
                    break;

                case GameResultE.ForcedDraw:
                    ForcedDraw(tournamentMatch, tournamentWUser, tournamentBUser);
                    break;

                case GameResultE.Absent:
                    Absent(tournamentMatch, tournamentWUser, tournamentBUser);
                    break;

                case GameResultE.Draw:
                    ForcedDraw(tournamentMatch, tournamentWUser, tournamentBUser);
                    break;
                }
                #endregion
            }
            tournamentUsers.Add(tournamentWUser);
            tournamentUsers.Add(tournamentBUser);
            return(tournamentUsers);
            //tournamentUsers.Save(trans);
        }
Example #3
0
        static TournamentUsers GetTournamentPreliminaryWinners1(Cxt cxt, int tournamentID, int round, DataTable dtTournamentUsers)
        {
            TournamentUsers   tuWinners         = new TournamentUsers();
            TournamentMatches tournamentMatches = new TournamentMatches(cxt, GetTournamntPlayers(tournamentID));
            TournamentMatches tmW = new TournamentMatches();
            TournamentUsers   tuW = new TournamentUsers();
            TournamentUsers   tuL = new TournamentUsers();

            int wCounter = 0, bCounter = 0, dCounter = 0;

            foreach (DataRow item in tournamentMatches.DataTable.Rows)
            {
                TournamentMatch tournamentMatch = new TournamentMatch(cxt, item);

                TournamentUser tournamentUserB = null;
                TournamentUser tournamentUserW = null;


                switch (tournamentMatch.GameResultIDE)
                {
                case GameResultE.None:
                    break;

                case GameResultE.InProgress:
                    break;

                case GameResultE.WhiteWin:
                    bCounter       += 1;
                    tournamentUserW = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.WhiteUserID);
                    tournamentUserB = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.BlackUserID);
                    tuW.Add(tournamentUserW);
                    tuL.Add(tournamentUserB);
                    break;

                case GameResultE.WhiteLose:
                {
                    wCounter       += 1;
                    tournamentUserB = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.BlackUserID);
                    tournamentUserW = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.WhiteUserID);
                    tuW.Add(tournamentUserB);
                    tuL.Add(tournamentUserW);
                }
                break;

                case GameResultE.Draw:
                    dCounter += 1;
                    tmW.Add(tournamentMatch);
                    break;

                case GameResultE.Absent:
                    break;

                case GameResultE.NoResult:
                    break;

                case GameResultE.WhiteBye:
                    wCounter       += 1;
                    tournamentUserB = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.BlackUserID);
                    tournamentUserW = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.WhiteUserID);
                    tuW.Add(tournamentUserB);
                    tuL.Add(tournamentUserW);
                    break;

                case GameResultE.BlackBye:
                    bCounter       += 1;
                    tournamentUserW = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.WhiteUserID);
                    tournamentUserB = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.BlackUserID);
                    tuW.Add(tournamentUserW);
                    tuL.Add(tournamentUserB);
                    break;

                case GameResultE.ForcedWhiteWin:
                    bCounter       += 1;
                    tournamentUserW = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.WhiteUserID);
                    tournamentUserB = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.BlackUserID);
                    tuW.Add(tournamentUserW);
                    tuL.Add(tournamentUserB);
                    break;

                case GameResultE.ForcedWhiteLose:
                    wCounter       += 1;
                    tournamentUserB = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.BlackUserID);
                    tournamentUserW = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.WhiteUserID);
                    tuW.Add(tournamentUserB);
                    tuL.Add(tournamentUserW);
                    break;

                case GameResultE.ForcedDraw:
                    dCounter += 1;
                    tmW.Add(tournamentMatch);
                    break;

                default:
                    break;
                }
            }

            if (dCounter > 0)
            {
                foreach (DataRow item in tmW.DataTable.Rows)
                {
                    TournamentMatch tournamentMatch = new TournamentMatch(cxt, item);
                    if (tournamentMatch.EloWhiteAfter > tournamentMatch.EloBlackAfter)
                    {
                        TournamentUser tournamentUserW = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.WhiteUserID);
                        TournamentUser tournamentUserB = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.BlackUserID);
                        tuW.Add(tournamentUserW);
                        tuL.Add(tournamentUserB);
                    }
                    else if (tournamentMatch.EloBlackAfter > tournamentMatch.EloWhiteAfter)
                    {
                        TournamentUser tournamentUserB = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.BlackUserID);
                        TournamentUser tournamentUserW = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.WhiteUserID);
                        tuW.Add(tournamentUserB);
                        tuL.Add(tournamentUserW);
                    }
                    else
                    {
                        TournamentUser tournamentUserB = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.BlackUserID);
                        TournamentUser tournamentUserW = TournamentUser.GetTournamentUserById(cxt, tournamentID, tournamentMatch.WhiteUserID);
                        tuW.Add(tournamentUserB);
                        tuW.Add(tournamentUserW);
                    }
                }
            }
            if (tuL.Count > 0)
            {
                foreach (DataRow item in dtTournamentUsers.Rows)
                {
                    TournamentUser tu1 = new TournamentUser(cxt, item);

                    if (!tuL.Contains("UserID = " + tu1.UserID))
                    {
                        tuWinners.Add(tu1);
                    }
                }
            }
            return(tuWinners);
        }