示例#1
0
文件: AI.cs 项目: TehPers/Joueur.cs
        private void MoveToEnemies(Cowboy cowboy)
        {
            Console.WriteLine($"{cowboy.Job}: Looking for enemies starting at {cowboy.Tile.X}, {cowboy.Tile.Y}");
            Node path = this.PathToNearest(cowboy.Tile, t => t.Cowboy?.Owner == this.Player.Opponent, t => {
                int cost = this.GetMovementCost(t);
                // Try to go to another side of enemy if tile would damage friendly unit
                //if (t.tileNorth && t.tileNorth.cowboy && t.tileNorth.cowboy.owner == this.player) cost += 7;
                //if (t.tileEast && t.tileEast.cowboy && t.tileEast.cowboy.owner == this.player) cost += 7;
                //if (t.tileSouth && t.tileSouth.cowboy && t.tileSouth.cowboy.owner == this.player) cost += 7;
                //if (t.tileWest && t.tileWest.cowboy && t.tileWest.cowboy.owner == this.player) cost += 7;
                return(cost);
            }, true);

            if (path != null)
            {
                Console.WriteLine($"{cowboy.Job}: Found path! Target at ({path.Tile.X}, {path.Tile.Y}).");

                Node moveNode = path;
                while (moveNode.Parent?.Parent != null)
                {
                    moveNode = moveNode.Parent;
                }

                if (moveNode != path)
                {
                    if (cowboy.Move(moveNode.Tile))
                    {
                        return;
                    }
                    Console.WriteLine($"{cowboy.Job}: Couldn't Move. Pathfinding is broken.");
                }
                else
                {
                    Console.WriteLine($"{cowboy.Job}: Already here!");
                }
            }
            else
            {
                Console.WriteLine($"{cowboy.Job}: Path not found.");
            }
        }
示例#2
0
文件: AI.cs 项目: TehPers/Joueur.cs
        private void RunFromHazards(Cowboy cowboy)
        {
            if (this.GetMovementCost(cowboy.Tile) != 1)
            {
                return;
            }

            Console.WriteLine($"{cowboy.Job}: Running from hazards starting at {cowboy.Tile.X}, {cowboy.Tile.Y}");
            Node path = this.PathToNearest(cowboy.Tile, tile => this.GetMovementCost(tile) == 1, null, true);

            if (path != null)
            {
                Console.WriteLine($"{cowboy.Job}: Found path! Target at {path.Tile.X}, {path.Tile.Y}");

                Node moveNode = path;
                while (moveNode.Parent?.Parent != null)
                {
                    moveNode = moveNode.Parent;
                }

                if (moveNode != path)
                {
                    if (cowboy.Move(moveNode.Tile))
                    {
                        return;
                    }
                    Console.WriteLine("{cowboy.job}: Couldn't move. Pathfinding is broken");
                }
                else
                {
                    Console.WriteLine("{cowboy.job}: Already safe!");
                }
            }
            else
            {
                Console.WriteLine("{cowboy.job}: Path not found");
            }
        }
示例#3
0
文件: AI.cs 项目: TehPers/Joueur.cs
        private bool MoveToPiano(Cowboy cowboy, HashSet <int> playedPianos)
        {
            Console.WriteLine($"{cowboy.Job}: Looking for piano starting at {cowboy.Tile.X}, {cowboy.Tile.Y}");
            Node path = this.PathToNearest(cowboy.Tile, t => t.Furnishing != null && t.Furnishing.IsPiano && !playedPianos.Contains(this.CoordsToIndex(t.X, t.Y)), null, true);

            if (path == null)
            {
                Console.WriteLine($"{cowboy.Job}: Path not found");
            }
            else
            {
                Console.WriteLine($"{cowboy.Job}: Found path! Target at {path.Tile.X}, {path.Tile.Y}");

                Node moveNode = path;
                while (moveNode.Parent?.Parent != null)
                {
                    moveNode = moveNode.Parent;
                }

                if (moveNode != path)
                {
                    if (cowboy.Move(moveNode.Tile))
                    {
                        return(true);
                    }
                    Console.WriteLine($"{cowboy.Job}: Couldn't Move. Pathfinding is broken");
                }
                else
                {
                    Console.WriteLine($"{cowboy.Job}: Playing piano");
                    cowboy.Play(moveNode.Tile.Furnishing);
                    playedPianos.Add(this.CoordsToIndex(moveNode.Tile.X, moveNode.Tile.Y));
                    return(true);
                }
            }

            return(false);
        }
示例#4
0
文件: AI.cs 项目: TehPers/Joueur.cs
        // validSpot(tile) => -# for break, 0 for continue, +# for match
        private bool MoveToLineOfSight(Cowboy cowboy, Func <Tile, int> validSpot, out string actDir)
        {
            Console.WriteLine($"{cowboy.Job}: Looking for line of sight spot to enemies starting at {cowboy.Tile.X}, {cowboy.Tile.Y}");
            string dir  = null;
            Node   path = this.PathToNearest(cowboy.Tile, tile => {
                // Check if valid spot
                int cost = this.GetMovementCost(tile);
                if (cost < 0 && tile.Cowboy != cowboy)
                {
                    return(false);
                }
                // Check if enemy piano-playing cowboy in line of sight
                Tile t;

                // Check +x line of sight
                dir   = "East";
                int x = tile.X;
                int y = tile.Y;
                while ((t = this.GetTile(++x, y)) != null)
                {
                    int r = validSpot(t);
                    if (r < 0)
                    {
                        break;
                    }
                    if (r > 0)
                    {
                        return(true);
                    }
                }
                // Check -x line of sight
                dir = "West";
                x   = tile.X;
                y   = tile.Y;
                while ((t = this.GetTile(--x, y)) != null)
                {
                    int r = validSpot(t);
                    if (r < 0)
                    {
                        break;
                    }
                    if (r > 0)
                    {
                        return(true);
                    }
                }

                // Check +y line of sight
                dir = "South";
                x   = tile.X;
                y   = tile.Y;
                while ((t = this.GetTile(x, ++y)) != null)
                {
                    int r = validSpot(t);
                    if (r < 0)
                    {
                        break;
                    }
                    if (r > 0)
                    {
                        return(true);
                    }
                }

                // Check -y line of sight
                dir = "North";
                x   = tile.X;
                y   = tile.Y;
                while ((t = this.GetTile(x, --y)) != null)
                {
                    int r = validSpot(t);
                    if (r < 0)
                    {
                        break;
                    }
                    if (r > 0)
                    {
                        return(true);
                    }
                }

                dir = null;
                return(false);
            });

            actDir = dir;
            if (path != null)
            {
                Console.WriteLine($"{cowboy.Job}: Found path! Target at {path.Tile.X}, {path.Tile.Y}");
                Node moveNode = path;
                while (moveNode.Parent?.Parent != null)
                {
                    moveNode = moveNode.Parent;
                }

                if (moveNode.Tile != cowboy.Tile)
                {
                    if (cowboy.Move(moveNode.Tile))
                    {
                        return(true);
                    }
                    Console.WriteLine($"{cowboy.Job}: Couldn't move. Pathfinding is broken.");
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                Console.WriteLine($"{cowboy.Job}: No decent spots found.");
            }
            return(false);
        }