Example #1
0
 public string NextAction(LegacyMap map, IPlayer player)
 {
     if (path == null)
     {
         return(null);
     }
     else if (idx < path.Length)
     {
         Point p    = path[idx];
         var   type = map.tileTypeMap[p.X, p.Y];
         if (type == TileContent.Lava || type == TileContent.Resource || type == TileContent.Unknown)
         {
             return(null);
         }
         else if (type == TileContent.Wall)
         {
             Console.WriteLine("RAWR");
             return(AIHelper.CreateMeleeAttackAction(p - player.Position)); //hotfix degueu
         }
         idx++;
         return(AIHelper.CreateMoveAction(p - player.Position));
     }
     else
     {
         return(null);
     }
 }
Example #2
0
        /// <summary>
        /// Walk right next to a tile
        /// </summary>
        internal string WalkTowardsTile(Point tilePosition, Map map, bool isReturningHome)
        {
            var deltaX = tilePosition.X - PlayerInfo.Position.X;
            var deltaY = tilePosition.Y - PlayerInfo.Position.Y;

            if (!isReturningHome)
            {
                if (deltaX < 0)
                {
                    deltaX += 1;
                }
                else
                {
                    deltaX -= 1;
                }
            }

            //moving character
            if (deltaX != 0)
            {
                var direction = deltaX > 0 ? 1 : -1; // UGLY
                if (map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Wall || map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Player)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(direction)));
                }
                if (map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Lava || map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Player)
                {
                    return(AIHelper.CreateMoveAction(new Point(0, 1)));
                }
                return(AIHelper.CreateMoveAction(new Point(direction)));
            }

            if (deltaY != 0)
            {
                var direction = deltaY > 0 ? 1 : -1;
                if (map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Wall || map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Player)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(0, direction)));
                }
                if (map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Lava || map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Player)
                {
                    return(AIHelper.CreateMoveAction(new Point(1)));
                }
                return(AIHelper.CreateMoveAction(new Point(0, direction)));
            }

            arrivedAtDestination = true;
            return(AIHelper.CreateEmptyAction());
        }
Example #3
0
 public string NavigateToNextPosition(Tile adjacentTile)
 {
     if (adjacentTile.TileType == TileContent.Wall || adjacentTile.TileType == TileContent.Player)
     {
         return(AIHelper.CreateMeleeAttackAction(GetDirectionToTile(adjacentTile)));
     }
     else
     {
         return(AIHelper.CreateMoveAction(GetDirectionToTile(adjacentTile)));
     }
 }
Example #4
0
        private string MoveTo(Point direction)
        {
            var tileToGo = _executer.Map.TileAt(direction + _executer.PlayerInfo.Position);

            if (tileToGo.TileType == TileContent.Wall)
            {
                return(AIHelper.CreateMeleeAttackAction(direction));
            }
            else
            {
                return(AIHelper.CreateMoveAction(direction));
            }
        }
Example #5
0
        /// <summary>
        /// Implement your bot here.
        /// </summary>
        /// <param name="map">The gamemap.</param>
        /// <param name="visiblePlayers">Players that are visible to your bot.</param>
        /// <returns>The action you wish to execute.</returns>
        internal string ExecuteTurn(Map map, IEnumerable <IPlayer> visiblePlayers)
        {
            // TODO: Implement your AI here.
            if (map.GetTileAt(PlayerInfo.Position.X + _currentDirection, PlayerInfo.Position.Y) == TileContent.Wall)
            {
                _currentDirection *= -1;
            }

            var data = StorageHelper.Read <TestClass>("Test");

            Console.WriteLine(data?.Test);
            return(AIHelper.CreateMoveAction(new Point(_currentDirection, 0)));
        }
Example #6
0
 internal string MoveDirection(int Xdistance, int Ydistance, Map map)
 {
     if (Math.Abs(Xdistance) >= Math.Abs(Ydistance))
     {
         if (map.GetTileAt(PlayerInfo.Position.X + (Xdistance / Xdistance), PlayerInfo.Position.Y) == TileContent.Resource)
         {
             if (Math.Abs(Ydistance) != 0)
             {
                 return(AIHelper.CreateMoveAction(new Point(0, (Ydistance / Math.Abs(Ydistance)))));
             }
             else
             {
                 return(AIHelper.CreateMoveAction(new Point(0, 1)));
             }
         }
         if (map.GetTileAt(PlayerInfo.Position.X + (Xdistance / Math.Abs(Xdistance)), PlayerInfo.Position.Y) == TileContent.Wall)
         {
             return(AIHelper.CreateMeleeAttackAction(new Point((Xdistance / Math.Abs(Xdistance)), 0)));
         }
         else
         {
             return(AIHelper.CreateMoveAction(new Point((Xdistance / Math.Abs(Xdistance)), 0)));
         }
     }
     else
     {
         if (map.GetTileAt(PlayerInfo.Position.X, PlayerInfo.Position.Y + (Ydistance / Math.Abs(Ydistance))) == TileContent.Resource)
         {
             if (Math.Abs(Xdistance) != 0)
             {
                 return(AIHelper.CreateMoveAction(new Point((Xdistance / Math.Abs(Xdistance)), 0)));
             }
             else
             {
                 return(AIHelper.CreateMoveAction(new Point(1, 0)));
             }
         }
         if (map.GetTileAt(PlayerInfo.Position.X, PlayerInfo.Position.Y + (Ydistance / Math.Abs(Ydistance))) == TileContent.Wall)
         {
             return(AIHelper.CreateMeleeAttackAction(new Point(0, (Ydistance / Math.Abs(Ydistance)))));
         }
         else
         {
             return(AIHelper.CreateMoveAction(new Point(0, (Ydistance / Math.Abs(Ydistance)))));
         }
     }
 }
Example #7
0
        /// <summary>
        /// Implement your bot here.
        /// </summary>
        /// <param name="map">The gamemap.</param>
        /// <param name="visiblePlayers">Players that are visible to your bot.</param>
        /// <returns>The action you wish to execute.</returns>
        internal string ExecuteTurn(Map map, IEnumerable <IPlayer> visiblePlayers)
        {
            if (PlayerInfo.CarriedResources >= PlayerInfo.CarryingCapacity)
            {
                return(WalkTowardsTile(PlayerInfo.HouseLocation, map, true));
            }

            int[] mineralDirection = MineralAdjacentDirection(map);

            if (mineralDirection != null)
            {
                return(AIHelper.CreateCollectAction(new Point(mineralDirection[0], mineralDirection[1])));
            }

            else
            {
                var resource = LookForVisibleResource(map);

                if (resource != null)
                {
                    return(WalkTowardsTile(new Point(resource.X, resource.Y), map, false));
                }

                // randomly walk if no resource detected within range
                else
                {
                    if (map.GetTileAt(PlayerInfo.Position.X + _currentDirection, PlayerInfo.Position.Y) ==
                        TileContent.Wall)
                    {
                        _currentDirection *= -1;
                        distanceTravelled  = 0;
                        moving             = false;
                        previousDirection  = INVALID_DIRECTION;
                    }

                    if (movingRandom)
                    {
                        return(MoveRandomly(map));
                    }
                }
            }

            var data = StorageHelper.Read <TestClass>("Test");

            return(AIHelper.CreateMoveAction(new Point(0, -1)));
        }
 /// <summary>
 /// When called, the player will move in a specific direction
 /// Input must be between [-1, -1] and [1, 1], and can only have 1 parameter != 0
 /// </summary>
 /// <param name="point">Move in the x axis. Left = [-1, 0], Right = [1, 0]
 ///                     Move in the y axis. Top = [0, -1], Down = [0, 1] </param>
 private static string Move(Point point)
 {
     if (point.X != 0 ^ point.Y != 0)
     {
         if (point.X != 0) // move in x axis
         {
             return(AIHelper.CreateMoveAction(new Point(point.X, 0)));
         }
         else // move in y axis
         {
             return(AIHelper.CreateMoveAction(new Point(0, point.Y)));
         }
     }
     else // Called if the user sent inconsistent entrie values
     {
         return(AIHelper.CreateMoveAction(new Point(0, 0))); // Won't move
     }
 }
Example #9
0
        private string moveToHouse(Point houseDistance, IPlayer playerInfor, Map map)
        {
            if (houseDistance.X != 0)
            {
                // if (ressourcePositions[0].X - PlayerInfo.Position.X == 1){

                //     Random rand = new Random();
                //     int number = rand.Next(0,1);
                //     return AIHelper.CreateMoveAction(new Point(0,randomize()));
                // }
                if (map.GetTileAt(playerInfor.Position.X - 1, playerInfor.Position.Y) == TileContent.Wall)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(-1, 0)));
                }
                if (map.GetTileAt(playerInfor.Position.X + 1, playerInfor.Position.Y) == TileContent.Wall)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(1, 0)));
                }
                return(houseDistance.X > 0 ? AIHelper.CreateMoveAction(new Point(1, 0)) : AIHelper.CreateMoveAction(new Point(-1, 0)));
            }
            else if (houseDistance.Y != 0)
            {
                // if (ressourcePositions[0].Y - PlayerInfo.Position.Y == 1){
                //     Random rand = new Random();
                //     int number = rand.Next(0,1);
                //     return AIHelper.CreateMoveAction(new Point(randomize(),0));

                // }
                if (map.GetTileAt(playerInfor.Position.X, playerInfor.Position.Y - 1) == TileContent.Wall)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(0, -1)));
                }
                if (map.GetTileAt(playerInfor.Position.X, playerInfor.Position.Y + 1) == TileContent.Wall)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(0, 1)));
                }
                return(houseDistance.Y > 0 ? AIHelper.CreateMoveAction(new Point(0, 1)) : AIHelper.CreateMoveAction(new Point(0, -1)));
            }
            return(AIHelper.CreateMoveAction(new Point(0, 1)));
        }
Example #10
0
        private string moveToRessource(Point distance, List <Point> ressourcePositions, IPlayer playerInfor, Map map)
        {
            if (distance.X != 0)
            {
                if (Math.Abs((int)Point.DistanceSquared(ressourcePositions[0], PlayerInfo.Position)) == 1)
                {
                    return(AIHelper.CreateCollectAction(miningPosition(ressourcePositions[0], PlayerInfo.Position)));
                }
                if (map.GetTileAt(playerInfor.Position.X - 1, playerInfor.Position.Y) == TileContent.Wall)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(-1, 0)));
                }
                if (map.GetTileAt(playerInfor.Position.X + 1, playerInfor.Position.Y) == TileContent.Wall)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(1, 0)));
                }

                return(distance.X > 0 ? AIHelper.CreateMoveAction(new Point(1, 0)) : AIHelper.CreateMoveAction(new Point(-1, 0)));
            }

            else if (distance.Y != 0)
            {
                if (Math.Abs((int)Point.DistanceSquared(ressourcePositions[0], PlayerInfo.Position)) == 1)
                {
                    return(AIHelper.CreateCollectAction(miningPosition(ressourcePositions[0], PlayerInfo.Position)));
                }
                if (map.GetTileAt(playerInfor.Position.X, playerInfor.Position.Y - 1) == TileContent.Wall)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(0, -1)));
                }
                if (map.GetTileAt(playerInfor.Position.X, playerInfor.Position.Y + 1) == TileContent.Wall)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(0, 1)));
                }
                return(distance.Y > 0 ? AIHelper.CreateMoveAction(new Point(0, 1)) : AIHelper.CreateMoveAction(new Point(0, -1)));
            }
            return("");
        }
Example #11
0
        internal string MoveRandomly(Map map)
        {
            if (!moving)
            {
                Random rnd = new Random();
                randomDirection = rnd.Next(1, 5);
                randomDistance  = rnd.Next(1, MAX_RANDOM_DISTANCE);
                moving          = true;

                while (randomDirection == previousDirection)
                {
                    randomDirection = rnd.Next(1, 5);
                }
            }

            if (distanceTravelled >= randomDistance)
            {
                moving            = false;
                distanceTravelled = 0;
            }

            if (moving)
            {
                switch (randomDirection)
                {
                case 1:
                    if (MeleeTargetExists(map, 1, 0))
                    {
                        return(AIHelper.CreateMeleeAttackAction(new Point(1, 0)));
                    }
                    return(AIHelper.CreateMoveAction(new Point(1, 0)));

                case 2:
                    if (MeleeTargetExists(map, -1, 0))
                    {
                        return(AIHelper.CreateMeleeAttackAction(new Point(-1, 0)));
                    }
                    return(AIHelper.CreateMoveAction(new Point(-1, 0)));

                case 3:
                    if (MeleeTargetExists(map, 0, 1))
                    {
                        return(AIHelper.CreateMeleeAttackAction(new Point(0, 1)));
                    }
                    return(AIHelper.CreateMoveAction(new Point(0, 1)));

                case 4:
                    if (MeleeTargetExists(map, 0, -1))
                    {
                        return(AIHelper.CreateMeleeAttackAction(new Point(0, -1)));
                    }
                    return(AIHelper.CreateMoveAction(new Point(0, -1)));
                }

                distanceTravelled++;
            }

            if (distanceTravelled >= randomDistance)
            {
                moving            = false;
                distanceTravelled = 0;
            }

            var data = StorageHelper.Read <TestClass>("Test");

            return(AIHelper.CreateEmptyAction());
        }
Example #12
0
        /// <summary>
        /// Implement your bot here.
        /// </summary>
        /// <param name="map">The gamemap.</param>
        /// <param name="visiblePlayers">Players that are visible to your bot.</param>
        /// <returns>The action you wish to execute.</returns>
        internal string ExecuteTurn(Map map, IEnumerable <IPlayer> visiblePlayers)
        {
            getInterestingObjects(map, PlayerInfo.Position);
            objects.Sort((x, y) => x.priority.CompareTo(y.priority));
            Point nextMove;

            if (PlayerInfo.Position == PlayerInfo.HouseLocation)
            {
                nextMove = new Point();
                if (PlayerInfo.GetUpgradeLevel(UpgradeType.Defence) == 0 && PlayerInfo.TotalResources >= upgrades[0])
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.Defence));
                }
                if (PlayerInfo.GetUpgradeLevel(UpgradeType.CarryingCapacity) == 0 && PlayerInfo.TotalResources >= upgrades[0])
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.CarryingCapacity));
                }
                if (PlayerInfo.GetUpgradeLevel(UpgradeType.AttackPower) == 0 && PlayerInfo.TotalResources >= upgrades[0])
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.AttackPower));
                }
                if (PlayerInfo.GetUpgradeLevel(UpgradeType.CarryingCapacity) == 1 && PlayerInfo.TotalResources >= upgrades[1])
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.CarryingCapacity));
                }
                if (PlayerInfo.GetUpgradeLevel(UpgradeType.CollectingSpeed) == 0 && PlayerInfo.TotalResources >= upgrades[0])
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.CollectingSpeed));
                }
            }

            if (PlayerInfo.TotalResources >= 30000 && !PlayerInfo.CarriedItems.Contains(PurchasableItem.Backpack))
            {
                Point shopLocation = map.GetVisibleTiles().FirstOrDefault(x => x.TileType == TileContent.Shop)?.Position;

                if (shopLocation == null)
                {
                    TileContent tileToTheLeft = map.GetTileAt(PlayerInfo.Position.X - 1, PlayerInfo.Position.Y);
                    nextMove = tileToTheLeft != TileContent.Resource && tileToTheLeft != TileContent.Lava ? new Point(-1, 0) : new Point(0, 1);
                }
                else
                {
                    nextMove = new PathFinder(map, PlayerInfo.Position, shopLocation).FindNextMove();
                }

                if (Point.DistanceSquared(PlayerInfo.Position, shopLocation) == 1)
                {
                    return(AIHelper.CreatePurchaseAction(PurchasableItem.Backpack));
                }
            }
            else if (PlayerInfo.CarriedResources == PlayerInfo.CarryingCapacity || objects.Count == 0)
            {
                nextMove = new PathFinder(map, PlayerInfo.Position, PlayerInfo.HouseLocation).FindNextMove();
            }
            else
            {
                nextMove = new PathFinder(map, PlayerInfo.Position, objects[0].position).FindNextMove();
            }
            Point shouldIStayOrShouldIGoNow = PlayerInfo.Position + nextMove;

            TileContent content = map.GetTileAt(shouldIStayOrShouldIGoNow.X, shouldIStayOrShouldIGoNow.Y);

            switch (content)
            {
            case TileContent.Empty:
            case TileContent.House:
                return(AIHelper.CreateMoveAction(nextMove));

            case TileContent.Resource:
                return(AIHelper.CreateCollectAction(nextMove));

            case TileContent.Wall:
                return(AIHelper.CreateMeleeAttackAction(nextMove));

            case TileContent.Player:
                return(AIHelper.CreateMeleeAttackAction(nextMove));

            default:
                return(AIHelper.CreateEmptyAction());
            }
        }
Example #13
0
        private string GoTo(Point location, Map map, bool moveHorizontally)
        {
            Point direction = null;

            if (_temporaryTarget != null && PlayerInfo.Position != _temporaryTarget)
            {
                location = _temporaryTarget;
            }
            else if (PlayerInfo.Position == _temporaryTarget)
            {
                _temporaryTarget = null;
            }

            if (moveHorizontally)
            {
                if (PlayerInfo.Position.X != location.X)
                {
                    direction = new Point(MathF.Sign(location.X - PlayerInfo.Position.X), 0);
                }
                else
                {
                    return(GoTo(location, map, false));
                }

                TileContent content = map.GetTileAt(PlayerInfo.Position.X + direction.X, PlayerInfo.Position.Y + direction.Y);
                if (content != TileContent.Empty && content != TileContent.House)
                {
                    if (content == TileContent.Wall)
                    {
                        return(AIHelper.CreateMeleeAttackAction(direction));
                    }
                    else if (PlayerInfo.Position.Y == location.Y)
                    {
                        _temporaryTarget = FindTemporaryTarget(PlayerInfo.Position, location, true, map);
                    }
                    return(GoTo(location, map, false));
                }
                else
                {
                    return(AIHelper.CreateMoveAction(direction));
                }
            }
            else
            {
                if (PlayerInfo.Position.Y != location.Y)
                {
                    direction = new Point(0, MathF.Sign(location.Y - PlayerInfo.Position.Y));
                }
                else
                {
                    return(GoTo(location, map, true));
                }

                TileContent content = map.GetTileAt(PlayerInfo.Position.X + direction.X, PlayerInfo.Position.Y + direction.Y);
                if (content != TileContent.Empty && content != TileContent.House)
                {
                    if (content == TileContent.Wall)
                    {
                        return(AIHelper.CreateMeleeAttackAction(direction));
                    }
                    else if (PlayerInfo.Position.X == location.X)
                    {
                        _temporaryTarget = FindTemporaryTarget(PlayerInfo.Position, location, false, map);
                    }
                    return(GoTo(location, map, true));
                }
                else
                {
                    return(AIHelper.CreateMoveAction(direction));
                }
            }
        }
Example #14
0
        /// <summary>
        /// Implement your bot here.
        /// </summary>
        /// <param name="map">The gamemap.</param>
        /// <param name="visiblePlayers">Players that are visible to your bot.</param>
        /// <returns>The action you wish to execute.</returns>

        internal string ExecuteTurn(Map map, IEnumerable <IPlayer> visiblePlayers)
        {
            _currentDirection[0] = 0;
            _currentDirection[1] = 0;
            int[] HouseDistance = getHome(map);
            if (ABS(HouseDistance[0], HouseDistance[1]) == 0)
            {
                for (int i = 0; i < 5; i++)
                {
                    int price = prices[upgrades[i]];
                    if (price <= PlayerInfo.TotalResources)
                    {
                        upgrades[i] += 1;
                        /*return getType(i);*/
                    }
                }
            }
            int[] ClosestMine   = getDistance(TileContent.Resource, map);
            int[] ClosestPlayer = getDistance(TileContent.Player, map);
            if (ABS(ClosestPlayer[0], ClosestPlayer[1]) < 9 && ABS(ClosestPlayer[0], ClosestPlayer[1]) > 1)
            {
                return(MoveDirection(ClosestPlayer[0], ClosestPlayer[1], map));
            }
            else if (ABS(ClosestPlayer[0], ClosestPlayer[1]) == 1)
            {
                if (map.GetTileAt(PlayerInfo.Position.X + 1, PlayerInfo.Position.Y) == TileContent.Player)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(1, 0)));
                }
                if (map.GetTileAt(PlayerInfo.Position.X - 1, PlayerInfo.Position.Y) == TileContent.Player)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(-1, 0)));
                }
                if (map.GetTileAt(PlayerInfo.Position.X, PlayerInfo.Position.Y + 1) == TileContent.Player)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(0, 1)));
                }
                if (map.GetTileAt(PlayerInfo.Position.X, PlayerInfo.Position.Y - 1) == TileContent.Player)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(0, -1)));
                }
            }
            bool full = (PlayerInfo.CarryingCapacity == PlayerInfo.CarriedResources);

            if (!full)
            {
                if (ABS(ClosestMine[0], ClosestMine[1]) == 0)
                {
                    return(MoveDirection(HouseDistance[0], HouseDistance[1], map));
                }
                if (ABS(ClosestMine[0], ClosestMine[1]) == 1)  // a cote de la mine
                {
                    if ((map.GetTileAt(PlayerInfo.Position.X + 1, PlayerInfo.Position.Y) == TileContent.Resource))
                    {
                        return(AIHelper.CreateCollectAction(new Point(1, 0)));
                    }
                    if ((map.GetTileAt(PlayerInfo.Position.X - 1, PlayerInfo.Position.Y) == TileContent.Resource))
                    {
                        return(AIHelper.CreateCollectAction(new Point(-1, 0)));
                    }
                    if ((map.GetTileAt(PlayerInfo.Position.X, PlayerInfo.Position.Y + 1) == TileContent.Resource))
                    {
                        return(AIHelper.CreateCollectAction(new Point(0, 1)));
                    }
                    if ((map.GetTileAt(PlayerInfo.Position.X, PlayerInfo.Position.Y - 1) == TileContent.Resource))
                    {
                        return(AIHelper.CreateCollectAction(new Point(0, -1)));
                    }
                }
                else
                {
                    return(MoveDirection(ClosestMine[0], ClosestMine[1], map));
                }
            }
            else
            {
                return(MoveDirection(HouseDistance[0], HouseDistance[1], map));
            }
            return(AIHelper.CreateMoveAction(new Point(0, 1)));
        }
Example #15
0
        internal string ExecuteTurn(Map map, IEnumerable <IPlayer> visiblePlayers)
        {
            //portion pathfinding pour les Mines debut
            PathNoeud           playerPosition = new PathNoeud(PlayerInfo.Position.X, PlayerInfo.Position.Y, 0, 0, null);
            List <PathNoeud>    minePosition   = new List <PathNoeud>();
            List <ResourceTile> minePosition_  = new List <ResourceTile>();

            minePosition_ = GetVisibleResourceTiles(map);
            foreach (ResourceTile rt in minePosition_)
            {
                minePosition.Add(new PathNoeud(rt.Position.X, rt.Position.Y, 0, 0, null));
            }
            List <PathNoeud> paths = new List <PathNoeud>();

            //List<PathNoeud> finalPath = new List<PathNoeud>();

            if (PlayerInfo.Position.X == PlayerInfo.HouseLocation.X)
            {
                if (PlayerInfo.Position.Y == PlayerInfo.HouseLocation.Y)
                {
                    if (CanBuy_Amelioration(PlayerInfo))
                    {
                        return(WhatToBuy_Amelioration(PlayerInfo));
                    }
                }
            }



            if (finalPath.Count() == 0)
            {
                if (MustReturnToHouse() || minePosition.Count == 0)
                {
                    int       x         = PlayerInfo.HouseLocation.X;
                    int       y         = PlayerInfo.HouseLocation.Y;
                    PathNoeud housePath = new PathNoeud(x, y, 0, 0, null);
                    PathNoeud path      = trouverPathMine(playerPosition, housePath, map, PlayerInfo);
                    paths.Add(path);
                }
                else
                {
                    foreach (PathNoeud n in minePosition)
                    {
                        PathNoeud path = trouverPathMine(playerPosition, n, map, PlayerInfo);
                        if (path != null)
                        {
                            paths.Add(path);
                        }
                    }
                }
                if (paths.Count > 0)
                {
                    PathNoeud currentPath = paths[0];
                    foreach (PathNoeud n in paths)
                    {
                        if (currentPath.getGCost() > n.getGCost())
                        {
                            currentPath = n;
                        }
                    }
                    //fin portion pathfinding
                    finalPath = new List <PathNoeud>();
                    while (currentPath != null)
                    {
                        finalPath.Add(currentPath);
                        currentPath = currentPath.getParent();
                    }
                }
            }

            // miner si a coter dune mine
            if (PlayerInfo.CarriedResources != PlayerInfo.CarryingCapacity && mineAutour(map, PlayerInfo))
            {
                int x = 0;
                int y = 0;
                for (int i = -1; i <= 1; i += 2)
                {
                    if (TileContent.Resource == map.GetTileAt(PlayerInfo.Position.X + i, PlayerInfo.Position.Y))
                    {
                        x = PlayerInfo.Position.X + i;
                        y = PlayerInfo.Position.Y;
                        return(AIHelper.CreateCollectAction(new Point(x - PlayerInfo.Position.X, y - PlayerInfo.Position.Y)));
                    }
                }
                for (int i = -1; i <= 1; i += 2)
                {
                    if (TileContent.Resource == map.GetTileAt(PlayerInfo.Position.X, PlayerInfo.Position.Y + i))
                    {
                        x = PlayerInfo.Position.X;
                        y = PlayerInfo.Position.Y + i;
                        return(AIHelper.CreateCollectAction(new Point(x - PlayerInfo.Position.X, y - PlayerInfo.Position.Y)));
                    }
                }
            }

            // se deplacer
            if (finalPath.Count > 0)
            {
                PathNoeud prochainMove = finalPath[finalPath.Count - 1];
                if (map.GetTileAt(prochainMove.getX(), prochainMove.getY()) == TileContent.Wall)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(prochainMove.getX() - PlayerInfo.Position.X, prochainMove.getY() - PlayerInfo.Position.Y)));
                }
                else
                {
                    finalPath.Remove(prochainMove);
                    return(AIHelper.CreateMoveAction(new Point(prochainMove.getX() - PlayerInfo.Position.X, prochainMove.getY() - PlayerInfo.Position.Y)));
                }
            }



            var data = StorageHelper.Read <TestClass>("Test");

            Console.WriteLine(data?.Test);
            return(AIHelper.CreateMoveAction(new Point(_currentDirection, 0)));

            return(null);
        }
Example #16
0
        internal string ExecuteTurn(Map map, IEnumerable <IPlayer> visiblePlayers)
        {
            // TODO: Implement your AI here.
            string instruction = "";

            map.VisibleDistance = 20;
            List <Tile> visibleTiles = map.GetVisibleTiles().ToList();

            ressourceTiles = visibleTiles.Where(t => t.TileType == TileContent.Resource).ToList();
            enemiesTiles   = visibleTiles.Where(t => t.TileType == TileContent.Player).ToList();

            DistanceFromTiles dist = new DistanceFromTiles(TrouverDistanceEntreDeuxPoints);

            Point destination = PlayerInfo.HouseLocation;



            Tuple <Point, TileContent> nextMove = null;

            switch (listTitlePriority[0])
            {
            case TileContent.House:
                nextMove = checkNextTile(map, destination);
                break;

            case TileContent.Lava:
                break;

            case TileContent.Player:
                if (enemiesTiles.Count != 0)
                {
                    enemiesTiles = enemiesTiles.OrderBy(p => dist(p.Position, PlayerInfo.Position)).ToList();
                }
                nextMove = checkNextTile(map, enemiesTiles[1].Position);
                break;

            case TileContent.Resource:
                if (ressourceTiles.Count != 0)
                {
                    ressourceTiles = ressourceTiles.OrderBy(t => dist(t.Position, PlayerInfo.Position)).ToList();
                    destination    = ressourceTiles[0].Position;
                }
                nextMove = checkNextTile(map, destination);
                break;

            case TileContent.Shop:
                break;

            case TileContent.Wall:
                break;
            }



            switch (nextMove.Item2)
            {
            case TileContent.Empty:
                instruction = AIHelper.CreateMoveAction(nextMove.Item1 - this.PlayerInfo.Position);
                break;

            case TileContent.House:
                instruction = AIHelper.CreateMoveAction(nextMove.Item1 - this.PlayerInfo.Position);
                //nextMove = checkNextTile(map, closestResource.Position);
                break;

            case TileContent.Lava:
                break;

            case TileContent.Resource:
                instruction = AIHelper.CreateCollectAction(nextMove.Item1 - this.PlayerInfo.Position);
                break;

            case TileContent.Shop:
                break;

            case TileContent.Player:
                instruction = AIHelper.CreateMeleeAttackAction(nextMove.Item1 - this.PlayerInfo.Position);
                break;

            case TileContent.Wall:
                instruction = AIHelper.CreateMeleeAttackAction(nextMove.Item1 - this.PlayerInfo.Position);
                break;
            }

            if (vertical < 20)
            {
                vertical++;
                instruction = AIHelper.CreateMoveAction(PlayerInfo.HouseLocation - this.PlayerInfo.Position);
            }

            var data = StorageHelper.Read <TestClass>("Test");

            Console.WriteLine(data?.Test);
            return(instruction);//AIHelper.CreateCollectAction(new Point(1, 0));
            //return AIHelper.CreateMoveAction(new Point(-1, 0));
        }
            private static string FindEasyPath(Map map, Point point)
            {
                bool moveLeft  = false,
                     moveRight = false,
                     moveUp    = false,
                     moveDown  = false;

                int nbMovesX = point.X;
                int nbMovesY = point.Y;

                if (nbMovesX > 0)
                {
                    moveRight = true;
                }
                else if (nbMovesX < 0)
                {
                    moveLeft = true;
                }
                if (nbMovesY > 0)
                {
                    moveDown = true;
                }
                else if (nbMovesY < 0)
                {
                    moveUp = true;
                }

                Random random = new Random(DateTime.Now.Millisecond);

                if (random.Next() % 2 == 0)
                {
                    if (moveLeft)
                    {
                        return(AIHelper.CreateMoveAction(new Point(-1, 0)));
                    }
                    else if (moveRight)
                    {
                        return(AIHelper.CreateMoveAction(new Point(1, 0)));
                    }
                    else if (moveUp)
                    {
                        return(AIHelper.CreateMoveAction(new Point(0, -1)));
                    }
                    else //(moveDown)
                    {
                        return(AIHelper.CreateMoveAction(new Point(0, 1)));
                    }
                }
                else
                {
                    if (moveUp)
                    {
                        return(AIHelper.CreateMoveAction(new Point(0, -1)));
                    }
                    else if (moveDown)
                    {
                        return(AIHelper.CreateMoveAction(new Point(0, 1)));
                    }
                    else if (moveLeft)
                    {
                        return(AIHelper.CreateMoveAction(new Point(-1, 0)));
                    }
                    else //(moveRight)
                    {
                        return(AIHelper.CreateMoveAction(new Point(1, 0)));
                    }
                }
            }