Building the tile picker for a palette toy (mobile app, testing headless with lua main.lua and a scripted list of decisions before the touch UI). Two things look wrong and I can't tell if it's one bug or two.
- A rejection with
want = "amber"(third in the palette) gets mex=2 color=greennext. Plain rejections are fine. - The history dump at the end prints the same color and x for every entry, the last proposal's (
x=3 color=green, over and over). The grid still ends up right.
The resume prints show the decisions arriving correctly, so I doubt it's an off-by-one resume (see the coroutine.resume docs). Is history reading the grid late?
The coroutine:
function Proposer.new(palette, start_x)
local proposal = { x = start_x, color = nil }
return coroutine.create(function()
local x = start_x
while true do
local c = palette:next()
proposal.x, proposal.color = x, c
local decision = coroutine.yield(proposal)
if decision.accept then
x = x + 1
elseif decision.want then
palette:seek(decision.want)
end
end
end)
end
And the part of Session:step that records history:
table.insert(self.history, { tile = self.pending, decision = decision })
if decision.accept then
self.grid[self.pending.x] = self.pending.color.name
end
Where does the amber get lost?
