diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss index 318a039c..e8271722 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss @@ -836,4 +836,23 @@ (entryCreationWindow.hide) (when entryWindow (set entryWindow.keyboardEnabled true) - (entryWindow.show))) \ No newline at end of file + (entryWindow.show))) + +(defMacro withConnectedAndMatching [forOrDoFor &body body] + `(,forOrDoFor s rewardSprites.members + (let [id (dictGet indexMap s) + connectedPieces (dictGet connectedPieces id) + matchingPieces (filter (for map [matchingPiecesLeft matchingPiecesRight matchingPiecesUp matchingPiecesDown] + (dictGet map id)))] + ,@body))) + +(method countAvailableMatches [] + (iHalf + (apply + + (withConnectedAndMatching for + (- matchingPieces.length connectedPieces.length))))) + +(method :Array> listAvailableMatches [] + (apply concat (the Array>> (withConnectedAndMatching for + (for piece (filter matchingPieces ->p !(contains connectedPieces p)) + [s piece]))))) \ No newline at end of file