Пример #1
0
        private void SetNextStepPlayerId(int currStepPlayerId)
        {
            int?tmpNextStepPlayerId = Players.Where(player => player.Id != currStepPlayerId)
                                      .Select(player => player.Id).FirstOrDefault();

            if (BoardService.GetAvailableSteps(tmpNextStepPlayerId ?? -1).Count == 0)
            {
                tmpNextStepPlayerId = currStepPlayerId;

                if (BoardService.GetAvailableSteps(currStepPlayerId).Count == 0)
                {
                    tmpNextStepPlayerId = null;
                    SetWinner();
                }
            }

            NextStepPlayerId = tmpNextStepPlayerId;
        }
Пример #2
0
        /// <summary>
        /// Method for the player do step.
        /// </summary>
        /// <param name="playerId">Player that do step.</param>
        /// <param name="chipDoStepDTO">The chip that done step.</param>
        /// <returns>Changed chips list.</returns>
        public List <Chip> DoStep(int playerId, ChipDoStepDTO chipDoStepDTO)
        {
            if (!BoardService.CheckInitBoard())
            {
                throw new Exception("Board is not initialized.");
            }
            if (Players == null)
            {
                throw new Exception("Players is not initialized.");
            }

            if (!CheckNextStepPlayerId(playerId))
            {
                throw new Exception("This player is not in the step queue.");
            }

            IPlayer player = Players.Where(player => player.Id == playerId)
                             .FirstOrDefault();

            List <Chip> availableChips = BoardService.GetAvailableSteps(player.Id);
            List <Chip> flippedChips   = new List <Chip>();

            if (availableChips.Count == 0)
            {
                return(flippedChips);
            }

            Chip chipForStep = player.PlayerType == PlayerType.Human ?
                               new Chip(chipDoStepDTO, player.Id) :
                               availableChips[new Random().Next(0, availableChips.Count)];

            if (player.PlayerType == PlayerType.Human &&
                !availableChips.Contains(chipForStep))
            {
                throw new Exception("This step is unavailable!");
            }

            flippedChips = BoardService.FlipChips(chipForStep, player.Id);
            SetNextStepPlayerId(playerId);

            return(flippedChips);
        }
Пример #3
0
 /// <summary>
 /// Method that calculates mobility for given board and player
 /// </summary>
 /// <param name="boardService"></param>
 /// <param name="id">Player ID</param>
 /// <returns>Integer score (more is better)</returns>
 static int Mobility(BoardService boardService, int id)
 {
     return(boardService.GetAvailableSteps(id).Distinct().Count());
 }