예제 #1
0
 public void CloseMatch(DartGameParameters gameParameters)
 {
     foreach (var player in gameParameters.Players)
     {
         player.ClearUndo();
     }
 }
예제 #2
0
        public void AcceptScore(DartGameParameters parameters)
        {
            var currentPlayer = parameters.Players[parameters.CurrentPlayer];

            var undoItem = new UndoItem
            {
                Score            = currentPlayer.CurrentScore,
                CurrentDartCount = currentPlayer.CurrentDartCount - currentPlayer.LastDarts.Count,
            };

            currentPlayer.UndoItems.Add(undoItem);

            undoItem.HitsBull = currentPlayer.OldHits.ContainsKey(25)
                ? currentPlayer.OldHits[25]
                : currentPlayer.HitsBull;

            undoItem.Hits20 = currentPlayer.OldHits.ContainsKey(20) ? currentPlayer.OldHits[20] : currentPlayer.Hits20;
            undoItem.Hits19 = currentPlayer.OldHits.ContainsKey(19) ? currentPlayer.OldHits[19] : currentPlayer.Hits19;
            undoItem.Hits18 = currentPlayer.OldHits.ContainsKey(18) ? currentPlayer.OldHits[18] : currentPlayer.Hits18;
            undoItem.Hits17 = currentPlayer.OldHits.ContainsKey(17) ? currentPlayer.OldHits[17] : currentPlayer.Hits17;
            undoItem.Hits16 = currentPlayer.OldHits.ContainsKey(16) ? currentPlayer.OldHits[16] : currentPlayer.Hits16;
            undoItem.Hits15 = currentPlayer.OldHits.ContainsKey(15) ? currentPlayer.OldHits[15] : currentPlayer.Hits15;

            currentPlayer.AcceptCricketScores();

            currentPlayer.CurrentScore += parameters.DartTotal;

            currentPlayer.MergeLastDarts(false, new Leg
            {
                Id       = parameters.CurrentGameId,
                IsWinner = parameters.IsGameOver
            }, parameters.CurrentTurn);

            CheckGamesState(parameters.Players);
        }
예제 #3
0
        public void AcceptScore(DartGameParameters parameters)
        {
            var currentPlayer = parameters.Players[parameters.CurrentPlayer];

            var undoItem = new UndoItem
            {
                Score            = currentPlayer.CurrentScore,
                CurrentDartCount = currentPlayer.CurrentDartCount - currentPlayer.LastDarts.Count,
            };

            currentPlayer.UndoItems.Add(undoItem);

            if (parameters.IsBust)
            {
                // If player busts then no value is recorded
                currentPlayer.RemoveDartScores();
                currentPlayer.InterimScore = parameters.Players[parameters.CurrentPlayer].CurrentScore;
            }

            currentPlayer.MergeLastDarts(false, new Leg
            {
                Id       = parameters.CurrentGameId,
                IsWinner = parameters.IsGameOver
            }, parameters.CurrentTurn);

            if (!parameters.IsBust)
            {
                parameters.Players[parameters.CurrentPlayer].CurrentScore -= parameters.DartTotal;
            }
        }
예제 #4
0
        public bool IsGameOver(DartGameParameters parameters)
        {
            var isAnyOpenScore = false;

            var winners = GetWinningPlayers(parameters.Players.ToList());

            if (winners.Count == 1)
            {
                var currentPlayer = parameters.Players[parameters.CurrentPlayer];

                var leader = winners.First();

                var currentPlayerIsLeader = currentPlayer.UniqueId == leader.UniqueId;

                if (currentPlayerIsLeader && ScorableCount(new List <Player> {
                    currentPlayer
                }) > 0 || ScorableCount(parameters.Players) > 2)
                {
                    isAnyOpenScore = true;
                }

                if (!currentPlayerIsLeader && ScorableCount(new List <Player> {
                    currentPlayer
                }) == 0 || ScorableCount(parameters.Players) > 1)
                {
                    isAnyOpenScore = true;
                }
            }
            else
            {
                isAnyOpenScore = ScorableCount(parameters.Players) > 0;
            }

            return(!isAnyOpenScore);
        }
예제 #5
0
        public void RejectScore(DartGameParameters parameters)
        {
            var currentPlayer = parameters.Players[parameters.CurrentPlayer];

            currentPlayer.DiscardLastDarts();

            currentPlayer.InterimScore = currentPlayer.CurrentScore;
        }
예제 #6
0
        public string ProcessScore(DartGameParameters parameters)
        {
            var currentPlayer = parameters.Players[parameters.CurrentPlayer];

            currentPlayer.InterimScore = currentPlayer.CurrentScore + parameters.DartTotal;

            return(parameters.DartTotal.ToString());
        }
예제 #7
0
        public List <Player> GetVictoriousPlayers(DartGameParameters gameParameters)
        {
            var winningPlayers = GetWinningPlayers(gameParameters.Players.ToList());

            foreach (var winningPlayer in winningPlayers)
            {
                winningPlayer.IsWinner = true;
            }

            return(winningPlayers);
        }
예제 #8
0
        public List <Tuple <int, string> > GetCheckOutHints(DartGameParameters parameters)
        {
            if (!parameters.Players.Any())
            {
                return(new List <Tuple <int, string> >());
            }

            return
                (_checkoutCard.Where(
                     m => m.Item1 == parameters.Players[parameters.CurrentPlayer].CurrentScore - parameters.DartTotal).ToList());
        }
예제 #9
0
        public void Undo(DartGameParameters gameParameters)
        {
            var playerToUndo = gameParameters.Players[gameParameters.CurrentPlayer];

            var undoItem = playerToUndo.PopUndo();

            if (undoItem != null)
            {
                playerToUndo.CurrentScore     = undoItem.Score;
                playerToUndo.InterimScore     = undoItem.Score;
                playerToUndo.CurrentDartCount = undoItem.CurrentDartCount;
            }
        }
예제 #10
0
        public string ProcessScore(DartGameParameters parameters)
        {
            var currentPlayer = parameters.Players[parameters.CurrentPlayer];

            currentPlayer.InterimScore = currentPlayer.CurrentScore - parameters.DartTotal;

            if (currentPlayer.InterimScore > 1)
            {
                return(parameters.DartTotal.ToString());
            }

            return(string.Empty);
        }
예제 #11
0
        public List <Tuple <int, string> > GetCheckOutForNextTurn(DartGameParameters parameters)
        {
            if (!parameters.Players.Any())
            {
                return(new List <Tuple <int, string> >());
            }

            return
                (_checkoutCard.Where(
                     m =>
                     m.Item2.Split(' ').Length <= 3 &&
                     m.Item1 == parameters.Players[parameters.CurrentPlayer].CurrentScore - parameters.DartTotal).ToList());
        }
예제 #12
0
        public int ProcessTotal(DartGameParameters parameters)
        {
            var currentScore = parameters.DartScore;

            // Is this a scoring opportunity
            if (_validScores.Any(m => m == currentScore.NumberHit))
            {
                // Convert a bull to a double 25 - makes handling this score easier
                if (currentScore.ScoreType == ScoreType.Bull)
                {
                    currentScore.Value     = 50;
                    currentScore.NumberHit = 25;
                    currentScore.ScoreType = ScoreType.Double;
                }

                Player currentPlayer = parameters.Players[parameters.CurrentPlayer];

                var startingHitCount = currentPlayer.GetNumberHitCount(currentScore.NumberHit);

                if (!IsScoreable(currentScore.NumberHit, parameters.Players.Except(new List <Player> {
                    currentPlayer
                })))
                {
                    currentPlayer.SetNumberHitCount(currentScore.NumberHit, Math.Min(GetScoreMultiplier(currentScore) + startingHitCount, 3));
                    currentScore.Value = 0;
                    return(0);
                }

                if (startingHitCount == HitsToOpenCloseScore)
                {
                    return(parameters.DartScore.Value);
                }

                var scoreInstances = GetScoreMultiplier(currentScore);

                currentPlayer.SetNumberHitCount(currentScore.NumberHit, Math.Min(scoreInstances + startingHitCount, 3));

                var endingHitCount = currentPlayer.GetNumberHitCount(currentScore.NumberHit);

                var scoreMultiplier = endingHitCount - startingHitCount;

                currentScore.Value = scoreMultiplier > 0 ? parameters.DartScore.Value - (currentScore.NumberHit * scoreMultiplier) : 0;

                return(currentScore.Value);
            }

            currentScore.Value = 0;

            return(0);
        }
예제 #13
0
        public void Undo(DartGameParameters gameParameters)
        {
            var playerToUndo = gameParameters.Players[gameParameters.CurrentPlayer];

            var undoItem = playerToUndo.PopUndo();

            if (undoItem != null)
            {
                playerToUndo.CurrentScore     = undoItem.Score;
                playerToUndo.InterimScore     = undoItem.Score;
                playerToUndo.CurrentDartCount = undoItem.CurrentDartCount;
                playerToUndo.Hits20           = undoItem.Hits20;
                playerToUndo.Hits19           = undoItem.Hits19;
                playerToUndo.Hits18           = undoItem.Hits18;
                playerToUndo.Hits17           = undoItem.Hits17;
                playerToUndo.Hits16           = undoItem.Hits16;
                playerToUndo.Hits15           = undoItem.Hits15;
                playerToUndo.HitsBull         = undoItem.HitsBull;

                CheckGamesState(gameParameters.Players);
            }
        }
예제 #14
0
 public bool IsGameOver(DartGameParameters parameters)
 {
     return(parameters.Players[parameters.CurrentPlayer].CurrentScore - parameters.DartTotal == 0 &&
            (parameters.DartScore.ScoreType == ScoreType.Bull || parameters.DartScore.ScoreType == ScoreType.Double));
 }
예제 #15
0
 public bool IsValidScore(DartGameParameters parameters)
 {
     return(true);
 }
예제 #16
0
 public List <Player> GetVictoriousPlayers(DartGameParameters getGameParameters)
 {
     return(new List <Player> {
         getGameParameters.Players.First(m => m.CurrentScore == 0)
     });
 }
예제 #17
0
 public List <Tuple <int, string> > GetCheckOutHints(DartGameParameters parameters)
 {
     return(new List <Tuple <int, string> >());
 }
예제 #18
0
 public bool IsValidScore(DartGameParameters parameters)
 {
     return(parameters.Players[parameters.CurrentPlayer].CurrentScore - parameters.DartTotal >= 2);
 }
예제 #19
0
 public int ProcessTotal(DartGameParameters parameters)
 {
     return(parameters.DartScore.Value);
 }