Ejemplo n.º 1
0
        static List <PathNoeud> getNeighbours(PathNoeud n, PathNoeud end, Map map, IPlayer playerInfo)
        {
            List <PathNoeud> neighbours = new List <PathNoeud>();

            for (int i = -1; i <= 1; i += 2)
            {
                int posX = n.getX();
                int posY = n.getY();
                if (map.VisibleDistance > Math.Abs(posX - playerInfo.Position.X) && map.VisibleDistance > Math.Abs(posY - playerInfo.Position.Y))
                {
                    PathNoeud tampon = new PathNoeud(posX + i, posY, n.getGCost() + 1, calculerHCost(n, end), n);
                    neighbours.Add(tampon);
                }
            }
            for (int i = -1; i <= 1; i += 2)
            {
                int posX = n.getX();
                int posY = n.getY();
                if (map.VisibleDistance > Math.Abs(posX - playerInfo.Position.X) && map.VisibleDistance > Math.Abs(posY - playerInfo.Position.Y))
                {
                    PathNoeud tampon = new PathNoeud(posX, posY + i, n.getGCost() + 1, calculerHCost(n, end), n);
                    neighbours.Add(tampon);
                }
            }
            return(neighbours);
        }
Ejemplo n.º 2
0
        static int calculerHCost(PathNoeud n, PathNoeud end)
        {
            int x = Math.Abs(n.getX() - end.getX());
            int y = Math.Abs(n.getY() - end.getY());

            return(x + y);
        }
Ejemplo n.º 3
0
 static bool verifierNoeudPareil(PathNoeud n1, PathNoeud n2)
 {
     if (n1.getX() == n2.getX() && n1.getY() == n2.getY())
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 4
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);
        }