protected Competition() { Results = new List<Result> { }; IsCryingCompetion = false; InitialTeams = new List<Team>(); EndNode = new Node { ParentNode = null }; DynamicPot = 0; }
private Node ApplyResultOnCompetition(Result result, Node rootNode) { var node = SearchNodeOfTeam(result.TeamWin, rootNode); if (node.ParentNode.Team == null) { node.ParentNode.Team = result.TeamWin; } return rootNode; }
private void AutoPlayForMissingTeam(Node rootNode) { if (rootNode == null) return; AutoPlayForMissingTeam(rootNode.BottomNode); AutoPlayForMissingTeam(rootNode.TopNode); CheckTeamWithoutOpponent(rootNode.BottomNode); CheckTeamWithoutOpponent(rootNode.TopNode); }
public Result CreateResult(Node rootNode, Team teamWin) { var nodeOfTeamWin = SearchNodeOfTeam(teamWin, rootNode); if (nodeOfTeamWin.ParentNode == null) { throw new ResultImpossibleException(); } var nodeOfTeamLoose = nodeOfTeamWin.ParentNode.BottomNode == nodeOfTeamWin ? nodeOfTeamWin.ParentNode.TopNode : nodeOfTeamWin.ParentNode.BottomNode; var result = new Result { TeamWin = teamWin, TeamLoose = nodeOfTeamLoose.Team, DepthOfTheGame = nodeOfTeamWin.DepthOfTheTree}; _teamService.UpdatePlayedGame(result); _resultRepo.Save(result); return result; }
public Node ApplyResultOnCompetition(Competition competition, Node nodeTree) { return competition.Results.OrderBy(x => x.Date).Aggregate(nodeTree, (current, result) => ApplyResultOnCompetition(result, current)); }
private Node SearchNodeOfTeam(Team team, Node rootNode) { if (rootNode.Team != null && rootNode.Team.Id == team.Id) { return rootNode; } Node tmpNode; if (rootNode.BottomNode != null) { tmpNode = SearchNodeOfTeam(team, rootNode.BottomNode); if (tmpNode != null) return tmpNode; } if (rootNode.TopNode != null) { tmpNode = SearchNodeOfTeam(team, rootNode.TopNode); if (tmpNode != null) return tmpNode; } return null; }
private Node CreateNode(List<Team> listTeamInFirstLevel, List<Team> teams, Competition competition, Node parentNode, int levelTree, int depth) { if (levelTree > depth) return null; if (!listTeamInFirstLevel.Any() && !teams.Any() && parentNode != null) return null; var node = new Node { ParentNode = parentNode, DepthOfTheTree = depth, Level = levelTree, CompetitionId = competition.Id }; if (!listTeamInFirstLevel.Any() && teams.Any() && (levelTree == depth - 1)) { var team = PickATeam(teams); node.TopNode = null; node.BottomNode = null; node.Team = team; } if (listTeamInFirstLevel.Any() && levelTree == depth) { var team = PickATeam(listTeamInFirstLevel); node.TopNode = null; node.BottomNode = null; node.Team = team; } node.TopNode = CreateNode(listTeamInFirstLevel, teams, competition, node, levelTree + 1, depth); node.BottomNode = CreateNode(listTeamInFirstLevel, teams, competition, node, levelTree + 1, depth); return node; }
private void CheckTeamWithoutOpponent(Node node) { if (node == null) return; if (node.BottomNode == null || node.BottomNode.Team == null) { if (node.BottomNode != null && node.BottomNode.Team == null) { CheckTeamWithoutOpponent(node.BottomNode); return; } if (node.TopNode != null && node.TopNode.Team != null) { node.Team = node.TopNode.Team; } } else if (node.TopNode == null || node.TopNode.Team == null) { if (node.TopNode != null && node.TopNode.Team == null) { CheckTeamWithoutOpponent(node.TopNode); return; } node.Team = node.BottomNode.Team; } }