From 01425e8526505937f6360a1fc02437afebd6bbe8 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Tue, 13 Sep 2022 22:06:15 +0000 Subject: [PATCH] count and list available matches --- .../source/HabitState.kiss | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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