팔레트 장난감용 tile picker를 만들고 있어요 (모바일 앱이고, 터치 UI를 붙이기 전에 lua main.lua와 스크립트로 짠 decision 목록으로 headless 테스트 중이에요). 이상한 게 두 가지 있는데 버그가 하나인지 두 개인지 모르겠어요.
want = "amber"(팔레트에서 세 번째)로 reject하면 다음에 x=2 color=green이 나와요. 일반 reject는 괜찮아요.
- 마지막에 찍는 history dump가 모든 항목에 똑같은 color와 x를 출력해요. 마지막 proposal 값(
x=3 color=green)이 계속 반복돼요. 그래도 grid는 결과적으로 맞게 나와요.
resume 출력을 보면 decision은 제대로 들어오고 있어서, resume이 off-by-one인 것 같지는 않아요 (coroutine.resume docs 참고). history가 grid를 늦게 읽는 걸까요?
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
그리고 history를 기록하는 Session:step의 일부분이에요:
table.insert(self.history, { tile = self.pending, decision = decision })
if decision.accept then
self.grid[self.pending.x] = self.pending.color.name
end
amber가 어디서 사라지는 걸까요?
영어에서 번역·원문 보기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 me x=2 color=green next. 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?