Exemplo n.º 1
0
        public void GivenBettersPlacesMatchBets(Table table)
        {
            foreach (TableRow row in table.Rows)
            {
                TestUtilities.ParseBetterMatchBetPlacements(row, out string betterName, out int roundIndex, out int groupIndex, out int matchIndex, out string playerName);

                RoundBase round = createdRounds[roundIndex];
                GroupBase group = createdGroups[groupIndex];
                Match     match = group.Matches[matchIndex];

                bool betterNameIsNotEmpty = betterName.Length > 0;
                bool playerNameIsNotEmpty = playerName.Length > 0;

                if (betterNameIsNotEmpty && playerNameIsNotEmpty)
                {
                    Better better = round.Tournament.GetBetterByName(betterName);
                    Player player = match.FindPlayer(playerName);

                    better.Should().NotBeNull();
                    player.Should().NotBeNull();

                    better.PlaceMatchBet(match, player).Should().NotBeNull();
                }
            }
        }
Exemplo n.º 2
0
        public void CanSolveTie()
        {
            PlayerReference maruPlayerReference = tournament.RegisterPlayerReference("Maru");

            round.SetPlayersPerGroupCount(3);
            PlayerReference storkPlayerReference = tournament.RegisterPlayerReference("Stork");

            round.SetAdvancingPerGroupCount(2);
            PlayerReference taejaPlayerReference = tournament.RegisterPlayerReference("Taeja");

            BracketRound bracketRound = tournament.AddBracketRound();

            GroupBase group = round.Groups.First();

            foreach (Match match in round.Groups.First().Matches)
            {
                SystemTimeMocker.SetOneSecondAfter(match.StartDateTime);
                match.Player1.IncreaseScore(2);
            }

            group.HasProblematicTie().Should().BeTrue();
            group.HasSolvedTie().Should().BeFalse();
            group.SolveTieByChoosing(taejaPlayerReference.Id).Should().BeFalse();

            group.HasProblematicTie().Should().BeTrue();
            group.HasSolvedTie().Should().BeFalse();
            group.SolveTieByChoosing(storkPlayerReference.Id).Should().BeTrue();

            group.HasProblematicTie().Should().BeTrue();
            group.HasSolvedTie().Should().BeTrue();

            bracketRound.Groups.First().Matches[0].Player1.GetName().Should().Be("Taeja");
            bracketRound.Groups.First().Matches[0].Player2.GetName().Should().Be("Stork");
        }
Exemplo n.º 3
0
        protected bool PlayAvailableMatches(GroupBase group)
        {
            foreach (Match match in group.Matches)
            {
                int winningScore = (int)Math.Ceiling(match.BestOf / 2.0);

                bool matchShouldHaveStarted = match.StartDateTime < SystemTime.Now;
                bool matchIsNotFinished     = match.GetPlayState() != PlayStateEnum.Finished;

                if (matchShouldHaveStarted && matchIsNotFinished)
                {
                    // Give points to player with name that precedes the other alphabetically
                    bool increasePlayer1Score = match.Player1.GetName().CompareTo(match.Player2.GetName()) <= 0;
                    bool scoreIncreased;

                    if (increasePlayer1Score)
                    {
                        scoreIncreased = match.Player1.IncreaseScore(winningScore);
                    }
                    else
                    {
                        scoreIncreased = match.Player2.IncreaseScore(winningScore);
                    }

                    if (!scoreIncreased)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        public Result Handle(SelectPlayerThatAdvancesDuringProblematicTime command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie. Tournament ({ command.TournamentId }) not found."));
            }

            GroupBase group = tournament.GetGroupById(command.GroupId);

            if (group == null)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie. Group not found."));
            }

            List <PlayerReference> playerReferences = group.GetPlayerReferences();
            PlayerReference        playerReference  = playerReferences.FirstOrDefault(playerReference => playerReference.Name == command.PlayerName);

            if (playerReference == null)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie. Player not found."));
            }

            bool playerChosenSuccessfully = _tournamentRepository.SolveTieByChoosingPlayerInGroup(group, playerReference);

            if (!playerChosenSuccessfully)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Exemplo n.º 5
0
        public void WhenMatchesInTournamentNamedSwitchesPlayerReferences(string tournamentName, Table table)
        {
            using (TournamentRepository tournamentRepository = CreateTournamentRepository())
            {
                Tournament tournament = tournamentRepository.GetTournamentByName(tournamentName);

                foreach (TableRow row in table.Rows)
                {
                    ParsePlayerSwitch(row,
                                      out int roundIndex,
                                      out int groupIndex1,
                                      out int matchIndex1,
                                      out string playerName1,
                                      out int groupIndex2,
                                      out int matchIndex2,
                                      out string playerName2);

                    RoundBase roundBase = tournament.Rounds[roundIndex];

                    GroupBase groupBase1 = roundBase.Groups[groupIndex1];
                    Match     match1     = groupBase1.Matches[matchIndex1];
                    Player    player1    = match1.FindPlayer(playerName1);

                    GroupBase groupBase2 = roundBase.Groups[groupIndex2];
                    Match     match2     = groupBase2.Matches[matchIndex2];
                    Player    player2    = match2.FindPlayer(playerName2);

                    tournamentRepository.SwitchPlayersInMatches(player1, player2);
                }

                tournamentRepository.Save();
            }
        }
Exemplo n.º 6
0
        private void PlaceBetsOnAvailableMatchesInGroup(List <Better> betters, GroupBase group)
        {
            Random random       = new Random(133742069);
            int    matchCounter = 0;

            foreach (Domain.Match match in group.Matches)
            {
                if (match.GetPlayState() != PlayStateEnum.NotBegun)
                {
                    continue;
                }

                Better better = betters[0];

                if (matchCounter % 4 != 0)
                {
                    better.PlaceMatchBet(match, match.Player1);
                }

                for (int betterIndex = 1; betterIndex < betters.Count; ++betterIndex)
                {
                    Player player = random.Next(2) == 0 ? match.Player1 : match.Player2;

                    better = betters[betterIndex];
                    better.PlaceMatchBet(match, player);
                }

                matchCounter++;
            }
        }
Exemplo n.º 7
0
        public void WhenBestOfInMatchInGroupIsSetTo(int matchIndex, int groupIndex, int bestOf)
        {
            GroupBase group = createdGroups[groupIndex];
            Match     match = group.Matches[matchIndex];

            match.SetBestOf(bestOf);
        }
Exemplo n.º 8
0
        public void ThenWinningPlayerCannotBeFetchedFromMatchInGroup(int matchIndex, int groupIndex)
        {
            GroupBase group = createdGroups[groupIndex];
            Match     match = group.Matches[matchIndex];

            match.GetWinningPlayer().Should().BeNull();
        }
Exemplo n.º 9
0
        public void ThenBestOfInMatchInGroupShouldBe(int matchIndex, int groupIndex, int bestOf)
        {
            GroupBase group = createdGroups[groupIndex];
            Match     match = group.Matches[matchIndex];

            match.BestOf.Should().Be(bestOf);
        }
Exemplo n.º 10
0
        /**
         *  Returns the specified element's layout bounds as a Rectangle or null
         *  if the index is invalid, the corresponding element is null,
         *  <code>includeInLayout=false</code>,
         *  or if this layout's <code>target</code> property is null.
         *
         *  <p>Layout subclasses that support <code>useVirtualLayout=true</code> must
         *  override this method to compute a potentially approximate value for
         *  elements that are not in view.</p>
         *
         *  Param: index Index of the layout element.
         *
         *  Returns: The specified element's layout bounds.
         */
        internal virtual Rectangle GetElementBounds(int index) // TEMP internal
        {
            GroupBase g = Target;

            if (null == g)
            {
                return(null);
            }

            int n = g.NumberOfChildren;

            if ((index < 0) || (index >= n))
            {
                return(null);
            }

            ILayoutElement elt = (ILayoutElement)g.GetChildAt(index);

            if (null == elt || !elt.IncludeInLayout)
            {
                return(null);
            }

            float eltX = LayoutUtil.GetLayoutBoundsX((InvalidationManagerClient)elt);
            float eltY = LayoutUtil.GetLayoutBoundsY((InvalidationManagerClient)elt);
            float eltW = LayoutUtil.GetLayoutBoundsWidth((InvalidationManagerClient)elt);
            float eltH = LayoutUtil.GetLayoutBoundsHeight((InvalidationManagerClient)elt);

            return(new Rectangle(eltX, eltY, eltW, eltH));
        }
Exemplo n.º 11
0
        public void ThenParticipatingPlayersInGroupShouldBeMappedAccordingly(int groupIndex, Table table)
        {
            GroupBase group = createdGroups[groupIndex];

            foreach (TableRow row in table.Rows)
            {
                row["Match index"].Should().NotBeNullOrEmpty();
                row["Player 1 name"].Should().NotBeNull();
                row["Player 2 name"].Should().NotBeNull();

                ParseBracketGroupMatchSetup(row, out int matchIndex, out string player1Name, out string player2Name);

                if (player1Name.Length > 0)
                {
                    group.Matches[matchIndex].Player1.GetName().Should().Be(player1Name);
                }
                else
                {
                    group.Matches[matchIndex].Player1.PlayerReferenceId.Should().BeEmpty();
                }

                if (player2Name.Length > 0)
                {
                    group.Matches[matchIndex].Player2.GetName().Should().Be(player2Name);
                }
                else
                {
                    group.Matches[matchIndex].Player2.PlayerReferenceId.Should().BeEmpty();
                }
            }
        }
Exemplo n.º 12
0
        internal void UpdateScrollRect(float width, float height) // TEMP internal
        {
            //if (Target.Id == "view")
            //    Debug.Log("LayoutBase.UpdateScrollRect: " + width + ", " + height);

            GroupBase g = Target;

            if (null == g)
            {
                return;
            }

            //if (Target.Id == "contentGroup")
            //    Debug.Log("ClipAndEnableScrolling: " + ClipAndEnableScrolling);

            if (ClipAndEnableScrolling)
            {
                float hsp = _horizontalScrollPosition;
                float vsp = _verticalScrollPosition;

                //if (Target.Id == "view")
                //    Debug.Log("g.ScrollRect clipped " + new Rectangle(hsp, vsp, width, height));

                g.ScrollRect = new Rectangle(hsp, vsp, width, height);
            }
            else
            {
                //g.ScrollRect = null;

                //if (Target.Id == "view")
                //    Debug.Log("g.ScrollRect " + new Rectangle(0, 0, width, height));

                g.ScrollRect = null; // new Rectangle(0, 0, width, height);
            }
        }
Exemplo n.º 13
0
        public static List <PlayerReference> FetchFrom(GroupBase group)
        {
            if (group.GetPlayState() == PlayStateEnum.Finished)
            {
                PlayerStandingsSolver playerStandingsSolver = new PlayerStandingsSolver();
                List <StandingsEntry <PlayerReference> > playerReferences = playerStandingsSolver.FetchFrom(group);
                playerReferences = FilterAdvancingPlayers(group, playerReferences);

                if (group.HasProblematicTie())
                {
                    playerReferences = FilterTyingPlayers(group, playerReferences);
                    playerReferences.AddRange(group.ChoosenTyingPlayerEntries);
                }

                List <PlayerReference> advancingPlayers = new List <PlayerReference>();

                foreach (StandingsEntry <PlayerReference> entry in playerReferences)
                {
                    advancingPlayers.Add(entry.Object);
                }

                return(advancingPlayers);
            }

            return(new List <PlayerReference>());
        }
Exemplo n.º 14
0
        public void GivenScoreIsAddedToPlayersInGivenMatchesInGroups(Table table)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            foreach (TableRow row in table.Rows)
            {
                TestUtilities.ParseScoreAddedToMatchPlayer(row, out int _, out int groupIndex, out int matchIndex, out string scoringPlayer, out int scoreAdded);

                GroupBase group = createdGroups[groupIndex];
                Match     match = group.Matches[matchIndex];

                SystemTimeMocker.SetOneSecondAfter(match.StartDateTime);

                Player player = match.FindPlayer(scoringPlayer);

                if (player != null)
                {
                    player.IncreaseScore(scoreAdded);
                }
                else
                {
                    throw new Exception("Invalid player name in given match within given group");
                }
            }
        }
Exemplo n.º 15
0
        private void RunTestsWithFivePlayers(GroupBase group)
        {
            group.Matches[0].Player1.GetName().Should().Be("Maru");
            group.Matches[0].Player2.GetName().Should().Be("Rain");

            group.Matches[1].Player1.GetName().Should().Be("Stork");
            group.Matches[1].Player2.GetName().Should().Be("Bomber");

            group.Matches[2].Player1.GetName().Should().Be("Rain");
            group.Matches[2].Player2.GetName().Should().Be("Bomber");

            group.Matches[3].Player1.GetName().Should().Be("Maru");
            group.Matches[3].Player2.GetName().Should().Be("Taeja");

            group.Matches[4].Player1.GetName().Should().Be("Bomber");
            group.Matches[4].Player2.GetName().Should().Be("Taeja");

            group.Matches[5].Player1.GetName().Should().Be("Rain");
            group.Matches[5].Player2.GetName().Should().Be("Stork");

            group.Matches[6].Player1.GetName().Should().Be("Taeja");
            group.Matches[6].Player2.GetName().Should().Be("Stork");

            group.Matches[7].Player1.GetName().Should().Be("Bomber");
            group.Matches[7].Player2.GetName().Should().Be("Maru");

            group.Matches[8].Player1.GetName().Should().Be("Stork");
            group.Matches[8].Player2.GetName().Should().Be("Maru");

            group.Matches[9].Player1.GetName().Should().Be("Taeja");
            group.Matches[9].Player2.GetName().Should().Be("Rain");
        }
Exemplo n.º 16
0
        public void SolvingTieWhenThereIsNoTieDoesNothing()
        {
            PlayerReference maruPlayerReference  = tournament.RegisterPlayerReference("Maru");
            PlayerReference storkPlayerReference = tournament.RegisterPlayerReference("Stork");
            PlayerReference taejaPlayerReference = tournament.RegisterPlayerReference("Taeja");

            round.SetPlayersPerGroupCount(3);

            GroupBase group = round.Groups.First();
            Match     match;

            match = round.Groups.First().Matches[0];
            SystemTimeMocker.SetOneSecondAfter(match.StartDateTime);
            match.Player1.IncreaseScore(2);

            match = round.Groups.First().Matches[1];
            SystemTimeMocker.SetOneSecondAfter(match.StartDateTime);
            match.Player2.IncreaseScore(2);

            match = round.Groups.First().Matches[2];
            SystemTimeMocker.SetOneSecondAfter(match.StartDateTime);
            match.Player1.IncreaseScore(2);

            group.HasProblematicTie().Should().BeFalse();
            group.SolveTieByChoosing(maruPlayerReference.Id).Should().BeFalse();
        }
Exemplo n.º 17
0
        public void ThenPlayStateOfGroupIsSetTo(int groupIndex, string playStateString)
        {
            GroupBase group = createdGroups[groupIndex];

            PlayStateEnum playState = ParsePlayStateString(playStateString);

            group.GetPlayState().Should().Be(playState);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Initialize a new instance <see cref="GroupItemControl"/>
 /// </summary>
 protected GroupItemControl()
 {
     groupBase   = new GroupBase(this);
     Items       = new GroupItemCollection(this);
     columns     = 1;
     chunks      = new Chunks <GroupItemElement>();
     contentSize = Size.Empty;
 }
Exemplo n.º 19
0
        public void Report(GroupBase group, TournamentIssues issue)
        {
            int    roundIndex  = GetIndexOf(group.Round);
            int    groupIndex  = GetIndexOf(group);
            string description = GetDescriptionFor(issue);

            Issues.Add(TournamentIssue.Create(roundIndex, groupIndex, -1, description));
        }
Exemplo n.º 20
0
        public void ThenMatchInGroupShouldBeInState(int matchIndex, int groupIndex, string playStateString)
        {
            PlayStateEnum playState = ParsePlayStateString(playStateString);

            GroupBase group = createdGroups[groupIndex];
            Match     match = group.Matches[matchIndex];

            match.GetPlayState().Should().Be(playState);
        }
Exemplo n.º 21
0
 protected static void CheckGroupValidity <GroupType>(GroupBase group)
 {
     group.Should().NotBeNull();
     group.Should().BeOfType <GroupType>();
     group.Id.Should().NotBeEmpty();
     group.Matches.Should().NotBeEmpty();
     group.RoundId.Should().NotBeEmpty();
     group.Round.Should().NotBeNull();
 }
Exemplo n.º 22
0
        public void PlayerInGroupAndPlayerInGroupSwitchesMatches(string player1Name, int group1Index, string player2Name, int group2Index)
        {
            GroupBase group1 = createdGroups[group1Index];
            GroupBase group2 = createdGroups[group2Index];

            Player player1 = FindPlayerInGroup(player1Name, group1);
            Player player2 = FindPlayerInGroup(player2Name, group2);

            PlayerSwitcher.SwitchMatchesOn(player1, player2);
        }
Exemplo n.º 23
0
 public MatchBetTests()
 {
     user       = User.Create("Stålberto");
     tournament = Tournament.Create("GSL 2019");
     round      = tournament.AddBracketRound();
     tournament.RegisterPlayerReference("Maru");
     tournament.RegisterPlayerReference("Stork");
     group = round.Groups.First();
     match = group.Matches.First();
 }
Exemplo n.º 24
0
        internal virtual void ScrollPositionChanged() // TEMP internal (protected)
        {
            GroupBase g = Target;

            if (null == g)
            {
                return;
            }

            UpdateScrollRect(g.Width, g.Height);
        }
Exemplo n.º 25
0
 public static GroupDto ConvertToGroupDto(GroupBase group)
 {
     return(new GroupDto()
     {
         Id = group.Id,
         ContestType = group.ContestType.ToString(),
         SortOrder = group.SortOrder,
         Name = group.Name,
         Matches = group.Matches.Select(match => ConvertToMatchDto(match)).ToList()
     });
 }
Exemplo n.º 26
0
        private void RunTestsWithThreePlayers(GroupBase group)
        {
            group.Matches[0].Player1.GetName().Should().Be("Maru");
            group.Matches[0].Player2.GetName().Should().Be("Taeja");

            group.Matches[1].Player1.GetName().Should().Be("Taeja");
            group.Matches[1].Player2.GetName().Should().Be("Stork");

            group.Matches[2].Player1.GetName().Should().Be("Stork");
            group.Matches[2].Player2.GetName().Should().Be("Maru");
        }
Exemplo n.º 27
0
        public TournamentIssueReporterTests()
        {
            tournament = Tournament.Create("GSL 2019");
            round      = tournament.AddBracketRound();
            tournament.RegisterPlayerReference("Maru");
            tournament.RegisterPlayerReference("Stork");
            group = round.Groups.First();
            match = group.Matches.First();

            tournamentIssueReporter = new TournamentIssueReporter();
        }
Exemplo n.º 28
0
        private static List <StandingsEntry <PlayerReference> > FilterTyingPlayers(GroupBase group, List <StandingsEntry <PlayerReference> > playerStandings)
        {
            List <StandingsEntry <PlayerReference> > nonFilteredPlayers = new List <StandingsEntry <PlayerReference> >();

            foreach (StandingsEntry <PlayerReference> entry in group.FindProblematiclyTyingPlayers())
            {
                nonFilteredPlayers.Remove(entry);
            }

            return(nonFilteredPlayers);
        }
Exemplo n.º 29
0
 public static GroupState Create(GroupBase group)
 {
     if (group == null)
     {
         throw new ArgumentNullException("group");
     }
     return(new GroupState(group.Id)
     {
         _createOn = group.CreateOn
     }.InternalModify(group));
 }
Exemplo n.º 30
0
        internal float DragScrollRegionSizeVertical   = 20; // TEMP internal

        internal void InvalidateTargetSizeAndDisplayList()  // TEMP internal (protected)
        {
            GroupBase g = Target;

            if (null == g)
            {
                return;
            }

            g.InvalidateSize();
            g.InvalidateDisplayList();
        }