diff --git a/board.lua b/board.lua index 622d63d..4ceffb4 100644 --- a/board.lua +++ b/board.lua @@ -4,6 +4,7 @@ function board:init(ruleset) self.ruleset=ruleset self.cursor=cursor:new(self) self.animator=animator:new() + self.checkpoint=nil self.slots={} self.wells={} @@ -67,12 +68,20 @@ function board:deal(seed) end end +function board:undo() + if (self.checkpoint) self.checkpoint:apply(self) print("applied") + self.checkpoint=nil +end + function board:on_idle() self:find_automove() end +function board:pre_move(card) + self.checkpoint=checkpoint:new(self,card) +end + function board:on_move() - -- TODO: Make checkpoint self:find_automove() end @@ -142,6 +151,13 @@ function board:draw() end end) + if self.checkpoint then + local cpl=self.ruleset.layouts:checkpoint() + local x,y=cpl:place_card(0) + self.ruleset.deck:draw_card(x,y,self.checkpoint.card,{shadowed=true}) + print("❎",x+1,y+9,7) + end + self.animator:draw() if self.animator:idle() then diff --git a/checkpoint.lua b/checkpoint.lua new file mode 100644 index 0000000..8b654d5 --- /dev/null +++ b/checkpoint.lua @@ -0,0 +1,39 @@ +checkpoint=klass() +function checkpoint:init(board,card) + self.card=card + self.slots={} + self.wells={} + for s=1,#board.slots do + local cnt={} + for c in all(board.slots[s].contents) do + add(cnt,c) + end + self.slots[s]=cnt + end + for w=1,#board.wells do + local cnt={} + for c in all(board.wells[w].contents) do + add(cnt,c) + end + self.wells[w]=cnt + end +end + +function checkpoint:apply(board) + for s=1,#board.slots do + while #board.slots[s].contents>0 do + deli(board.slots[s].contents) + end + for i in all(self.slots[s]) do + add(board.slots[s].contents,i) + end + end + for w=1,#board.wells do + while #board.wells[w].contents>0 do + deli(board.wells[w].contents) + end + for i in all(self.wells[w]) do + add(board.wells[w].contents,i) + end + end +end \ No newline at end of file diff --git a/cursor.lua b/cursor.lua index a54ebaf..d624445 100644 --- a/cursor.lua +++ b/cursor.lua @@ -37,6 +37,7 @@ function cursor:toggle_grab() if acc==acceptance_state.not_grabbed then if (self.board.slots[self:hover_slot()]:peek()) self.grabbed=self:hover_slot() elseif acc==acceptance_state.would_accept then + self.board:pre_move(src:peek()) local card=src:pop() tar:add(card) self.grabbed=nil diff --git a/main.lua b/main.lua index 222fe08..fcd5a66 100644 --- a/main.lua +++ b/main.lua @@ -14,6 +14,7 @@ function main:update() if (btnp(2)) self.board.cursor:move_y(-1) if (btnp(3)) self.board.cursor:move_y(1) if (btnp(4)) self.board.cursor:toggle_grab() + if (btnp(5)) self.board:undo() end end diff --git a/main.p8 b/main.p8 index 80ebc48..d67180c 100644 --- a/main.p8 +++ b/main.p8 @@ -5,6 +5,7 @@ __lua__ #include animator.lua #include board.lua #include board_animations.lua +#include checkpoint.lua #include dealer.lua #include cursor.lua #include layout.lua diff --git a/progression.lua b/progression.lua index d19a976..c428912 100644 --- a/progression.lua +++ b/progression.lua @@ -1,5 +1,5 @@ progression={ - ruleset:new(11,5,10,25), + ruleset:new(11,4,13,22,"ff"), -- level 1 ruleset:new(5,1,9,0), -- by test: always winnable -- level 2 diff --git a/ruleset.lua b/ruleset.lua index c783131..c4505a2 100644 --- a/ruleset.lua +++ b/ruleset.lua @@ -176,6 +176,11 @@ function ruleset:generate_layouts() assert(false,"unknown well") end + function layouts:checkpoint() + local wx=(ruleset.n_slots\2)*10 + return layout:new(x+wx,1,layout_mode.obscured) + end + function layouts:slot(i) if i<=ruleset.n_slots then local sx=(i-1)*10 diff --git a/simulator/level_7.txt b/simulator/level_7.txt index 14968d1..5dd58a2 100644 --- a/simulator/level_7.txt +++ b/simulator/level_7.txt @@ -852,3 +852,200 @@ 5002 5046 5015 +5072 +5007 +5108 +4988 +5101 +4906 +5090 +4987 +5012 +5166 +5098 +5136 +5125 +5064 +5134 +5143 +5195 +5190 +5197 +5193 +5078 +5089 +5208 +5133 +4941 +5217 +5142 +5198 +5227 +5225 +5251 +5246 +5187 +5219 +5139 +5249 +5157 +5273 +5077 +4942 +5267 +5268 +5213 +5239 +5252 +5291 +5308 +5253 +5306 +5242 +5296 +5288 +5344 +5313 +5088 +5224 +5356 +5207 +5338 +5186 +5343 +5381 +5151 +5401 +5405 +5270 +5416 +5376 +5427 +5415 +5438 +5279 +5479 +5349 +5302 +5430 +5330 +5471 +5503 +5446 +5283 +5404 +5495 +5519 +5363 +5111 +5400 +5512 +5541 +5317 +5546 +5480 +5502 +5504 +5399 +5524 +5547 +5535 +5567 +5419 +5469 +5580 +5599 +5537 +5575 +5550 +5568 +5605 +5615 +5555 +5498 +5574 +5463 +5493 +5315 +5564 +5663 +5633 +5677 +5640 +5656 +5604 +5511 +5686 +5702 +5660 +5697 +5662 +5626 +5684 +5560 +5709 +5680 +5713 +5669 +5561 +5741 +5699 +5733 +5745 +5752 +5607 +5732 +5716 +5721 +5706 +5764 +5765 +5584 +5671 +5761 +5781 +5750 +5809 +5717 +5812 +5825 +5808 +5842 +5844 +5848 +5753 +5687 +5814 +5879 +5893 +5890 +5794 +5846 +5931 +5802 +5930 +5876 +5914 +5932 +5747 +5948 +5963 +5970 +5912 +5720 +5974 +5990 +5722 +5818 +5852 +5647 +5976 +6025 +6012 +6032 +6038 +6050 +6047 +5954 +6056 +5964