private static void Absent(TournamentMatch tournamentMatch, TournamentUser tournamentWUser, TournamentUser tournamentBUser) { if (tournamentMatch.TournamentMatchStatusE == TournamentMatchStatusE.ForcedWhiteLose) { tournamentWUser.TournamentPoints = tournamentWUser.TournamentPoints - 0; tournamentBUser.TournamentPoints = tournamentBUser.TournamentPoints + 1; } else if (tournamentMatch.TournamentMatchStatusE == TournamentMatchStatusE.ForcedWhiteWin) { tournamentWUser.TournamentPoints = tournamentWUser.TournamentPoints + 1; tournamentBUser.TournamentPoints = tournamentBUser.TournamentPoints - 0; } else if (tournamentMatch.TournamentMatchStatusE == TournamentMatchStatusE.ForcedDraw) { tournamentWUser.TournamentPoints = tournamentWUser.TournamentPoints + 0.5m; tournamentBUser.TournamentPoints = tournamentBUser.TournamentPoints + 0.5m; } else if (tournamentMatch.TournamentMatchStatusE == TournamentMatchStatusE.BlackBye) { tournamentWUser.TournamentPoints = tournamentWUser.TournamentPoints + 1; tournamentBUser.TournamentPoints = tournamentBUser.TournamentPoints - 0; } else if (tournamentMatch.TournamentMatchStatusE == TournamentMatchStatusE.WhiteBye) { tournamentWUser.TournamentPoints = tournamentWUser.TournamentPoints - 0; tournamentBUser.TournamentPoints = tournamentBUser.TournamentPoints + 1; } }
private static void ForcedDraw(TournamentMatch tournamentMatch, TournamentUser tournamentWUser, TournamentUser tournamentBUser) { if (tournamentMatch.TournamentMatchStatusE == TournamentMatchStatusE.ForcedWhiteLose) { tournamentWUser.TournamentPoints = tournamentWUser.TournamentPoints - 0.5m; tournamentBUser.TournamentPoints = tournamentBUser.TournamentPoints + 0.5m; } else if (tournamentMatch.TournamentMatchStatusE == TournamentMatchStatusE.ForcedWhiteWin) { tournamentWUser.TournamentPoints = tournamentWUser.TournamentPoints + 0.5m; tournamentBUser.TournamentPoints = tournamentBUser.TournamentPoints - 0.5m; } }
static TournamentUsers GetPreliminaryRound(Cxt cxt, Tournament tournament, DataTable dtTournamentUsers) { double upperDiff = 0.0, lowerDiff = 0.0; TournamentUsers preliminaryRoundUsers = new TournamentUsers(); bool isTrue = false; //preliminaryRoundUsers = IsPreliminaryRound(dtTournamentUsers, ref isTrue); if (!isTrue) { for (int i = 1; i < 20; i++) { double dbl = Math.Pow(2, i); if (dbl >= dtTournamentUsers.Rows.Count) { upperDiff = dbl - Convert.ToDouble(dtTournamentUsers.Rows.Count); lowerDiff = Convert.ToDouble(dtTournamentUsers.Rows.Count) - Math.Pow(2, i - 1); DataView dv = new DataView(dtTournamentUsers); dv.Sort = "EloBefore DESC"; DataTable dt = dv.ToTable(); /* * if (lowerDiff == 1.0) * { * dt.Rows[0].Delete(); * preliminaryRoundUsers = new TournamentUsers(cxt, dt); * break; * } * else */ if (upperDiff == 0.0) { preliminaryRoundUsers = new TournamentUsers(cxt, dt); break; } for (int j = 0; j < lowerDiff * 2; j++) { DataRow dr = dt.Rows[j]; TournamentUser tu = new TournamentUser(cxt, dr); preliminaryRoundUsers.Add(tu); } break; } } } return(preliminaryRoundUsers); }
static void CreateKnockoutTournamentMatches(Cxt cxt, TournamentUsers tournamentUsers, TournamentMatches tournamentMatches, int round, Tournament Tournament) { if (tournamentUsers.Count > 0) { for (int i = 0; i < tournamentUsers.Count / 2; i++) { TournamentUser userW = new TournamentUser(cxt, tournamentUsers.DataTable.Rows[i]); TournamentUser userB = new TournamentUser(cxt, tournamentUsers.DataTable.Rows[tournamentUsers.Count - i - 1]); TournamentMatch tournamentMatch = new TournamentMatch(cxt, 0); tournamentMatch.Round = round; tournamentMatch.WhiteUserID = userW.UserID; tournamentMatch.BlackUserID = userB.UserID; tournamentMatch.TournamentID = Tournament.TournamentID; tournamentMatch.TournamentMatchTypeE = TournamentMatchTypeE.Normal; if (Tournament.TournamentStartDate > DateTime.Now) { tournamentMatch.MatchStartDate = Tournament.TournamentStartDate; } else { tournamentMatch.MatchStartDate = DateTime.Now; } if (Tournament.TournamentStartTime > DateTime.Now) { tournamentMatch.MatchStartTime = Tournament.TournamentStartTime; } else { tournamentMatch.MatchStartTime = DateTime.Now; } tournamentMatch.TimeMin = Tournament.TimeControlMin; tournamentMatch.TimeSec = Tournament.TimeControlSec; tournamentMatch.TournamentMatchStatusE = TournamentMatchStatusE.Scheduled; tournamentMatch.EloWhiteBefore = userW.EloBefore; tournamentMatch.EloBlackBefore = userB.EloBefore; tournamentMatch.CreatedBy = Ap.CurrentUserID; tournamentMatch.DateCreated = DateTime.Now; tournamentMatch.StatusID = (int)StatusE.Active; tournamentMatches.Add(tournamentMatch); } } }
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); }
public static Kv UpdateReplacePlayer(Cxt cxt, int tournamentID, int userID, int userID2) { Kv kv = new Kv(); SqlTransaction trans = null; try { trans = SqlHelper.BeginTransaction(Config.ConnectionString); bool result = TournamentMatch.GetTournamentMatchByTournamentUserID(cxt, tournamentID, userID); if (result) { kv.Set("Result", (int)MsgE.ErrorTournamentPlayerReplaceUser); return(kv); } TournamentUser tu = GetTournamentUserById(cxt, tournamentID, userID); BaseCollection.Execute(trans, "UpdateTournamentMatchWithUser", tournamentID, userID, userID2, cxt.CurrentUserID, 3); if (tu.UserID2 > 0) { userID = tu.UserID2; } BaseCollection.Execute(trans, "UpdateTournamentMatchWithUser", tournamentID, userID, userID2, cxt.CurrentUserID, 0); BaseCollection.Execute(trans, "UpdateTournamentMatchWithUser", tournamentID, userID, userID2, cxt.CurrentUserID, 1); SqlHelper.CommitTransaction(trans); kv.Set("Result", 0); } catch (Exception ex) { SqlHelper.RollbackTransaction(trans); Log.Write(cxt, ex); } return(kv); }
private static void CreateSchavengenMatches(Cxt cxt, Tournament tournament, TournamentUsers TournamentUsers) { TournamentUser userW = null; TournamentUser userB = null; if (TournamentUsers.Count > 0) { DataTable dt = null; if ((TournamentUsers.Count / 2) % 2 == 1) { dt = SchSystemsOdd(TournamentUsers.Count / 2); } else { dt = SchSystems(TournamentUsers.Count / 2); } foreach (DataRow item in dt.Rows) { userW = new TournamentUser(Cxt.Instance, TournamentUsers[Convert.ToInt32(item["Player1"]) - 1]); userB = new TournamentUser(Cxt.Instance, TournamentUsers[Convert.ToInt32(item["Player2"]) - 1]); TournamentMatch tournamentMatch = new TournamentMatch(cxt, 0); tournamentMatch.Round = Convert.ToInt32(item["Round"]); tournamentMatch.WhiteUserID = userW.UserID; tournamentMatch.BlackUserID = userB.UserID; tournamentMatch.TournamentID = tournament.TournamentID; tournamentMatch.TournamentMatchTypeE = TournamentMatchTypeE.Normal; if (tournament.TournamentStartDate > DateTime.Now) { tournamentMatch.MatchStartDate = tournament.TournamentStartDate; } else { tournamentMatch.MatchStartDate = DateTime.Now; } if (tournament.TournamentStartTime > DateTime.Now) { tournamentMatch.MatchStartTime = tournament.TournamentStartTime; } else { tournamentMatch.MatchStartTime = DateTime.Now; } tournamentMatch.TimeMin = tournament.TimeControlMin; tournamentMatch.TimeSec = tournament.TimeControlSec; tournamentMatch.TournamentMatchStatusE = TournamentMatchStatusE.Scheduled; tournamentMatch.EloWhiteBefore = userW.EloBefore; tournamentMatch.EloBlackBefore = userB.EloBefore; tournamentMatch.CreatedBy = cxt.CurrentUserID; tournamentMatch.DateCreated = DateTime.Now; tournament.TournamentMatches.Add(tournamentMatch); } } }
private static void CreateSchavengenMatches(Cxt cxt, Tournament tournament, TournamentUsers TournamentUsers, bool isWhite, int counter, int round, ref int val, ref int roundValue) { TournamentUser userW = null; TournamentUser userB = null; if (TournamentUsers.Count > 0) { DataTable dt = null; if ((TournamentUsers.Count / 2) % 2 == 1) { dt = SchSystemsOdd(TournamentUsers.Count / 2); } else { dt = SchSystems(TournamentUsers.Count / 2); } //DataRow[] dr = dt.Select("1=1", "Round desc"); //int round = i + counter * Convert.ToInt32(dr[0]["Round"]); foreach (DataRow item in dt.Rows) { if (val == round) { roundValue++; val = 0; } if (isWhite) { userW = new TournamentUser(Cxt.Instance, TournamentUsers[Convert.ToInt32(item["Player1"]) - 1]); userB = new TournamentUser(Cxt.Instance, TournamentUsers[Convert.ToInt32(item["Player2"]) - 1]); } else { userW = new TournamentUser(Cxt.Instance, TournamentUsers[Convert.ToInt32(item["Player2"]) - 1]); userB = new TournamentUser(Cxt.Instance, TournamentUsers[Convert.ToInt32(item["Player1"]) - 1]); } TournamentMatch tournamentMatch = new TournamentMatch(cxt, 0); tournamentMatch.Round = roundValue; tournamentMatch.WhiteUserID = userW.UserID; tournamentMatch.BlackUserID = userB.UserID; tournamentMatch.TournamentID = tournament.TournamentID; tournamentMatch.TournamentMatchTypeE = TournamentMatchTypeE.Normal; if (tournament.TournamentStartDate > DateTime.Now) { tournamentMatch.MatchStartDate = tournament.TournamentStartDate; } else { tournamentMatch.MatchStartDate = DateTime.Now; } if (tournament.TournamentStartTime > DateTime.Now) { tournamentMatch.MatchStartTime = tournament.TournamentStartTime; } else { tournamentMatch.MatchStartTime = DateTime.Now; } tournamentMatch.TimeMin = tournament.TimeControlMin; tournamentMatch.TimeSec = tournament.TimeControlSec; tournamentMatch.TournamentMatchStatusE = TournamentMatchStatusE.Scheduled; tournamentMatch.EloWhiteBefore = userW.EloBefore; tournamentMatch.EloBlackBefore = userB.EloBefore; tournamentMatch.CreatedBy = cxt.CurrentUserID; tournamentMatch.DateCreated = DateTime.Now; tournamentMatch.StatusID = (int)StatusE.Active; tournament.TournamentMatches.Add(tournamentMatch); val++; } } }
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); }
static void CalculateRoundRobinMatch(Cxt cxt, int tournamentID, Tournament tournament, List <DataRow> listTournamentUsers) { TournamentUser userW = null; TournamentUser userB = null; int dblRound = (tournament.DoubleRound) ? 2 : 1; int moderound = (listTournamentUsers.Count % 2 == 1) ? listTournamentUsers.Count : listTournamentUsers.Count - 1; for (int counter = 0; counter < dblRound; counter++) { DataTable dtCalculatePair = CalculateParing(listTournamentUsers.Count); for (int i = 0; i < dtCalculatePair.Rows.Count; i++) { DataRow drCal = dtCalculatePair.Rows[i]; if (counter == 1) { userW = new TournamentUser(cxt, listTournamentUsers[Convert.ToInt32(drCal["Player2"]) - 1]); userB = new TournamentUser(cxt, listTournamentUsers[Convert.ToInt32(drCal["Player1"]) - 1]); } else { userW = new TournamentUser(cxt, listTournamentUsers[Convert.ToInt32(drCal["Player1"]) - 1]); userB = new TournamentUser(cxt, listTournamentUsers[Convert.ToInt32(drCal["Player2"]) - 1]); } int round = Convert.ToInt32(drCal["Round"]); if (counter > 0) { round = round + moderound; } TournamentMatch tournamentMatch = new TournamentMatch(cxt, 0); tournamentMatch.Round = round; tournamentMatch.WhiteUserID = userW.UserID; tournamentMatch.BlackUserID = userB.UserID; tournamentMatch.TournamentID = tournamentID; tournamentMatch.TournamentMatchTypeE = TournamentMatchTypeE.Normal; if (tournament.TournamentStartDate > DateTime.Now) { tournamentMatch.MatchStartDate = tournament.TournamentStartDate; } else { tournamentMatch.MatchStartDate = DateTime.Now; } if (tournament.TournamentStartTime > DateTime.Now) { tournamentMatch.MatchStartTime = tournament.TournamentStartTime; } else { tournamentMatch.MatchStartTime = DateTime.Now; } tournamentMatch.TimeMin = tournament.TimeControlMin; tournamentMatch.TimeSec = tournament.TimeControlSec; tournamentMatch.TournamentMatchStatusE = TournamentMatchStatusE.Scheduled; if (userW.UserID == 2 || userB.UserID == 2) { tournamentMatch.TournamentMatchStatusE = TournamentMatchStatusE.Absent; } tournamentMatch.EloWhiteBefore = userW.EloBefore; tournamentMatch.EloBlackBefore = userB.EloBefore; tournamentMatch.CreatedBy = Ap.CurrentUserID; tournamentMatch.DateCreated = DateTime.Now; tournamentMatch.StatusID = (int)StatusE.Active; tournament.TournamentMatches.Add(tournamentMatch); } } }
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); }