예제 #1
0
        public override string Second()
        {
            string        filename = GetFilename();
            List <string> input    = System.IO.File.ReadAllLines(filename).ToList();

            PRINT = false;
            RecursiveCombat game = new RecursiveCombat(input);

            game.PlayGame();
            var result = game.Score();

            return(result.ToString());
        }
예제 #2
0
            protected override void SetResultOfRound()
            {
                // CHECK IF A RECURSIVE GAME SHOULD HAPPEN

                // If both players have at least as many cards remaining
                // in their deck as the value of the card they just drew,
                // the winner of the round is determined by playing a new game of Recursive Combat.
                Player playerWon;

                bool playSubgame = Players.All(p => p.NrOfCards >= p.PlayedCard);

                if (playSubgame)
                {
                    if (PRINT)
                    {
                        Console.WriteLine("Playing a sub-game to determine the winner...");
                    }

                    var playersWithNewCards = Players.Select(p => new Player(p.Name, p.Cards.ToList().Take(p.PlayedCard).ToList())).ToList();
                    SubGame++;
                    var newGame = new RecursiveCombat(playersWithNewCards, SubGame);
                    var playerWonRecursiceGame = newGame.PlayGame();
                    playerWon = Players.FirstOrDefault(p => p.Name == playerWonRecursiceGame.Name);
                    var otherPlayer = Players.FirstOrDefault(p => p.Name != playerWonRecursiceGame.Name);
                    // note that the winner's card might be the lower-valued of the two cards
                    playerWon.WonCards(playerWon.PlayedCard, otherPlayer.PlayedCard);

                    if (PRINT)
                    {
                        Console.WriteLine($"...anyway, back to game {GameNr}.");
                    }
                }
                else
                {
                    // find player with the highest card!
                    playerWon = Players.OrderBy(p => p.PlayedCard).Reverse().FirstOrDefault();

                    CardsOnTable.Sort();
                    CardsOnTable.Reverse();
                    playerWon.WonCards(CardsOnTable);
                }

                if (PRINT)
                {
                    Console.WriteLine($"{playerWon.Name} wins round {Round} of game {GameNr}!");
                }

                // reset round!
                Players.ForEach(p => p.ResetRound());
                CardsOnTable = new List <int>();
            }
예제 #3
0
        public override bool Test2()
        {
            string        filename = GetTestFilename();
            List <string> input    = System.IO.File.ReadAllLines(filename).ToList();

            PRINT = false;
            RecursiveCombat game = new RecursiveCombat(input);

            game.PlayGame();
            var result = game.Score();

            bool testSucceeded = result == 291;

            return(testSucceeded);
        }