Esempio n. 1
0
        public int ScoreFromBoard(ListPlayer player, List <ListHex> playerPath, List <ListHex> opponentPath)
        {
            var opponent = player.Me == PlayerType.Blue ? PlayerType.Red : PlayerType.Blue;
            // player score
            var playerScore = PlayerScore(playerPath);
            // opponent score
            var opponentScore = PlayerScore(opponentPath);

            return(playerScore - opponentScore);
        }
Esempio n. 2
0
        public int ScoreFromBoard(ListMap map, ListPlayer player)
        {
            var opponent = player.Me == PlayerType.Blue ? PlayerType.Red : PlayerType.Blue;
            // player score
            var playerScore = PlayerScore(map, player.Me);
            // opponent score
            var opponentScore = PlayerScore(map, opponent);

            return(playerScore - opponentScore);
        }
Esempio n. 3
0
        public void StartInquisition(ListMap searchMap, ListPlayer searchPlayer)
        {
            var mapToSearch = searchMap.GetCopyOf();
            var searchScout = new Pathfinder(mapToSearch,
                                             searchPlayer.Me,
                                             searchPlayer.CostToMoveToClaimedNode,
                                             searchPlayer.CostToMoveToUnclaimedNode,
                                             searchPlayer.CostPerNodeTillEnd);

            _finalChoice = null;
            _finalScore  = -9999;

            ThinkAboutTheNextMove(
                searchPlayer,
                mapToSearch,
                searchScout.GetPathForPlayer(),
                null,
                searchPlayer.CurrentLevels,
                -9999,
                9999,
                true);
        }
Esempio n. 4
0
        private int ThinkAboutTheNextMove(
            ListPlayer player,
            ListMap map,
            List <ListHex> path,
            ListHex currentMove,
            int depth,
            int alpha,
            int beta,
            bool isMaximizing)
        {
            var judge = new Appraiser();

            var scout = new Pathfinder(map, isMaximizing ? player.Me : player.Opponent());

            var myPath = scout.GetPathForPlayer();

            if (depth == 0 || map.Board.All(x => x.Owner != PlayerType.White))
            {
                return(judge.ScoreFromBoard(player, myPath, path));
            }


            var possibleMoves = GetPossibleMoves(path, myPath, isMaximizing ? player.Me : player.Opponent(), map);

            if (isMaximizing)
            {
                foreach (var move in possibleMoves)
                {
                    var bestScore = -9999;
                    var newMap    = map.GetCopyOf();
                    newMap.TakeHex(player.Me, move.Row, move.Column);

                    bestScore = Math.Max(bestScore,
                                         ThinkAboutTheNextMove(
                                             player,
                                             newMap,
                                             myPath,
                                             move,
                                             depth - 1,
                                             alpha,
                                             beta,
                                             false));

                    if (bestScore > alpha)
                    {
                        _finalChoice = move.ToTuple();
                        alpha        = bestScore;
                    }
                    if (beta <= alpha)
                    {
                        break;
                    }
                }

                return(alpha);
            }
            else
            {
                foreach (var move in possibleMoves)
                {
                    var worstScore = 9999;
                    var newMap     = map.GetCopyOf();
                    newMap.TakeHex(player.Opponent(), move.Row, move.Column);


                    worstScore = Math.Min(worstScore, ThinkAboutTheNextMove(
                                              player,
                                              newMap,
                                              myPath,
                                              move,
                                              depth - 1,
                                              alpha,
                                              beta,
                                              true));
                    beta = Math.Min(worstScore, beta);
                    if (beta <= alpha)
                    {
                        break;
                    }
                }

                return(beta);
            }
        }