Beispiel #1
0
        /// <summary>
        /// Static evaluation function that returns score for given move
        /// </summary>
        /// <param name="board">Current board state</param>
        /// <param name="chip">Chip with coordinates that indicate move position</param>
        /// <returns>Integer score (more is better)</returns>
        public static int Evaluate(Board board, Chip chip)
        {
            int cPos  = 1;
            int cMob  = 1;
            int cPmob = 1;
            int cStab = 1;

            int id = chip.OwnerId;

            BoardService boardService = new BoardService();

            boardService.InitBoard(new Board(board));

            return(cPos * Position(chip) + cMob * Mobility(boardService, id) + cPmob *
                   PotentialMobility(boardService, id) + cStab * Stability(boardService, id));
        }
Beispiel #2
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;
        }
Beispiel #3
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);
        }
Beispiel #4
0
 public PlayerService(BoardService boardService)
 {
     this.BoardService = boardService;
 }
Beispiel #5
0
 /// <summary>
 /// Method that calculates potential 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 Stability(BoardService boardService, int id)
 {
     return(-(boardService.GetStableChips(id).Count()));
 }
Beispiel #6
0
 /// <summary>
 /// Method that calculates potential 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 PotentialMobility(BoardService boardService, int id)
 {
     return(-(boardService.GetFrontierChips(id).Count()));
 }
Beispiel #7
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());
 }