Esempio n. 1
0
        public void SetBias(PlayTurnRequest request)
        {
            int startX = request.PartyLocation.X;
            int startY = request.PartyLocation.Y;

            BiasSet = true;

            if (startX < 5)
            {
                goingEastBias = 1.25;
            }
            else
            {
                goingWestBias = 1.25;
            }

            if (startY < 5)
            {
                goingSouthBias = 1.25;
            }
            else
            {
                goingNorthBias = 1.25;
            }
        }
        public Task <Turn> ShowPath(Location featureLocation, PlayTurnRequest request)
        {
            Location partylocation = request.PartyLocation;

            if (featureLocation != null)
            {
                if (featureLocation.X > partylocation.X)
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkEast)));
                }
                if (featureLocation.X < partylocation.X)
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkWest)));
                }
                if (featureLocation.Y > partylocation.Y)
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkSouth)));
                }

                if (featureLocation.Y < partylocation.Y)
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkNorth)));
                }
            }

            return(Task.FromResult(request.PossibleActions.Contains(TurnAction.WalkSouth)
                ? new Turn(TurnAction.WalkSouth) : new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)])));
        }
Esempio n. 3
0
        public bool CanWalkNorth(PlayTurnRequest request)
        {
            if (actionList[actionList.Count - 1] == TurnAction.WalkSouth)
            {
                return(false);
            }

            return(request.PossibleActions.Contains(TurnAction.WalkNorth));
        }
Esempio n. 4
0
        public bool CanBattle(PlayTurnRequest request)
        {
            if (CanAttack(request) && CanDrinkPotion(request))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        public bool CanDrinkPotion(PlayTurnRequest request)
        {
            if (actionList[actionList.Count - 1] == TurnAction.DrinkPotion || potionAmount <= 0)
            {
                return(false);
            }

            return(request.PossibleActions.Contains(TurnAction.DrinkPotion));
        }
Esempio n. 6
0
        public Task <Turn> Battle(PlayTurnRequest request)
        {
            if (request.IsCombat && request.PartyMember.CurrentHealthPoints <= 20 && 0 < request.PartyMember.CurrentHealthPoints)
            {
                //return DrinkPotion();
                return(Attack());
            }

            return(Attack());
        }
        public Task <Turn> PlayTurn(PlayTurnRequest request)
        {
            var avoidCombat = false;

            return(Strategic());

            Task <Turn> Strategic()
            {
                return(request.IsCombat ? StrategicCombat() : StrategicNonCombat());
            }

            Task <Turn> StrategicCombat()
            {
                if (!request.IsCombat)
                {
                    return(Task.FromResult(new Turn(TurnAction.Attack)));
                }

                if (HealthChecker.NeedsToChug(request.PartyMember) && request.PossibleActions.Contains(TurnAction.DrinkPotion))
                {
                    return(Task.FromResult(new Turn(TurnAction.DrinkPotion)));
                }

                return(Task.FromResult(new Turn(TurnAction.Attack, Targeter.GetPriorityTarget(request.PossibleTargets))));
            }

            Task <Turn> StrategicNonCombat()
            {
                if (request.PossibleActions.Contains(TurnAction.Attack) && _random.NextDouble() > 0.5)
                {
                    return(StrategicCombat());
                }

                var movements = MovementTracker.GetMovementActions();

                if (request.PossibleActions.Contains(TurnAction.Loot))
                {
                    return(Task.FromResult(new Turn(TurnAction.Loot)));
                }

                if (request.PossibleActions.Contains(TurnAction.Open))
                {
                    return(Task.FromResult(new Turn(TurnAction.Open)));
                }

                var movementoptions =
                    request.PossibleActions.Where(s => movements.Contains(s));

                var direction = movetracker.GetNextDirection(movementoptions.ToList(), request.PartyLocation);

                Debug.WriteLine(direction);

                return(Task.FromResult(new Turn(direction)));
            }
        }
Esempio n. 8
0
        public async Task <PlayTurnResponse> PlayTurnAsync(PlayTurnRequest request)
        {
            var response = ServiceMessageFactory <PlayTurnResponse> .CreateFrom(request);

            var playerRequest = ServiceMessageFactory <GetPlayerRequest> .CreateFrom(request);

            playerRequest.PlayerId = request.PlayerId;
            var playerResponse = await playerAccess.GetPlayerAsync(playerRequest);

            var player = playerResponse.Player.Convert();

            var gameSessionRequest = ServiceMessageFactory <GetGameSessionRequest> .CreateFrom(request);

            gameSessionRequest.GameSessionId = request.GameSessionId;
            var gameSessionResponse = await gameSessionAccess.GetGameSessionAsync(gameSessionRequest);

            var gameSession = gameSessionResponse.GameSession.Convert();

            var tilesRequest = ServiceMessageFactory <FindTilesRequest> .CreateFrom(request);

            tilesRequest.Filter = tile => tile.GameSessionId == request.GameSessionId;
            var tilesResponse = await tileAccess.FindTilesAsync(tilesRequest);

            var tiles = tilesResponse.Tiles;

            Access.Tile.Interface.Tile tile;

            if (player.IsMachine)
            {
                tile          = autoPlayer.PlayTurn(tiles);
                tile.PlayerId = player.Id;
            }
            else
            {
                var address = request.Address.ToUpperInvariant();
                tile          = tiles.First(i => i.Address == address);
                tile.PlayerId = player.Id;
            }

            var updateTileRequest = ServiceMessageFactory <UpdateTileRequest> .CreateFrom(request);

            updateTileRequest.Tile = tile;
            var updateTileResponse = await tileAccess.UpdateTileAsync(updateTileRequest);

            if (updateTileResponse.HasErrors)
            {
                response.Errors += "Tile update error.";
            }
            IncrementPlayer(gameSession);

            return(response);
        }
Esempio n. 9
0
        public Task <Turn> DecideTurn(PlayTurnRequest request)
        {
            if (!BiasSet)
            {
                SetBias(request);
            }

            if (CanLoot(request))
            {
                return(Loot());
            }

            if (CanBattle(request))
            {
                return(Battle(request));
            }

            return(Move(request));
        }
Esempio n. 10
0
        public Task <Turn> PlayTurn(PlayTurnRequest request)
        {
            return(PlayToEnd());

            Task <Turn> PlayToEnd()
            {
                walkManager = new WalkManager(request, currentDirection);
                Turn testTurn = walkManager.Walk();

                currentDirection = walkManager.CurrentDirection;

                return(Task.FromResult(testTurn));
            }

            Task <Turn> Strategic()
            {
                const double goingEastBias  = 0.35;
                const double goingSouthBias = 0.25;

                if (request.PossibleActions.Contains(TurnAction.Loot))
                {
                    return(Task.FromResult(new Turn(TurnAction.Loot)));
                }

                if (request.PossibleActions.Contains(TurnAction.Attack))
                {
                    return(Task.FromResult(new Turn(TurnAction.Attack)));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkEast) && _random.NextDouble() > (1 - goingEastBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkEast)));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkSouth) && _random.NextDouble() > (1 - goingSouthBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkSouth)));
                }

                return(Task.FromResult(new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)])));
            }
        }
        public Task <Turn> PlayTurn(PlayTurnRequest request)
        {
            return(PlayToEnd());

            Task <Turn> PlayToEnd()
            {
                Dictionary <Location, TileType> TheMap = WriteMap(request.Map);

                return(GetSpecialFeatures(TheMap, request));
            }

            Task <Turn> Strategic()
            {
                const double goingEastBias  = 0.35;
                const double goingSouthBias = 0.25;

                if (request.PossibleActions.Contains(TurnAction.Loot))
                {
                    return(Task.FromResult(new Turn(TurnAction.Loot)));
                }

                if (request.PossibleActions.Contains(TurnAction.Attack))
                {
                    return(Task.FromResult(new Turn(TurnAction.Attack)));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkEast) && _random.NextDouble() > (1 - goingEastBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkEast)));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkSouth) && _random.NextDouble() > (1 - goingSouthBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkSouth)));
                }

                return(Task.FromResult(new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)])));
            }
        }
        public Task <Turn> PlayTurn(PlayTurnRequest request)
        {
            if (turnActions == null)
            {
                turnActions = getTurnActionsFromPathLocations(getPathLocationsFromMap(request.Map));
            }
            return(PlayToEnd());

            Task <Turn> PlayToEnd()
            {
                return(Strategic());
            }

            Task <Turn> Strategic()
            {
                TurnAction turnAction;

                if (request.PossibleActions.Contains(TurnAction.Attack))
                {
                    turnAction = TurnAction.Attack;
                }
                else if (request.PossibleActions.Contains(TurnAction.Open))
                {
                    turnAction = TurnAction.Open;
                }
                else if (request.PossibleActions.Contains(TurnAction.Loot))
                {
                    turnAction = TurnAction.Loot;
                }
                else
                {
                    currentStepInTurnActions++;
                    turnAction = turnActions[currentStepInTurnActions - 1];
                }
                return(Task.FromResult(new Turn(turnAction)));
            }
        }
Esempio n. 13
0
        public Task <Turn> PlayTurn(PlayTurnRequest request)
        {
            return(PlayToEnd());

            Task <Turn> PlayToEnd()
            {
                return(Task.FromResult(request.PossibleActions.Contains(TurnAction.WalkSouth) ? new Turn(TurnAction.WalkSouth) : new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)])));
            }

            Task <Turn> Strategic()
            {
                const double goingEastBias  = 0.35;
                const double goingSouthBias = 0.25;

                if (request.PossibleActions.Contains(TurnAction.Loot))
                {
                    return(Task.FromResult(new Turn(TurnAction.Loot)));
                }

                if (request.PossibleActions.Contains(TurnAction.Attack))
                {
                    return(Task.FromResult(new Turn(TurnAction.Attack)));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkEast) && _random.NextDouble() > (1 - goingEastBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkEast)));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkSouth) && _random.NextDouble() > (1 - goingSouthBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkSouth)));
                }

                return(Task.FromResult(new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)])));
            }
        }
Esempio n. 14
0
        public Task <Turn> Move(PlayTurnRequest request)
        {
            if (CanWalkEast(request) && _random.NextDouble() > (1 - goingEastBias))
            {
                return(WalkEast());
            }

            if (CanWalkSouth(request) && _random.NextDouble() > (1 - goingSouthBias))
            {
                return(WalkSouth());
            }

            if (CanWalkWest(request) && _random.NextDouble() > (1 - goingWestBias))
            {
                return(WalkWest());
            }

            if (CanWalkNorth(request) && _random.NextDouble() > (1 - goingNorthBias))
            {
                return(WalkNorth());
            }

            return(Move(request));
        }
 public Task <Turn> PlayTurn(PlayTurnRequest request)
 {
     return(dungeonAlgorithm.DecideTurn(request));
 }
        public Task <Turn> PlayTurn(PlayTurnRequest request)
        {
            return(riskBasedStrategic());

            Task <Turn> riskBasedStrategic()
            {
                var xLocation       = request.PartyLocation.X; //X locatie partymember
                var yLocation       = request.PartyLocation.Y; //Y locatie partymember
                var member          = request.PartyMember;
                var map             = request.Map;             // De tilemap
                var possibleActions = request.PossibleActions; //Al de mogelijke acties dat het character kan doen
                var isInCombat      = request.IsCombat;
                var possibleEnemies = request.PossibleTargets;

                if (possibleActions.Contains(TurnAction.DrinkPotion))
                {
                    hasPotions = true;
                }
                if (possibleActions.Contains(TurnAction.DrinkPotion) && isLowHP())
                {
                    return(Task.FromResult(new Turn(TurnAction.DrinkPotion)));
                }
                if (possibleActions.Contains(TurnAction.Loot))
                {
                    BlacklistPoints.Add(new Point(xLocation, yLocation));
                    return(Task.FromResult(new Turn(TurnAction.Loot)));
                }

                if (!calculated)
                {
                    var width  = map.Tiles.GetLength(0);
                    var height = map.Tiles.GetLength(1);
                    tilesmap = new float[width, height];

                    for (var i = 0; i < width; ++i)
                    {
                        for (var j = 0; j < height; ++j)
                        {
                            var tile = map.Tiles[i, j];
                            #region WeightCalculation
                            var weight = 0.00F;
                            if (tile.TileType == TileType.Wall || tile.TerrainType == TerrainType.Water)
                            {
                                weight = 0.0f;
                            }
                            else
                            {
                                weight = 0.1f;
                            }
                            tilesmap[i, j] = weight;
                            #endregion

                            switch (tile.TileType)
                            {
                            case TileType.TreasureChest:
                                TreasurePoints.Add(new TreasurePoint(new Point(i, j), tile.TreasureChest));
                                break;

                            case TileType.Finish:
                                FinishPoint = new Point(i, j);
                                break;

                            case TileType.Enemy:
                                enemies.Add(new EnemyPoint(new Point(i, j), tile.EnemyGroup));
                                break;
                            }
                        }
                    }

                    calculated = true;
                }


                if (currentPath == null)
                {
                    var grid = new Grid(tilesmap);
                    if (TreasurePoints.Any(x => !x.TreasureChest.IsEmpty))
                    {
                        List <Point> closestPoint = null;
                        foreach (var treasure in TreasurePoints.Where(x => !x.TreasureChest.IsEmpty))
                        {
                            if (closestPoint == null)
                            {
                                closestPoint = Pathfinding.FindPath(grid, new Point(xLocation, yLocation), treasure.Point, Pathfinding.DistanceType.Manhattan);
                                continue;
                            }
                            else
                            {
                                var newPoint = Pathfinding.FindPath(grid, new Point(xLocation, yLocation), treasure.Point,
                                                                    Pathfinding.DistanceType.Manhattan);
                                if (closestPoint.Count > newPoint.Count)
                                {
                                    closestPoint = newPoint;
                                }
                            }
                        }
                        currentPath = closestPoint;
                    }

                    //else if (!request.IsCombat&&canHandleCombat()&&!request.PossibleActions.Contains(TurnAction.Attack))
                    //{
                    //    currentPath = Pathfinding.FindPath(grid, new Point(xLocation, yLocation), enemies[0].Point, Pathfinding.DistanceType.Manhattan);
                    //}
                    //else if (request.PossibleActions.Contains(TurnAction.Attack) && canHandleCombat())
                    //{

                    //    return Task.FromResult(new Turn(TurnAction.Attack));

                    //}
                    else
                    {
                        currentPath = Pathfinding.FindPath(grid, new Point(xLocation, yLocation), FinishPoint, Pathfinding.DistanceType.Manhattan);
                    }
                }

                if (currentPath != null && currentPath.Count > 0)
                {
                    var currentStep = currentPath[0];
                    currentPath.RemoveAt(0);
                    return(Task.FromResult(new Turn(GetTurnAction(xLocation, yLocation, currentStep))));
                }
                else
                {
                    currentPath = null;
                }


                return(Task.FromResult(new Turn(TurnAction.Pass)));
            }
        }
Esempio n. 17
0
 public WalkManager(PlayTurnRequest request, TurnAction currentDirection)
 {
     CurrentDirection = currentDirection;
     Request          = request;
 }
Esempio n. 18
0
 public bool CanAttack(PlayTurnRequest request)
 {
     return(request.PossibleActions.Contains(TurnAction.Attack));
 }
        public Task<Turn> PlayTurn(PlayTurnRequest request)
        {
            return PlayToEnd();

            Task<Turn> PlayToEnd()
            {
                return Task.FromResult(request.PossibleActions.Contains(TurnAction.WalkEast)
                    ? new Turn(TurnAction.WalkEast)
                    : new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)]));
            }

            Task<Turn> Strategic()
            {
                const double goingEastBias = 0.35;
                const double goingSouthBias = 0.25;

                if (request.PossibleActions.Contains(TurnAction.Loot))
                {
                    return Task.FromResult(new Turn(TurnAction.Loot));
                }

                if (request.PossibleActions.Contains(TurnAction.Attack))
                {
                    return Task.FromResult(new Turn(TurnAction.Attack));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkEast) && _random.NextDouble() > (1 - goingEastBias))
                {
                    return Task.FromResult(new Turn(TurnAction.WalkEast));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkSouth) &&
                    _random.NextDouble() > (1 - goingSouthBias))
                {
                    return Task.FromResult(new Turn(TurnAction.WalkSouth));
                }

                return Task.FromResult(new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)]));
            }

            void Main(string[] args)
            {
                var map = request.Map;
                var start = new Tile();
                var finish = new Tile();

                for (var j = 0; j >= map.Tiles.Rank; j++)
                {
                    for (var i = 0; i >= map.Tiles.Col; i++)
                    {
                        if (map.Tiles[j, i].GetType() = StartPoint)
                        {
                            start = map.Tiles[j, i];
                        }

                        if (map.Tiles[j, i].GetType() = FinishPoint)
                        {
                            finish = map.Tiles[j, i];
                        }
                    }
                }

                var activeTiles = new List<Tile>();
                activeTiles.Add(start);
                var visitedTiles = new List<Tile>();
Esempio n. 20
0
        public Task <Turn> PlayTurn(PlayTurnRequest request)
        {
            return(PlayToEnd());

            Task <Turn> PlayToEnd()
            {
                return(Strategic());
                //return Task.FromResult(request.PossibleActions.Contains(TurnAction.WalkSouth) ? new Turn(TurnAction.WalkSouth) : new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)]));
            }

            Task <Turn> Strategic()
            {
                double goingEastBias  = 0.25;
                double goingSouthBias = 0.25;
                double goingNorthBias = 0.15;
                double goingWestBias  = 0.15;
                //Console.WriteLine("Locatie: " + request.PartyLocation.X + " , " + request.PartyLocation.Y);
                int          locatieX     = request.PartyLocation.X;
                int          locatieY     = request.PartyLocation.Y;
                List <int[]> finish       = GetTileTypeLoc(request.Map, TileType.Finish);
                int          finishX      = finish[0][0];
                int          finishY      = finish[0][1];
                List <int[]> lijst        = GetTileTypeLoc(request.Map, TileType.TreasureChest);
                int          aantalChests = lijst.Count();

                if (aantalChests != 0)
                {
                    int[] StartLoc  = { request.PartyLocation.X, request.PartyLocation.Y };
                    int[] FinishLoc = { finishX, finishY };
                    AStar aStar     = new AStar(request.Map, StartLoc, FinishLoc);
                }
                //Console.WriteLine("Const: " + request.PartyMember.GetType);
                if (request.PossibleActions.Contains(TurnAction.Loot))
                {
                    return(Task.FromResult(new Turn(TurnAction.Loot)));
                }

                if (request.PossibleActions.Contains(TurnAction.Attack))
                {
                    if (request.IsCombat)
                    {
                        if (request.PartyMember.CurrentHealthPoints < 70)
                        {
                            Console.WriteLine("HP: " + request.PartyMember.CurrentHealthPoints);
                            String test = Console.ReadLine();
                            if (request.PossibleActions.Contains(TurnAction.DrinkPotion))
                            {
                                return(Task.FromResult(new Turn(TurnAction.DrinkPotion)));
                            }
                        }
                    }

                    return(Task.FromResult(new Turn(TurnAction.Attack)));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkEast) && _random.NextDouble() > (1 - goingEastBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkEast)));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkSouth) && _random.NextDouble() > (1 - goingSouthBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkSouth)));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkNorth) && _random.NextDouble() > (1 - goingNorthBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkNorth)));
                }
                if (request.PossibleActions.Contains(TurnAction.WalkWest) && _random.NextDouble() > (1 - goingWestBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkWest)));
                }


                return(Task.FromResult(new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)])));
            }
        }
        public Task <Turn> PlayTurn(PlayTurnRequest request)
        {
            List <Position> itemPositions = new List <Position>();

            for (int i = 0; i < request.Map.Tiles.GetLength(0); i++)
            {
                for (int j = 0; j < request.Map.Tiles.GetLength(1); j++)
                {
                    if (request.Map.Tiles[i, j].TileType == TileType.TreasureChest)
                    {
                        Treasure treasurePosition = new Treasure();
                        treasurePosition.x = i;
                        treasurePosition.y = j;
                        itemPositions.Add(treasurePosition);
                    }
                    if (request.Map.Tiles[i, j].TileType == TileType.Enemy)
                    {
                        Enemy enemyPosition = new Enemy();
                        enemyPosition.x = i;
                        enemyPosition.y = j;
                        itemPositions.Add(enemyPosition);
                    }
                    //if (request.Map.Tiles[i, j].TileType == TileType.Finish)
                    //{
                    //    Finish finishPosition = new Finish();
                    //    finishPosition.x = i;
                    //    finishPosition.y = j;
                    //    itemPositions.Add(finishPosition);
                    //}
                }
            }
            Console.WriteLine("Itempositionslist: " + itemPositions.Count);
            Console.WriteLine("");

            int    locationPos = 0;
            double minDistance = 1000;

            discoveredLocations.Add(new DiscoveredLocation()
            {
                x = request.PartyLocation.X, y = request.PartyLocation.Y
            });

            for (int i = 0; i < itemPositions.Count; i++)
            {
                for (int j = 0; j < discoveredLocations.Count; j++)
                {
                    if (itemPositions[i].x != discoveredLocations[j].x && itemPositions[i].y != discoveredLocations[j].y)
                    {
                        if (checkDistance(request.PartyLocation.X, request.PartyLocation.Y, itemPositions[i].x, itemPositions[i].y) < minDistance)
                        {
                            minDistance = checkDistance(request.PartyLocation.X, request.PartyLocation.Y, itemPositions[i].x, itemPositions[i].y);
                            locationPos = i;
                        }
                    }
                }
            }

            if (tracker == null)
            {
                tracker = itemPositions[locationPos];
            }

            Console.WriteLine("Next Item Position " + tracker.x + " : " + tracker.y);
            Console.WriteLine("Mindistance: " + minDistance);
            Console.WriteLine("Playerposition: " + request.PartyLocation.X + " : " + request.PartyLocation.Y);


            return(Test());

            Task <Turn> Test()
            {
                if (request.IsCombat)
                {
                    if (request.PartyMember.CurrentHealthPoints < 5 && request.PossibleActions.Contains(TurnAction.DrinkPotion))
                    {
                        return(Task.FromResult(new Turn(TurnAction.DrinkPotion)));
                    }
                }

                if (request.PossibleActions.Contains(TurnAction.Attack))
                {
                    discoveredLocations.Add(tracker);
                    tracker = null;
                    return(Task.FromResult(new Turn(TurnAction.Attack)));
                }

                if (request.PossibleActions.Contains(TurnAction.Loot))
                {
                    discoveredLocations.Add(tracker);
                    tracker = null;
                    return(Task.FromResult(new Turn(TurnAction.Loot)));
                }


                Navigate nextItem = new Navigate(request, tracker.x, tracker.y);

                Console.WriteLine("Discovered locationslist:" + discoveredLocations.Count);
                return(nextItem.ShortestRoute());
                //return Task.FromResult(new Turn(TurnAction.WalkEast));
            }
        }
Esempio n. 22
0
        public Task <Turn> PlayTurn(PlayTurnRequest request)
        {
            var pathfinder     = new PathFinder(request.Map);
            var start_location = PathFinder.GetAllTileTypes(request.Map, TileType.Start)[0];
            // find loot
            List <Location> fullPath       = new List <Location>();
            var             Treasures      = pathfinder.GetAllPaths(start_location, TileType.TreasureChest);
            var             Enemies        = PathFinder.GetAllTileTypes(request.Map, TileType.Enemy);
            var             TreasureChests = PathFinder.GetAllTileTypes(request.Map, TileType.TreasureChest);
            var             EnemiesOnPath  = CalculateEnemies();

            foreach (var location in TreasureChests)
            {
                fullPath.AddRange(pathfinder.A_star(start_location, location));
                start_location = location;
            }
            fullPath.AddRange(pathfinder.A_star(start_location, PathFinder.GetAllTileTypes(request.Map, TileType.Finish)[0]));


            /*for (int i = 0;  i < Treasures.Count; i++)
             * {
             *  if (EnemiesOnPath[i] < 2)
             *  {
             *      fullPath.AddRange(Treasures[i]);
             *  }
             * }*/

            // calculate finish
            var path = fullPath;

            //var path = pathfinder.A_star(start_location, PathFinder.GetAllTileTypes(request.Map,TileType.Finish)[0]);

            return(SmartPath());

            Task <Turn> PlayToEnd()
            {
                return(Task.FromResult(request.PossibleActions.Contains(TurnAction.WalkSouth) ? new Turn(TurnAction.WalkSouth) : new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)])));
            }

            Task <Turn> SmartPath()
            {
                var start = path[index];

                if (index + 1 < path.Count)
                {
                    var location = path[++index];
                    int deltaX   = start.X - location.X;
                    int deltaY   = start.Y - location.Y;
                    if (request.Map.Tiles[start.X, start.Y].TileType == TileType.Enemy)
                    {
                        if (request.PossibleActions.Contains(TurnAction.Attack))
                        {
                            index--;
                            return(Task.FromResult(new Turn(TurnAction.Attack)));
                        }
                        else if (request.PossibleActions.Contains(TurnAction.Loot))
                        {
                            index--;
                            return(Task.FromResult(new Turn(TurnAction.Loot)));
                        }
                        else
                        {
                            return(WalkAction(deltaX, deltaY));
                        }
                    }
                    else if (request.Map.Tiles[start.X, start.Y].TileType == TileType.TreasureChest)
                    {
                        if (request.PossibleActions.Contains(TurnAction.Loot))
                        {
                            index--;
                            return(Task.FromResult(new Turn(TurnAction.Loot)));
                        }
                    }
                    return(WalkAction(deltaX, deltaY));
                }
                return(Task.FromResult(new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)])));
            }

            Task <Turn> WalkAction(int deltaX, int deltaY)
            {
                if (deltaX == -1 && deltaY == 0)
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkEast)));
                }
                else if (deltaX == 1 && deltaY == 0)
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkWest)));
                }
                else if (deltaX == 0 && deltaY == -1)
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkSouth)));
                }
                else if (deltaX == 0 && deltaY == 1)
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkNorth)));
                }
                else
                {
                    return(Task.FromResult(new Turn(TurnAction.Pass)));
                }
            }

            List <int> CalculateEnemies()
            {
                List <int> matrix = new List <int>();

                foreach (var treasure_path in Treasures)
                {
                    int EnemyCount = 0;
                    foreach (var EnemyLocation in Enemies)
                    {
                        if (treasure_path.Contains(EnemyLocation))
                        {
                            EnemyCount++;
                        }
                    }
                    matrix.Add(EnemyCount);
                }
                return(matrix);
            }

            Task <Turn> Strategic()
            {
                const double goingEastBias  = 0.35;
                const double goingSouthBias = 0.25;

                if (request.PossibleActions.Contains(TurnAction.Loot))
                {
                    return(Task.FromResult(new Turn(TurnAction.Loot)));
                }

                if (request.PossibleActions.Contains(TurnAction.Attack))
                {
                    return(Task.FromResult(new Turn(TurnAction.Attack)));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkEast) && _random.NextDouble() > (1 - goingEastBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkEast)));
                }

                if (request.PossibleActions.Contains(TurnAction.WalkSouth) && _random.NextDouble() > (1 - goingSouthBias))
                {
                    return(Task.FromResult(new Turn(TurnAction.WalkSouth)));
                }

                return(Task.FromResult(new Turn(request.PossibleActions[_random.Next(request.PossibleActions.Length)])));
            }
        }
        public Task <Turn> GetSpecialFeatures(Dictionary <Location, TileType> TheMap, PlayTurnRequest request)
        {
            Location location = null;

            foreach (KeyValuePair <Location, TileType> entry in TheMap)
            {
                if (entry.Value.Equals(TileType.TreasureChest))
                {
                    if (!request.Map.Tiles[entry.Key.X, entry.Key.Y].TreasureChest.IsEmpty)
                    {
                        location = entry.Key;
                        if (request.PossibleActions.Contains(TurnAction.Loot))
                        {
                            return(Task.FromResult(new Turn(TurnAction.Loot)));
                        }
                    }
                }
                else if (entry.Value.Equals(TileType.Enemy))
                {
                    if (!request.Map.Tiles[entry.Key.X, entry.Key.Y].EnemyGroup.IsDead)
                    {
                        location = entry.Key;
                        if (request.PossibleActions.Contains(TurnAction.Attack))
                        {
                            return(Task.FromResult(new Turn(TurnAction.Attack)));
                        }
                        if (request.PossibleActions.Contains(TurnAction.Loot))
                        {
                            return(Task.FromResult(new Turn(TurnAction.Loot)));
                        }
                    }
                }
                else if (entry.Value.Equals(TileType.Finish))
                {
                    location = entry.Key;
                }
            }

            return(ShowPath(location, request));
        }
 public Navigate(PlayTurnRequest _request, int _positionItemX, int _positionItemY)
 {
     request       = _request;
     positionItemX = _positionItemX;
     positionItemY = _positionItemY;
 }
Esempio n. 25
0
 public bool CanLoot(PlayTurnRequest request)
 {
     return(request.PossibleActions.Contains(TurnAction.Loot));
 }