[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Tools for high level game AI
- From: Steven Johnson <temujin98007@...>
- Date: Mon, 8 Sep 2008 11:43:56 -0700 (PDT)
> > - Can you show me how to modify your lua parlol example by supplying
> > function that will return all possible combinations of two numbers?
> > I have been trying to do it in scheme but with no success. I could though
> > get them one by one by manually typing (fail).
>
>
> As I hinted, it's not very mature yet. After the first non-fail the Choose
> returns and the internal coroutine is lost. Maybe I'll add a ChooseMulti or
> ChooseAll variant function with an accumulator table as argument or return
> value, where in place of this line in coroutineops.lua
>
>
> return choice
>
>
> it would have
>
>
> choices[#choices + 1] = choice
>
>
> You would also need to pass a fail function, which could just be a no-op,
> to the outer Choose so that it terminates gracefully (otherwise, in the best
> case, it'll error on Reset).
>
> Hope that helps / makes sense. If not, I blame trying to reason about this
> without coffee. :D I'll mess around with it tomorrow morning and post an
> example if it works and you haven't already done it.
The new version is attached.
Here's the example:
local Choose = coroutineops.Choose
local ChooseMulti = coroutineops.ChooseMulti
local Reset = coroutine_ex.Reset
local second = {}
local first = ChooseMulti({ 0, 1, 2, 3, 4, 5 }, function(n1)
second[#second + 1] = Choose({ 0, 1, 2, 3, 4, 5 }, function(n2)
if n1 + n2 ~= 7 then
Reset()
end
end)
end)
for i, n1 in ipairs(first) do
printf("%i, %i", n1, second[i])
end
There are still some kinks I'd probably hash out in practice, but it seems to function.
- Steve
Attachment:
CoroutineOps.lua
Description: Binary data