public void Execute(Deck deck, Teams teams, RoundContext roundContext)
        {
            var currentTeam = teams.CurrentTeam;

            currentTeam.AddPoint(deck.VisibleConcept, roundContext.CurrentRoundNumber);
            deck.Guess();
        }
Example #2
0
        public static RoundContext FromDto(RoundContextDto roundContextDto)
        {
            var roundContext = new RoundContext(roundContextDto.RoundNum);

            roundContext.Dealer    = roundContextDto.Dealer;
            roundContext.TrumpCard = roundContextDto.TrumpCard;

            foreach (var kvp in roundContextDto.Bids)
            {
                roundContext.Bids[kvp.Key] = kvp.Value;
            }

            foreach (var kvp in roundContextDto.PlayerDealOrder)
            {
                roundContext.PlayerDealOrder[kvp.Key] = kvp.Value;
            }

            foreach (var kvp in roundContextDto.Results)
            {
                roundContext.Results[kvp.Key] = kvp.Value;
            }

            foreach (var kvp in roundContextDto.Tricks)
            {
                roundContext.Tricks[kvp.Key] = TrickContextTransformer.FromDto(kvp.Value);
            }

            return(roundContext);
        }
Example #3
0
 public override MoveCollection NextMove(RoundContext context)
 {
     context.MyMoves
     .AddAttack(attack1)
     .AddAttack(attack2)
     .AddDefence(defence);
     return(context.MyMoves);
 }
Example #4
0
        private void updateState(RoundContext context)
        {
            roundCounter.nextRound();
            myScoreTotal       += context.MyDamage;
            opponentScoreTotal += context.OpponentDamage;

            bestFromLastMove = new BestAtackDefenceWraper();

            if (context.LastOpponentMoves != null)
            {
                List <Area> defences = new List <Area> {
                    Area.HookKick, Area.HookPunch, Area.LowKick, Area.LowKick
                };

                foreach (Move opponentMove in context.LastOpponentMoves?.GetDefences())
                {
                    attackHistory[opponentMove.Area].IncOpponentCountermovementsQuantity();
                    defences.Remove(opponentMove.Area);
                }

                // Find best possible attack for previous defence
                if (defences.Count() > 0)
                {
                    foreach (Area notOpponentDefence in defences)
                    {
                        if (Config.AttacksBaseValues[notOpponentDefence] > Config.AttacksBaseValues[bestFromLastMove.bestAttack])
                        {
                            bestFromLastMove.bestAttack      = notOpponentDefence;
                            bestFromLastMove.bestAttackValid = true;
                        }
                    }
                }
                else
                {
                    bestFromLastMove.bestAttackValid = false;
                }


                foreach (Move opponentMove in context.LastOpponentMoves?.GetAttacks())
                {
                    defenseHistory[opponentMove.Area].IncOpponentCountermovementsQuantity();
                    if (Config.DefensesBaseValues[opponentMove.Area] > Config.DefensesBaseValues[bestFromLastMove.bestDefence])
                    {
                        bestFromLastMove.bestDefence      = opponentMove.Area;
                        bestFromLastMove.bestDefenceValid = true;
                    }
                }
            }
        }
        public override MoveCollection NextMove(RoundContext context)
        {
            if (context.LastOpponentMoves?.Defences.Any(x => x.Area == this.attack1) == true)
            {
                this.attack1 = CreateRandomArea();
            }

            this.attack2 = CreateRandomArea();

            context.MyMoves
            .AddAttack(attack1)
            .AddAttack(attack2)
            .AddDefence(defence);
            return(context.MyMoves);
        }
Example #6
0
        public void MakeTurnTest()
        {
            IWizardFrontend testFrontend = null;

            var roundNum = 4;
            var deck     = new Deck();

            deck.Shuffle();

            var aiPlayer     = new AIPlayer(testFrontend, "wizardAI");
            var humanPlayer1 = new HumanPlayer(testFrontend, "Connor");
            var humanPlayer2 = new HumanPlayer(testFrontend, "Diana");

            for (int i = 0; i < roundNum; i++)
            {
                aiPlayer.TakeCard(deck.PopTop());
                humanPlayer1.TakeCard(deck.PopTop());
                humanPlayer2.TakeCard(deck.PopTop());
            }

            var testPlayers = new List <Player>
            {
                aiPlayer,
                humanPlayer1,
                humanPlayer2
            };

            var testGameContext = new GameContext(testPlayers);

            var trumpCard = new Card(CardValue.EIGHT, CardSuite.DIAMONDS);
            var curRound  = new RoundContext(roundNum);

            curRound.TrumpCard = trumpCard;
            testPlayers.ForEach(player => curRound.Bids[player]    = 0);
            testPlayers.ForEach(player => curRound.Results[player] = 0);
            var trick1 = new TrickContext(1);

            trick1.CardsPlayed[0] = (new Card(CardValue.JACK, CardSuite.CLUBS));

            curRound.Tricks[0]        = (trick1);
            testGameContext.Rounds[0] = (curRound);

            aiPlayer.MakeTurn(testGameContext);
        }
Example #7
0
        public override MoveCollection NextMove(RoundContext context)
        {
            myScoreTotal += context.MyDamage;
            opponentScoreTotal += context.OpponentDamage;

            context.MyMoves
                .AddAttack(attack1)
                .AddAttack(attack2);

            if (context.LastOpponentMoves?.GetAttacks().Any(x => x.Area == defence) == false)
            {
                defence = ChangeDefence(defence);
            }

            if (myScoreTotal >= opponentScoreTotal)
                context.MyMoves.AddAttack(CreateRandomAttack()); // 3 attacks, 0 defence
            else
                context.MyMoves.AddDefence(defence);
            return context.MyMoves;
        }
Example #8
0
        public override MoveCollection NextMove(RoundContext context)
        {
            updateState(context);

            foreach (OptimalizationAwareMove defence in defenseHistory.Values)
            {
                defence.ClearPromotion();
                if (bestFromLastMove.bestDefenceValid && defence.Area == bestFromLastMove.bestDefence)
                {
                    defence.Promote();
                }
            }

            foreach (OptimalizationAwareMove attack in attackHistory.Values)
            {
                attack.ClearPromotion();
                if (bestFromLastMove.bestAttackValid && attack.Area == bestFromLastMove.bestAttack)
                {
                    attack.Promote();
                }
            }

            IEnumerable <OptimalizationAwareMove> nextMoves = solver.solve(defenseHistory.Values.Concat(attackHistory.Values),
                                                                           energyPerRound);


            // Set attacks and defences
            foreach (var move in nextMoves)
            {
                if (move.Type == MoveType.Attack)
                {
                    context.MyMoves.AddAttack(move.Area);
                }
                else
                {
                    context.MyMoves.AddDefence(move.Area);
                }
            }

            return(context.MyMoves);
        }
Example #9
0
        public void MakeTurnTest()
        {
            var testFrontend = new ConsoleFrontend();

            var roundNum = 4;
            var deck     = new Deck();

            deck.Shuffle();

            var aiPlayer     = new AIPlayer(testFrontend, "wizardAI");
            var humanPlayer1 = new HumanPlayer(testFrontend, "Connor");
            var humanPlayer2 = new HumanPlayer(testFrontend, "Diana");

            for (int i = 0; i < roundNum; i++)
            {
                aiPlayer.TakeCard(deck.PopTop());
                humanPlayer1.TakeCard(deck.PopTop());
                humanPlayer2.TakeCard(deck.PopTop());
            }

            var testPlayers = new List <Player>
            {
                aiPlayer,
                humanPlayer1,
                humanPlayer2
            };
            var testGameContext = new GameContext(testPlayers);

            var curRound = new RoundContext(roundNum, CardSuite.DIAMONDS);
            var trick1   = new TrickContext(1);

            trick1.CardsPlayed.Add(new Card(CardValue.JACK, CardSuite.CLUBS));

            curRound.Tricks.Add(trick1);
            testGameContext.Rounds.Add(curRound);

            aiPlayer.MakeTurn(testGameContext);
        }
        public async Task <bool> DisplayTrickWinner(RoundContext curRound)
        {
            var curTrick = curRound.CurTrick;
            var winner   = curTrick.Winner;

            _componentProvider.SetMessageBoxText($"{winner.Name} won with a {curTrick.WinningCard.DisplayName}");

            var bid = curRound.Bids[winner];
            // note: technically the round is not over, so the results in the current round are from the prev trick => 1 is added
            var tricksTaken = curRound.Results[winner] + 1;

            _componentProvider.SetPlayerStatus(_playerOrdinals[winner.Name], $"{tricksTaken}/{bid}");

            _componentProvider.DiscardCardGroup.BringCardToFront(curTrick.WinningCard);
            _componentProvider.DiscardCardGroup.TransferAll
            (
                _componentProvider.CollapsedDiscardCardGroup,
                new AnimationBehavior()
            {
                Duration = 0.2
            }
            );
            await _componentProvider.RunQueuedAnimations();

            var winningCardGroup = _offScreenPlayerCardGroups[curTrick.Winner.Name];

            _componentProvider.CollapsedDiscardCardGroup.TransferAll
            (
                winningCardGroup,
                new AnimationBehavior()
            {
                Duration = 0.75, Rotations = 2
            }
            );
            await _componentProvider.RunQueuedAnimations();

            return(true);
        }
Example #11
0
        public void MakeBidTest()
        {
            IWizardFrontend testFrontend = null;

            var roundNum = 3;
            var deck     = new Deck();

            deck.Shuffle();

            var aiPlayer     = new AIPlayer(testFrontend, "wizardAI");
            var humanPlayer1 = new HumanPlayer(testFrontend, "Connor");
            var humanPlayer2 = new HumanPlayer(testFrontend, "Diana");

            for (int i = 0; i < roundNum; i++)
            {
                aiPlayer.TakeCard(deck.PopTop());
                humanPlayer1.TakeCard(deck.PopTop());
                humanPlayer2.TakeCard(deck.PopTop());
            }

            var testPlayers = new List <Player>
            {
                aiPlayer,
                humanPlayer1,
                humanPlayer2
            };
            var testGameContext = new GameContext(testPlayers);

            var trumpCard = new Card(CardValue.EIGHT, CardSuite.DIAMONDS);
            var curRound  = new RoundContext(roundNum);

            curRound.TrumpCard        = trumpCard;
            testGameContext.Rounds[0] = (curRound);

            aiPlayer.MakeBid(testGameContext);
        }
 public RoundRepository(RoundContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
 public async Task <bool> DisplayTrickWinner(RoundContext roundContext)
 {
     return(await _dispatcher.RunAsyncWithResult(CoreDispatcherPriority.Normal, async() => await _principalFrontend.DisplayTrickWinner(roundContext)));
 }
Example #14
0
 public RoundController(RoundContext context)
 {
     _context = context;
 }
Example #15
0
        private void updateState(RoundContext context)
        {
            roundCounter.nextRound();
            myScoreTotal       += context.MyDamage;
            opponentScoreTotal += context.OpponentDamage;
            battleContext.Add(context);

            bestFromLastMove = new BestAtackDefenceWraper();

            if (context.LastOpponentMoves != null)
            {
                // ________ Best attack and defence from n-th moves ________
                var lastNthRounds = battleContext.Skip(Math.Max(0, battleContext.Count() - Config.numLastRoundsConsidered))
                                    .Take(Config.numLastRoundsConsidered);

                Console.WriteLine("Rounds considered = " + lastNthRounds.Count());

                // clear history
                foreach (var move in attackHistory.Keys)
                {
                    attackHistory[move].TimesPresent  = 0;
                    defenseHistory[move].TimesPresent = 0;
                }

                //________ Count attacks from last n - th moves ________
                foreach (var round in lastNthRounds)
                {
                    // attacks
                    foreach (Move move in context.LastOpponentMoves?.GetDefences())
                    {
                        attackHistory[move.Area].TimesPresent += 1;
                    }
                    // defences
                    foreach (Move move in context.LastOpponentMoves?.GetAttacks())
                    {
                        defenseHistory[move.Area].TimesPresent += 1;
                    }
                }

                // ________ Best attack and defence from last move ________

                // best defenece from last move
                List <Area> defences = new List <Area> {
                    Area.HookKick, Area.HookPunch, Area.LowKick, Area.LowKick
                };
                foreach (Move opponentMove in context.LastOpponentMoves?.GetDefences())
                {
                    defences.Remove(opponentMove.Area);
                }

                // Find best possible attack for previous defence
                if (defences.Count() > 0)
                {
                    foreach (Area notOpponentDefence in defences)
                    {
                        if (Config.AttacksBaseValues[notOpponentDefence] > Config.AttacksBaseValues[bestFromLastMove.bestAttack])
                        {
                            bestFromLastMove.bestAttack      = notOpponentDefence;
                            bestFromLastMove.bestAttackValid = true;
                        }
                    }
                }
                else
                {
                    bestFromLastMove.bestAttackValid = false;
                }

                // best defence from last move
                foreach (Move opponentMove in context.LastOpponentMoves?.GetAttacks())
                {
                    if (Config.DefensesBaseValues[opponentMove.Area] > Config.DefensesBaseValues[bestFromLastMove.bestDefence])
                    {
                        bestFromLastMove.bestDefence      = opponentMove.Area;
                        bestFromLastMove.bestDefenceValid = true;
                    }
                }
            }
        }
 public void Execute(Deck deck, RoundContext roundContext)
 {
     roundContext.MoveToNextRound();
     deck.Reset();
 }
 public bool IsNextRoundTime(Deck deck, RoundContext roundContext) => deck.IsFinished;
Example #18
0
        public override MoveCollection NextMove(RoundContext context)
        {
            updateState(context);

            foreach (OptimalizationAwareMove defence in defenseHistory.Values)
            {
                defence.ClearPromotion();
                if (bestFromLastMove.bestDefenceValid && defence.Area == bestFromLastMove.bestDefence)
                {
                    defence.Promote();
                }
            }

            foreach (OptimalizationAwareMove attack in attackHistory.Values)
            {
                attack.ClearPromotion();
                if (bestFromLastMove.bestAttackValid && attack.Area == bestFromLastMove.bestAttack)
                {
                    attack.Promote();
                }
            }

            IEnumerable <OptimalizationAwareMove> nextMoves = solver.solve(defenseHistory.Values.Concat(attackHistory.Values),
                                                                           energyPerRound);

            // Set attacks and defences
            foreach (var move in nextMoves)
            {
                if (move.Type == MoveType.Attack)
                {
                    context.MyMoves.AddAttack(move.Area);
                }
                else
                {
                    context.MyMoves.AddDefence(move.Area);
                }
            }

            // <--
            if (context.LastOpponentMoves != null && context.MyMoves != null)
            {
                Console.WriteLine("My health = " + context.MyLifePoints.ToString());
                foreach (Move move in context.MyMoves?.GetAttacks())
                {
                    Console.WriteLine("my attack: " + move.Area.ToString());
                }
                foreach (Move move in context.MyMoves?.GetDefences())
                {
                    Console.WriteLine("my defence: " + move.Area.ToString());
                }

                Console.WriteLine("Oponents health = " + context.OpponentLifePoints.ToString());
                foreach (Move move in context.LastOpponentMoves?.GetAttacks())
                {
                    Console.WriteLine("oponent attack: " + move.Area.ToString());
                }
                foreach (Move move in context.LastOpponentMoves?.GetDefences())
                {
                    Console.WriteLine("oponent defence: " + move.Area.ToString());
                }
            }

            // <--


            return(context.MyMoves);
        }