/// <summary> /// Call after deserialization to get parent which leads to circular references. /// </summary> public void RebuildParentTree(Bracket parent) { this.Parent = parent; if (Left != null) { Left.RebuildParentTree(this); } if (Right != null) { Right.RebuildParentTree(this); } }
public void SetWinner(int winner) { if (FirstRoot == null) { return; } Bracket b = FirstRoot.NextBattle(); if (b != null) { b.Current = winner; } }
/// <summary> /// Generates GameObjects from tourney /// </summary> /// <param name="tournament"></param> /// <returns></returns> public Collection <GameObjectRobot> CreateGameObjects(Tournament tournament) { Collection <GameObjectRobot> objectList = new Collection <GameObjectRobot>(); if (tournament.Rules.Mode == TournamentMode.LastManStanding || tournament.Rules.Mode == TournamentMode.TeamLastTeamStanding) { foreach (Bracket bracket in tournament.Bracket.Root) { foreach (RobotLoader robot in Teams[bracket.Current - 1].Robots) { GameObjectRobot tank = new GameObjectRobot(robot); objectList.Add(tank); } } } else { Bracket b = tournament.Bracket.FirstRoot.NextBattle(); if (b.Left != null) { /*GameObjectRobot robot = new GameObjectRobot(Teams[b.Left.Current - 1].Robots[0]); * objectList.Add(robot);*/ foreach (RobotLoader robot in Teams[b.Left.Current - 1].Robots) { GameObjectRobot tank = new GameObjectRobot(robot); objectList.Add(tank); } } if (b.Right != null) { /*GameObjectRobot robot = new GameObjectRobot(Teams[b.Right.Current - 1].Robots[0]); * objectList.Add(robot);*/ foreach (RobotLoader robot in Teams[b.Right.Current - 1].Robots) { GameObjectRobot tank = new GameObjectRobot(robot); objectList.Add(tank); } } } return(objectList); }
public TournamentBracket(int teams, bool flat) { this.Teams = teams; Root = new Collection <Bracket>(); if (flat) { maxDepth = 0; for (int i = 1; i < teams + 1; i++) { Bracket rootBracket = new Bracket(); rootBracket.BuildTree(0, i, i, null); Root.Add(rootBracket); } } else { Bracket rootBracket = new Bracket(); maxDepth = rootBracket.BuildTree(0, 0, teams, null); Root.Add(rootBracket); } }
public int BuildTree(int deepth, int min, int max, Bracket parent) { Deepth = deepth; Parent = parent; int diff = max - min; int middle = min + Convert.ToInt32(Math.Ceiling(diff / 2.0)); int deepth1 = deepth, deepth2 = deepth; if (middle > min && middle < max) { Left = new Bracket(); deepth1 = Left.BuildTree(deepth + 1, min, middle, this); } if (middle < max) { Right = new Bracket(); deepth2 = Right.BuildTree(deepth + 1, middle, max, this); } if (Left == null && Right == null) { Current = middle; } if (deepth1 > deepth2) { Round = deepth1 - deepth + 1; // Starting with 1 return(deepth1); } else { Round = deepth2 - deepth + 1; // Starting with 1 return(deepth2); } }