public BinaryTreeNode AddRoot(matches elem) { root = new BinaryTreeNode { data = elem }; return(root); }
public BinaryTreeNode AddRight(BinaryTreeNode node, matches elem) { var newNode = new BinaryTreeNode { data = elem }; node.right = newNode; return(newNode); }
private static void ex6() { Random rnd = new Random(); var tree = new BinaryTree(); string[] teams = { "BEL", "FRA", "BRA", "ENG", "URU", "CRO", "POR", "SPA", "ARG", "COL", "MEX", "SWI", "ITA", "GER", "CHI", "SWE" }; matches[] match = new matches[teams.Length / 2]; matches empmat = new matches(); empmat.team1 = String.Empty; empmat.team2 = String.Empty; empmat.score1 = 0; empmat.score2 = 0; BinaryTreeNode[] node = new BinaryTreeNode[15]; node[0] = tree.AddRoot(empmat); node[1] = tree.AddLeft(node[0], empmat); node[2] = tree.AddRight(node[0], empmat); for (int i = 1, j = 3; i < (node.Length - 1) / 2; i++) { node[j] = tree.AddLeft(node[i], empmat); j++; node[j] = tree.AddRight(node[i], empmat); j++; } for (int i = 0, j = 0; i < match.Length; i++, j += 2) { matches matche = new matches(); matche.team1 = teams[j]; matche.team2 = teams[j + 1]; matche.score1 = rnd.Next(0, 5); matche.score2 = rnd.Next(0, 5); while (matche.score1 == matche.score2) { matche.score1 = rnd.Next(0, 5); matche.score2 = rnd.Next(0, 5); } match[i] = matche; } for (int i = node.Length - 1, j = match.Length - 1; j > -1; i--, j--) { node[i].data = match[j]; } for (int i = 6; i > -1; i--) { node[i].data = Nextmatch(node[i].left.data, node[i].right.data); } tree.PreOrderTraversal(); Console.WriteLine(); Console.ReadKey(); }
static matches Nextmatch(matches match1, matches match2) { string newteam1 = ""; string newteam2 = ""; Random rnd = new Random(); if (match1.score1 >= match1.score2) { newteam1 = match1.team1; } else { newteam1 = match1.team2; } if (match2.score1 >= match2.score2) { newteam2 = match2.team1; } else { newteam2 = match2.team2; } matches newmatch = new matches(); newmatch.team1 = newteam1; newmatch.team2 = newteam2; newmatch.score1 = rnd.Next(0, 5); newmatch.score2 = rnd.Next(0, 5); while (newmatch.score1 == newmatch.score2) { newmatch.score1 = rnd.Next(0, 5); newmatch.score2 = rnd.Next(0, 5); } return(newmatch); }
public ActionResult SchedualMatch(string club2id, string gameid, string loca, DateTime dateof) { List <users> ul = (List <users>)Session["Data"]; int userid = ul[0].userid; using (var context = new Entities()) { int clubid = (from c in context.clubs where c.userid == userid select c.clubid).SingleOrDefault(); matches mch = new matches { club1 = clubid, club2 = int.Parse(club2id), gameid = int.Parse(gameid), loc = loca, C_date = dateof, C_status = true }; context.matches.Add(mch); context.SaveChanges(); TempData["Message"] = "Match scdual request has been made!"; return(RedirectToAction("match-scheduals")); } }
get => GetValue(ref matches); set => SetValue(ref matches, value);