Exemplo n.º 1
0
        public void AuotComplete()
        {
            while (Winner == null)
            {
                NextRound(new Deck(true, true));

                CurrentRound.AutoComplete();

                // for debugging
                //Console.WriteLine(CurrentRound.ToString());
            }
        }
Exemplo n.º 2
0
 public void MakeVote(Vote vote)
 {
     try
     {
         vote.Name = playersDict[vote.UserId].Name;
         CurrentRound.AddVote(vote);
     }
     catch (Exception ex)
     {
         Console.WriteLine("MakeVote.ex :" + ex.Message);
     }
 }
Exemplo n.º 3
0
 public void PickNextPresident(int playerId)
 {
     try
     {
         CurrentRound.MoveToNextRound();
         CurrentRound.PresidentId = playerId;
     }
     catch (Exception ex)
     {
         Console.WriteLine("PickNextPresident.ex: " + ex.Message);
     }
 }
Exemplo n.º 4
0
        public void Drive()
        {
            int numOfPlayers   = Input.GetNumOfPlayers();
            int buttonPosition = Input.GetButtonPosition();
            int myPosition     = Input.GetMyPosition();

            List <Tuple <string, int> > players = Input.GetPlayerNamesAndStackSizes(numOfPlayers).ToList();

            StartNewRound(numOfPlayers, myPosition, buttonPosition, players.Select(p => p.Item1).ToList(), players.Select(p => p.Item2).ToList());

            CurrentRound.Drive();
        }
Exemplo n.º 5
0
        public void NextRound()
        {
            var nextRoundNumber = CurrentRound.RoundNumber + 1;

            if (nextRoundNumber > MaxRound)
            {
                End = true;
            }
            else
            {
                CurrentRound.StartRound(nextRoundNumber);
            }
        }
Exemplo n.º 6
0
 public void MoveToNextTurn()
 {
     try
     {
         CurrentRound.MoveToNextRound();
         presidentIndex           = ((++presidentIndex) % AlivePlayers.Count);
         CurrentRound.PresidentId = AlivePlayers[presidentIndex].UserId;
     }
     catch (Exception ex)
     {
         Console.WriteLine("MoveToNexTurn.ex:" + ex.Message);
     }
 }
Exemplo n.º 7
0
        public void MakeBeliveMove(BeliveMove move, Guid nextMoverId, Guid loserId, IReadOnlyCollection <PlayingCard> takedLoserCards)
        {
            var loser = Players.FirstOrDefault(p => p.Player.Id == loserId);

            loser.PlayingCards.AddRange(takedLoserCards);

            CurrentRound.AddMove(move);
            CurrentRound.End(loser.Player);

            NextRound();

            CurrentMover = Players.First(p => p.Player.Id == nextMoverId).Player;
        }
Exemplo n.º 8
0
        public RoundStatus AddPoints(Dart dart)
        {
            if (CurrentRound.RoundStatus == RoundStatus.Completed)
            {
                AddRound();
            }

            var roundStatus = CurrentRound.AddDart(dart);

            mCurrentPoints = mCurrentPoints - dart.Points;

            return(roundStatus);
        }
Exemplo n.º 9
0
            private bool IsLastTinyBlockOfCurrentSlot()
            {
                var producedBlocksOfCurrentRound = MinerInRound.ProducedTinyBlocks;
                var roundStartTime = CurrentRound.GetRoundStartTime();

                if (CurrentBlockTime < roundStartTime)
                {
                    return(producedBlocksOfCurrentRound == _maximumBlocksCount);
                }

                var blocksBeforeCurrentRound = MinerInRound.ActualMiningTimes.Count(t => t < roundStartTime);

                return(producedBlocksOfCurrentRound == blocksBeforeCurrentRound.Add(_maximumBlocksCount));
            }
Exemplo n.º 10
0
        /// <summary>
        /// Fill the grill with best fit meat.
        /// </summary>
        public virtual void FillCurrentRound()
        {
            Meat meat;

            do
            {
                var area = _maxRectangle.GetLargestRectangle(CurrentRound.Surface);
                meat = _strategy.GetNextMeat(_meats, area.Length, area.Width, out bool rotate);
                if (meat != null)
                {
                    CurrentRound.AddMeat(meat, rotate, area.LengthPosition, area.WidthPosition);
                }
            } while (meat != null);
        }
Exemplo n.º 11
0
 public void NominateChancellor(int chancId)
 {
     try
     {
         if (CurrentRound != null)
         {
             CurrentRound.NominateChancellor(chancId);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("CanNominateChancellor.ex: " + ex.Message);
     }
 }
Exemplo n.º 12
0
        public void GetResultIfNotEnoughCardsToContinue_NeitherPlayersHaveCards_ShouldReturnResultWithNoCardsAllPlayersMessage()
        {
            _mockPlayerService.Setup(mps => mps.IsPlayerOutOfCards(It.IsAny <Player>())).Returns(true);
            var currentRound = new CurrentRound(new List <Player>()
            {
                new Player("Tester1"), new Player("Tester2")
            });

            var result = _gameRoundService.GetResultIfNotEnoughCardsToContinue(currentRound);

            Assert.AreEqual(result.Message, "All players ran out of cards.");
            Assert.IsNull(result.FirstPlayerCard);
            Assert.IsNull(result.SecondPlayerCard);
            Assert.IsFalse(result.IsWarRequired);
        }
Exemplo n.º 13
0
        public void PlayerVoteCard(Player player, Card card)
        {
            if (GameState != State.Voting)
            {
                throw new InvalidOperationException($"Invalid game state {GameState.DisplayName} for PlayerVoteCard command");
            }


            if (!CurrentPlayedCards.Contains(card))
            {
                throw new InvalidOperationException($"Player {player.Name} cannot vote for a card that hasn't been played.");
            }

            CurrentRound.PlayerVoteCard(player, card);
        }
Exemplo n.º 14
0
 void roundplus()
 {
     CurrentRound++;
     Round_TXT.text       = CurrentRound + " / " + MaxRound;
     Round_Alert_TXT.text = "Round " + CurrentRound.ToString();
     if (CurrentRound == MaxRound)
     {
         //Final Round
         StartCoroutine(Final_Round_Alert());
     }
     else if (CurrentRound > MaxRound)
     {
         //End Of The Game
     }
 }
Exemplo n.º 15
0
 public void Next(Team winTeam)
 {
     if (groupId == 0)
     {
         units.Clear();
     }
     units.AddRange(winTeam.unitInfos);
     if (++groupId >= CurrentRound.Count)
     {
         if (++roundId < Count)
         {
             CurrentRound.RandomAssign(units);
             groupId = 0;
         }
     }
 }
Exemplo n.º 16
0
        public void GetCardDrawResult_TwoAces_ShouldGetTiedResult()
        {
            var player1Card  = new Card(Suit.Spades, Rank.Ace);
            var player2Card  = new Card(Suit.Hearts, Rank.Ace);
            var currentRound = new CurrentRound(new List <Player>()
            {
                new Player("1"), new Player("2")
            });

            currentRound.CardPot.Add(player1Card);
            currentRound.CardPot.Add(player2Card);

            var result = _gameRoundService.GetCardDrawResult(currentRound);

            Assert.AreEqual(ComparisonResult.Tie, result.ComparisonResult);
        }
Exemplo n.º 17
0
        public void GetCardDrawResult_TwoFaceCardsWithHigherFirstCard_ShouldGetFirstCardWinsResult()
        {
            var player1Card  = new Card(Suit.Clubs, Rank.King);
            var player2Card  = new Card(Suit.Clubs, Rank.Jack);
            var currentRound = new CurrentRound(new List <Player>()
            {
                new Player("1"), new Player("2")
            });

            currentRound.CardPot.Add(player1Card);
            currentRound.CardPot.Add(player2Card);

            var result = _gameRoundService.GetCardDrawResult(currentRound);

            Assert.AreEqual(ComparisonResult.FirstCardWins, result.ComparisonResult);
        }
Exemplo n.º 18
0
        public void GetCardDrawResult_SameFaceCardValue_ShouldGetTiedResult()
        {
            var player1Card  = new Card(Suit.Diamonds, Rank.Queen);
            var player2Card  = new Card(Suit.Hearts, Rank.Queen);
            var currentRound = new CurrentRound(new List <Player>()
            {
                new Player("1"), new Player("2")
            });

            currentRound.CardPot.Add(player1Card);
            currentRound.CardPot.Add(player2Card);

            var result = _gameRoundService.GetCardDrawResult(currentRound);

            Assert.AreEqual(ComparisonResult.Tie, result.ComparisonResult);
        }
Exemplo n.º 19
0
        public void GetCardDrawResult_TwoNumericCardsDifferentSuitsWithHigherSecondCard_ShouldGetSecondCardWinsResult()
        {
            var player1Card  = new Card(Suit.Clubs, Rank.Five);
            var player2Card  = new Card(Suit.Spades, Rank.Nine);
            var currentRound = new CurrentRound(new List <Player>()
            {
                new Player("1"), new Player("2")
            });

            currentRound.CardPot.Add(player1Card);
            currentRound.CardPot.Add(player2Card);

            var result = _gameRoundService.GetCardDrawResult(currentRound);

            Assert.AreEqual(ComparisonResult.SecondCardWins, result.ComparisonResult);
        }
Exemplo n.º 20
0
        public void GetCardDrawResult_FaceCardAndAceWithHigherSecondCard_ShouldGetSecondCardWinsResult()
        {
            var player1Card  = new Card(Suit.Clubs, Rank.Queen);
            var player2Card  = new Card(Suit.Clubs, Rank.Ace);
            var currentRound = new CurrentRound(new List <Player>()
            {
                new Player("1"), new Player("2")
            });

            currentRound.CardPot.Add(player1Card);
            currentRound.CardPot.Add(player2Card);

            var result = _gameRoundService.GetCardDrawResult(currentRound);

            Assert.AreEqual(ComparisonResult.SecondCardWins, result.ComparisonResult);
        }
Exemplo n.º 21
0
        public void PlayHand(object _lock)
        {
            PrepareHand();

            //PRE FLOP
            CurrentRound.IsPreflop = true;
            CurrentRound.PlayBettingRound(_lock);
            UpdatePlayersBets();
            pot = CurrentRound.CurrentPot;

            //FLOP
            deck.PullCard(Card.State.FaceDown); //burn card
            int i = 0;

            foreach (Card card in deck.PullCards(3))
            {
                communityCards[i] = card;
                i++;
            }

            //SECOND BETTING ROUND
            CurrentRound  = new Round(dealer, activePlayers, pot, false, preferences);
            activePlayers = CurrentRound.PlayBettingRound(_lock);
            UpdatePlayersBets();
            pot = CurrentRound.CurrentPot;

            //TURN
            deck.PullCard(Card.State.FaceDown); //burn card
            communityCards[i] = deck.PullCard(Card.State.FaceUp);
            i++;

            //THIRD BETTING ROUND
            CurrentRound  = new Round(dealer, activePlayers, pot, false, preferences);
            activePlayers = CurrentRound.PlayBettingRound(_lock);
            UpdatePlayersBets();
            pot = CurrentRound.CurrentPot;

            //RIVER
            deck.PullCard(Card.State.FaceDown); //burn card
            communityCards[i] = deck.PullCard(Card.State.FaceUp);

            //FORTH BETTING ROUND
            CurrentRound  = new Round(dealer, activePlayers, pot, false, preferences);
            activePlayers = CurrentRound.PlayBettingRound(_lock);
            UpdatePlayersBets();
            pot = CurrentRound.CurrentPot;
        }
Exemplo n.º 22
0
        public void NextRound(int chunks)
        {
            Locked = true;

            if (CurrentRound != null)
            {
                Rounds.Add(CurrentRound.Copy());
            }
            Rounds.ForEach(x => x.Locked = true);

            foreach (Player player in Players)
            {
                player.Chunk = string.Empty;
            }

            CurrentRound    = new Round();
            CurrentRound.ID = Rounds.Count() + 1;

            foreach (Player player in Players.Where(x => x.Alive && x.ID > 0))
            {
                CurrentRound.Players.Add(player);
            }

            List <List <Player> > chunksList = new List <List <Player> >();

            for (int i = 0; i < chunks; i++)
            {
                chunksList.Add(new List <Player>());
            }

            foreach (var player in CurrentRound.Players.Where(x => !string.IsNullOrEmpty(x.SeedChunk)))
            {
                if (int.TryParse(player.SeedChunk, out int chunk) && chunksList.Count() >= chunk)
                {
                    player.Chunk = chunk.ToString();
                    chunksList[chunk - 1].Add(player);
                }
            }

            foreach (var player in RandomPermutation(CurrentRound.Players.Where(x => string.IsNullOrEmpty(x.Chunk))))
            {
                List <Player> chunk = chunksList.FirstOrDefault(x => x.Count() == chunksList.Min(y => y.Count()));
                chunk.Add(player);
                player.Chunk = (chunksList.IndexOf(chunk) + 1).ToString();
            }
        }
Exemplo n.º 23
0
        public void GetCardDrawResult_TwoPlayerCards_ShouldPopulatePlayerCardsInResult()
        {
            var player1Card  = new Card(Suit.Clubs, Rank.Eight);
            var player2Card  = new Card(Suit.Diamonds, Rank.King);
            var currentRound = new CurrentRound(new List <Player>()
            {
                new Player("1"), new Player("2")
            });

            currentRound.CardPot.Add(player1Card);
            currentRound.CardPot.Add(player2Card);

            var result = _gameRoundService.GetCardDrawResult(currentRound);

            Assert.AreEqual(player1Card, result.FirstPlayerCard);
            Assert.AreEqual(player2Card, result.SecondPlayerCard);
        }
        /// <summary>
        /// Asynchronous export item's properties
        /// </summary>
        /// <returns>An <see cref="ExportableCI"/> instance containing all relevant properties</returns>
        public async Task <ExportableCurrentSeasonInfoCI> ExportAsync()
        {
            var groupsTask = Groups?.Select(async g => await g.ExportAsync().ConfigureAwait(false));

            return(new ExportableCurrentSeasonInfoCI
            {
                Id = Id.ToString(),
                Name = new Dictionary <CultureInfo, string>(Name),
                Year = Year,
                StartDate = StartDate,
                EndDate = EndDate,
                SeasonCoverage = SeasonCoverage != null ? await SeasonCoverage.ExportAsync().ConfigureAwait(false) : null,
                Groups = groupsTask != null ? await Task.WhenAll(groupsTask) : null,
                CurrentRound = CurrentRound != null ? await CurrentRound.ExportAsync().ConfigureAwait(false) : null,
                Competitors = CompetitorsIds?.Select(s => s.ToString()),
                Schedule = Schedule?.Select(s => s.ToString()).ToList()
            });
        }
Exemplo n.º 25
0
        public void PlayerPlayCard(Player player, Card card)
        {
            if (GameState != State.InProgress)
            {
                throw new InvalidOperationException($"Invalid game state {GameState.DisplayName} for PlayerPlayCard command");
            }
            var count = Deck.Hand(player).Count;

            if (Deck.Hand(player).Count < 6)
            {
                throw new InvalidOperationException($"Player {player.Name} has already played a card");
            }

            CurrentRound.PlayerPlayCard(player, card);
            if (HasAllPlayersPlayed())
            {
                GameState = State.Voting;
            }
        }
            public override ConsensusCommand GetAEDPoSConsensusCommand()
            {
                var arrangedMiningTime =
                    MiningTimeArrangingService.ArrangeNormalBlockMiningTime(CurrentRound, Pubkey, CurrentBlockTime);

                return(new ConsensusCommand
                {
                    Hint = new AElfConsensusHint
                    {
                        Behaviour = AElfConsensusBehaviour.UpdateValue,
                        RoundId = CurrentRound.RoundId,
                        PreviousRoundId = _previousRoundId
                    }.ToByteString(),
                    ArrangedMiningTime = arrangedMiningTime,
                    // Cancel mining after time slot of current miner because of the task queue.
                    MiningDueTime = CurrentRound.GetExpectedMiningTime(Pubkey).AddMilliseconds(MiningInterval),
                    LimitMillisecondsOfMiningBlock = DefaultBlockMiningLimit
                });
            }
Exemplo n.º 27
0
        public SingleCardPlayResult GetResultIfNotEnoughCardsToContinue(CurrentRound currentRound)
        {
            SingleCardPlayResult result = null;

            if (_playerService.IsPlayerOutOfCards(currentRound.Players[0]) && _playerService.IsPlayerOutOfCards(currentRound.Players[1]))
            {
                result = new SingleCardPlayResult(null, null, false, NO_CARDS_ALL_PLAYERS);
            }
            else if (_playerService.IsPlayerOutOfCards(currentRound.Players[0]))
            {
                result = new SingleCardPlayResult(null, null, false, string.Format(NO_CARDS_SINGLE_PLAYER, currentRound.Players[0].Name));
            }
            else if (_playerService.IsPlayerOutOfCards(currentRound.Players[1]))
            {
                result = new SingleCardPlayResult(null, null, false, string.Format(NO_CARDS_SINGLE_PLAYER, currentRound.Players[1].Name));
            }

            return(result);
        }
Exemplo n.º 28
0
        public void GetResultIfNotEnoughCardsToContinue_SecondPlayersHasNoCards_ShouldReturnResultWithSecondPlayerNameInMessage()
        {
            var player1 = new Player("Tester1");
            var player2 = new Player("Tester2");

            _mockPlayerService.Setup(mps => mps.IsPlayerOutOfCards(player1)).Returns(false);
            _mockPlayerService.Setup(mps => mps.IsPlayerOutOfCards(player2)).Returns(true);
            var currentRound = new CurrentRound(new List <Player>()
            {
                player1, player2
            });

            var result = _gameRoundService.GetResultIfNotEnoughCardsToContinue(currentRound);

            Assert.AreEqual(result.Message, "Tester2 ran out of cards.");
            Assert.IsNull(result.FirstPlayerCard);
            Assert.IsNull(result.SecondPlayerCard);
            Assert.IsFalse(result.IsWarRequired);
        }
        private bool CreateNextRound()
        {
            if (CurrentRound != null)
            {
                CurrentRound.CheckResults();
            }



            if (Teams.Count == 0 && Competition.ParticipantNumber == Competition.Participations.Count)
            {
                foreach (Participation part in Competition.Participations)
                {
                    AddPlayer(part.Bot);
                }
            }

            Manager.Reset();
            Manager.LoadState(Teams, Rounds);

            TournamentRound rd = Manager.CreateNextRound(null);

            // Finals
            if (rd == null || rd.Pairings[0].TeamScores.Count == 1)
            {
                CurrentRound = null;
                return(false);
            }
            else
            {
                Round round = null;
                CreateRound(rd, ref round);

                RoundInstance ri = new RoundInstance(Competition, rd, round, this);
                ExecutedRounds.Add(CurrentRound);
                CurrentRound = ri;
                Rounds.Add(CurrentRound.CurrentRound);
                return(true);
            }
        }
Exemplo n.º 30
0
 public bool CanPlayerVote(Vote vote)
 {
     try
     {
         if (playersDict.ContainsKey(vote.UserId))
         {
             var player = playersDict[vote.UserId];
             if (player.Status == Status.Dead)
             {
                 return(false);
             }
             else if (!CurrentRound.IsPlayerAlreadyVoted(vote.UserId))
             {
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("CanPlayerVote.ex :" + ex.Message);
     }
     return(false);
 }