Exemple #1
0
        public ImplementedGameState(int players, Dictionary <CamelColor, Position> startingPositions, int boardSize = 16, int startingMoney = 3) : this()
        {
            RemainingDice = CamelHelper.GetAllCamelColors();
            BettingCards  = ImplementedBettingCard.GetAllBettingCards();

            BoardSize = boardSize;
            Round     = 0;

            for (var i = 0; i < players; i++)
            {
                Money[i]        = startingMoney;
                Traps[i]        = new Trap();
                Disqualified[i] = false;
            }

            var h = 0;

            foreach (var item in startingPositions.OrderBy(x => x.Value.Location).ThenBy(x => x.Value.Height))
            {
                Camels.Add(new Camel()
                {
                    CamelColor = item.Key,
                    Location   = item.Value.Location,
                    Height     = h++,
                });
            }
        }
Exemple #2
0
        public static List <CamelColor> RemainingEndGameBets(this GameState gameState, int player)
        {
            var possible = CamelHelper.GetAllCamelColors();
            var winners  = gameState.WinnerBets.Where(x => x.Player == player).Select(x => x.CamelColor).ToList();
            var losers   = gameState.LoserBets.Where(x => x.Player == player).Select(x => x.CamelColor).ToList();

            return(possible.Where(x => !winners.Contains(x) && !losers.Contains(x)).ToList());
        }
Exemple #3
0
        private Dictionary <CamelColor, Position> GetRandomStartingPositions(int seed)
        {
            var rnd = new ConsistantRandom(seed);
            var i   = 0;

            return(CamelHelper.GetAllCamelColors().ToDictionary(x => x, x => new Position {
                Location = rnd.Next(0, 2), Height = i++
            }));
        }
Exemple #4
0
        private void ResetRound()
        {
            StartingPlayer          = (StartingPlayer + 1) % Players.Count;
            CurrentPlayer           = StartingPlayer;
            GameState.RemainingDice = CamelHelper.GetAllCamelColors();
            GameState.BettingCards  = ImplementedBettingCard.GetAllBettingCards();
            GameState.Round++;

            History.Add(new StateChange(StateAction.NewRound, -1, CamelColor.Blue, GameState.Round));

            foreach (var playerTrapPair in GameState.Traps)
            {
                playerTrapPair.Value.Location = -1;
            }
        }
        public static List <BettingCard> GetAllBettingCards()
        {
            var result = new List <BettingCard>();

            foreach (var color in CamelHelper.GetAllCamelColors())
            {
                foreach (var val in new[] { 5, 3, 2 })
                {
                    result.Add(new BettingCard()
                    {
                        CamelColor = color,
                        Value      = val,
                        Owner      = -1
                    });
                }
            }

            return(result);
        }
Exemple #6
0
        public StateChange Getchange(int playerId, PlayerAction action)
        {
            if (action.CamelAction == CamelAction.ThrowDice)
            {
                if (!Gamestate.RemainingDice.Any())
                {
                    return(null);
                }

                var index = Rnd.Next(0, Gamestate.RemainingDice.Count);
                var color = Gamestate.RemainingDice[index];
                var value = Rnd.Next(1, 4);

                return(new DiceThrowStateChange(playerId, color, value));
            }
            else if (action.CamelAction == CamelAction.PickCard)
            {
                if (Gamestate.BettingCards.Any(x => x.IsFree && x.CamelColor == action.Color))
                {
                    var card = Gamestate.BettingCards.Where(x => x.IsFree && x.CamelColor == action.Color).OrderByDescending(x => x.Value).First();
                    return(new PickCardStateChange(playerId, action.Color, card.Value));
                }

                return(null);
            }
            else if (action.CamelAction == CamelAction.PlaceMinusTrap)
            {
                if (CamelHelper.IsValidTrapSpace(Gamestate, playerId, action.Value, positive: false))
                {
                    return(new MinusTrapStateChange(playerId, action.Value));
                }

                return(null);
            }
            else if (action.CamelAction == CamelAction.PlacePlussTrap)
            {
                if (CamelHelper.IsValidTrapSpace(Gamestate, playerId, action.Value, positive: true))
                {
                    return(new PlussTrapStateChange(playerId, action.Value));
                }

                return(null);
            }
            else if (action.CamelAction == CamelAction.SecretBetOnLoser || action.CamelAction == CamelAction.SecretBetOnWinner)
            {
                if (Gamestate.WinnerBets.Any(x => x.Player == playerId && x.CamelColor == action.Color))
                {
                    return(null);
                }

                if (Gamestate.LoserBets.Any(x => x.Player == playerId && x.CamelColor == action.Color))
                {
                    return(null);
                }

                if (action.CamelAction == CamelAction.SecretBetOnLoser)
                {
                    return(new LoserBetStateChange(playerId, action.Color));
                }
                else
                {
                    return(new WinnerBetStateChange(playerId, action.Color));
                }
            }

            return(new NoActionStateChange(playerId));
        }