Exemple #1
0
        public void ShouldCallout_AfterTurnEnd()
        {
            game = new DosGame(new NonShufflingDealer(TwentyGreenSharps), 2, 3);
            game.Start();
            game.MatchCenterRowCard(Player0, GreenSharp, GreenSharp);
            game.AddCardToCenterRow(Player0, GreenSharp);
            game.EndTurn(Player0);

            game.Callout(Player1, Player0).ShouldBeSuccess();
        }
Exemple #2
0
        public void ShouldNotCallDos_AfterNextPlayerMadeAMove()
        {
            game = new DosGame(new NonShufflingDealer(TwentyGreenSharps), 2, 3);
            game.Start();
            game.MatchCenterRowCard(Player0, GreenSharp, GreenSharp);
            game.AddCardToCenterRow(Player0, GreenSharp);
            game.EndTurn(Player0);

            game.Draw(Player1);
            game.CallDos(Player1).ShouldBeFail();
        }
Exemple #3
0
        private Result ChooseMove(DosGame game)
        {
            if (game.CurrentState.CanMatch)
            {
                var match = MakeMatch(game);
                if (match != null)
                {
                    var(matchers, target) = match.Value;
                    game.PublicLog($"`Match {matchers.ToLogString()} on {target.ToString()}` ({target.MatchWith(matchers).Message()})");
                    return(game.MatchCenterRowCard(this, target, matchers));
                }
            }

            if (game.CurrentState.CanAdd)
            {
                var card = ChooseCardForAdding(game);
                game.PublicLog($"`Add {card}`");
                return(game.AddCardToCenterRow(this, card));
            }

            if (game.CurrentState.CanDraw)
            {
                game.PublicLog("`Draw`");
                return(game.Draw(this));
            }

            if (game.CurrentState is TriggeredSwapGameState)
            {
                var swapTarget = game.Players
                                 .Where(p => p != this && p.IsActive())
                                 .OrderBy(p => p.Hand.Count)
                                 .First();
                game.PublicLog($"`Swapping with {swapTarget}`");
                return(game.SwapWith(this, swapTarget));
            }

            game.PublicLog("`Done`");
            return(game.EndTurn(this));
        }
Exemple #4
0
        private static void Main()
        {
            var game = new DosGame(new ShufflingDealer(Decks.Classic), 1, 7);
            var p    = game.Players.First();

            while (true)
            {
                var line = Console.ReadLine();
                line = line?.ToLowerInvariant().Trim();
                if (line == "quit")
                {
                    return;
                }

                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                if (line == "dos cards" || line == "dosc")
                {
                    Console.WriteLine(string.Join(Environment.NewLine, game.PersonalGameTableLines(p)));
                    continue;
                }

                if (line == "dosd")
                {
                    Console.WriteLine(game.EndTurn(p));
                    continue;
                }

                if (line.StartsWith("dos play "))
                {
                    var cardString = line.Substring(9).Trim();
                    Console.WriteLine(
                        CardParser.TryParseShortCard(cardString, out var card)
                            ? game.AddCardToCenterRow(p, card).Message
                            : $"Did not recognise the card \"{cardString}\", expected something like b9");
                    continue;
                }

                if (line.StartsWith("dos match "))
                {
                    var cardWords        = line.Substring(10).Split(" ", StringSplitOptions.RemoveEmptyEntries);
                    var cards            = new List <Card>();
                    var target           = (Card?)null;
                    var lookingForTarget = false;
                    foreach (var cardWord in cardWords)
                    {
                        if (!lookingForTarget)
                        {
                            if (cardWord == "on")
                            {
                                lookingForTarget = true;
                                continue;
                            }

                            if (CardParser.TryParseShortCard(cardWord, out var card))
                            {
                                cards.Add(card);
                            }
                        }
                        else
                        {
                            if (CardParser.TryParseShortCard(cardWord, out var card))
                            {
                                target = card;
                            }

                            break;
                        }
                    }

                    if (cards.IsEmpty() || target == null)
                    {
                        Console.WriteLine("Failed to parse your matching cards, sorry");
                    }
                    else
                    {
                        Console.WriteLine(game.MatchCenterRowCard(p, target.Value, cards.ToArray()));
                    }
                }
            }
        }