Ejemplo n.º 1
0
        private int PlayerScore(ListMap map, PlayerType player)
        {
            var scout           = new Pathfinder(map, player);
            var path            = scout.GetPathForPlayer();
            var isFullyAttached = path.Where(x => x.Owner == player).Any(x => x.IsAttachedToBothEnds());

            if (isFullyAttached)
            {
                Console.WriteLine((string)("Winning move found! " + player));
                return(player == PlayerType.Blue ? 5000 : -5000);
            }

            return(PlayerScore(path));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
            }
        }