static async Task TakeActionInUpToNLands(SelfCtx ctx, int adjCount, IEnumerable <Space> spaces, ActionOption <TargetSpaceCtx> action)
    {
        List <Space> options = spaces.ToList();

        while (adjCount-- > 0 && options.Count > 0)
        {
            var space = await ctx.Decision(new Select.Space($"{action.Description} ({adjCount + 1} remaining)", options, Present.Done));

            if (space == null)
            {
                break;
            }
            await action.Execute(ctx.Target(space));

            options.Remove(space);
        }
    }
Exemple #2
0
    // Excludes Oceans
    static ActionOption <SelfCtx> PickLandThenTakeAction(
        ActionOption <TargetSpaceCtx> spaceAction,
        Func <TargetSpaceCtx, bool> filter, string filterDescription,
        string landPreposition = "in"          // Depending on Action, "from" or "to" might be better
        ) => new ActionOption <SelfCtx>($"{spaceAction.Description} {landPreposition} {filterDescription}.",
                                        async ctx => {
        var spaceOptions = ctx.AllSpaces
                           .Select(s => ctx.Target(s))
                           .Where(x => !x.Space.IsOcean && filter(x))
                           .ToArray();
        if (spaceOptions.Length == 0)
        {
            return;
        }

        var spaceCtx = await ctx.SelectSpace("Select space to " + spaceAction.Description, spaceOptions);
        await spaceAction.Execute(spaceCtx);
    }
                                        );
Exemple #3
0
    // Excludes Oceans
    static public ActionOption <SelfCtx> PickDifferentLandThenTakeAction(
        string description,
        ActionOption <TargetSpaceCtx> spaceAction,
        Func <Space, bool> spaceFilter
        )
    {
        List <Space> used = new List <Space>();

        return(new ActionOption <SelfCtx>(description, async ctx => {
            var spaceOptions = ctx.AllSpaces.Where(s => !s.IsOcean && spaceFilter(s)).Except(used).ToArray();
            if (spaceOptions.Length == 0)
            {
                return;
            }

            var spaceCtx = await ctx.SelectSpace("Select space to " + spaceAction.Description, spaceOptions);
            used.Add(spaceCtx.Space);
            await spaceAction.Execute(spaceCtx);
        }));
    }