diff --git a/solitaire.lua b/solitaire.lua index 958a810..668e821 100644 --- a/solitaire.lua +++ b/solitaire.lua @@ -161,16 +161,20 @@ function update() c_hover[1]=8 end if si>8 and c_left then - c_hover={ - si-1, - #stacks[si-1] - } + c_hover[1]=si-1 + if hand then + c_hover[2]=#stacks[c_hover[1]] + else + c_hover[2]=find_top_of_stack(stacks[c_hover[1]], #stacks[c_hover[1]]) + end end if si>=8 and si<14 and c_right then - c_hover={ - si+1, - #stacks[si+1] - } + c_hover[1]=si+1 + if hand then + c_hover[2]=#stacks[c_hover[1]] + else + c_hover[2]=find_top_of_stack(stacks[c_hover[1]], #stacks[c_hover[1]]) + end end if si>=8 and c_up then c_hover[2]=c_hover[2]-1 @@ -296,6 +300,20 @@ function update() last_left=left end +-- This finds the largest stack that can be moved +function find_top_of_stack(stack, position) + local i=position + while i>1 do + if stack[i-1].rank~=stack[i].rank+1 or + suit_color[stack[i].suit]==suit_color[stack[i-1].suit] + then + return i + end + i=i-1 + end + return 1 +end + function move_is_valid(hand,hover) if hand[1]==hover[1] then return false end local moved_card=stacks[hand[1]][hand[2]]