Exemple #1
0
        private bool GenerateInternal(Board board, List <CharacterEntity> friendly, int width, int height)
        {
            try {
                board.width  = width;
                board.height = height;
                board.CreateTerrain(
                    BoardGeneration.Build(map, width, height)
                    );

                List <Tile> tiles = new List <Tile>(board.Tiles);

                // Check it tiles are all connected
                int totalTiles     = tiles.Count;
                int totalConnected = BoardUtils.AllReachableTiles(tiles[0]).Count;
                if (totalTiles != totalConnected)
                {
                    return(false);
                }

                foreach (CharacterEntity friend in friendly)
                {
                    Tile tile = tiles.PopRandom();
                    foreach (Tile n in tile.GetNeighbors())
                    {
                        tiles.Remove(n);
                    }
                    Place(friend, tile);
                }

                foreach (CharacterEntity enemy in RandomEnemies(enemyCount))
                {
                    Tile tile = tiles.PopRandom();
                    foreach (Tile n in tile.GetNeighbors())
                    {
                        tiles.Remove(n);
                    }
                    Place(enemy, tile);
                }
                return(true);
            } catch {
                board.Clear();
                return(false);
            }
        }
Exemple #2
0
    public async void Play()
    {
        await Task.Delay(1000);

        Skill walking = actor.GetMoveSkills().FirstOrDefault();

        if (walking != null && walking.area is Snake snake)
        {
            var reachableTiles = BoardUtils.AllReachableTiles(piece.on, maxLength: snake.maxRange, valid: CanStepOn);
            // TODO: Think
            var pair = reachableTiles.ToList().Random();
            if (pair.Key != piece.on)
            {
                SkillArea a = new SkillArea();
                a.AddRange(pair.Value);
                await SkillHandler.WALK.Apply(piece, a);
            }
        }

        var       skills        = actor.GetCoreSkills();
        float     bestHeuristic = 0;
        Skill     bestSkill     = null;
        SkillArea bestArea      = null;

        foreach (Skill skill in skills)
        {
            if (!skill.condition.IsValid())
            {
                continue;
            }
            // Try Cone
            skill.area.launcher = piece;
            if (skill.area is Cone cone)
            {
                foreach (Direction dir in DirectionUtils.DIRECTIONS)
                {
                    SkillArea area      = cone.SkillAreaIfTarget(dir);
                    float     heuristic = skill.effect.Heuristic(skill.element, piece, area);
                    if (heuristic > bestHeuristic)
                    {
                        bestHeuristic = heuristic;
                        bestArea      = area;
                        bestSkill     = skill;
                    }
                }
            }
            // Try Target
            else if (skill.area is Target target)
            {
                foreach (Tile tile in BoardUtils.AllTiles(t => target.CanSelect(t)))
                {
                    SkillArea area      = target.SkillAreaIfTarget(tile);
                    float     heuristic = skill.effect.Heuristic(skill.element, piece, area);
                    if (heuristic > bestHeuristic)
                    {
                        bestHeuristic = heuristic;
                        bestArea      = area;
                        bestSkill     = skill;
                    }
                }
            }
        }
        if (bestSkill != null)
        {
            await bestSkill.Apply(piece, bestArea);
        }
        Global.battle.NextTurn();
    }