Resource as Answer to a Puzzle Game

Godot Version 4.5

I’m building a prototype for a puzzle game, similar to Is This Seat Taken? or A Little to the Left. I want the game to allow multiple valid solutions, but I’m not sure what the best approach is in terms of performance and overall PC resource usage.

I have slots that elements can snap into, and the elements themselves. For an element to enter a slot, I use a slot_in function. The puzzle solution would be represented by a resource of type answer_types, which contains all possible valid answers. Then, for each level, I’d configure a specific resource (for example, level_1_answer). The main problem is how to build a player_answer and compare it against the level_answer.

For example, if I have 5 elements — A, B, C, D, and E — and 4 slots, and A and E are mutually exclusive, then I have two valid solutions:
[A, B, C, D] or [B, C, D, E].

To handle this, I wouldn’t look at the elements themselves, but at their attributes. For instance, I might require attributes 1, 2, 3, and 4. Elements B, C, and D provide attributes 1, 2, and 3, while A and E both provide attribute 4. That way, I can keep both solutions valid.

The mutual exclusion rule could be handled by modifying the element’s slot_in function to check whether a mutually exclusive element is already present in the answer. But that raises a few questions: how do I actually build the player_answer, and how do I compare it with the level_answer? Am I only checking counts of each element or attribute (for example, “I need 2 elements of type A” or “I need 3 elements with attribute 2”)?

One idea I had was for each element to have a copy of answer_types with the values it can contribute, and then add those to the player_answer. But then I run into the same issue again: how do I populate and manage that resource cleanly?

Initially, I thought about using dictionaries, but I’ve read that best practice would be to use resources instead, since they’re easier to edit when defining level answers and help keep the data consistent. I feel like if I were using dictionaries, I’d already have the prototype working, but I’d probably hate myself later when creating more levels hahaha.

I’m still thinking through these options and wanted to hear your ideas for possible solutions. I’ve been looking for tutorials and posts about puzzle game design, but I haven’t found many that go into this kind of problem.

Answer type doesn’t have to be a Resource, but just an enum parameter on the Element. And the Element I assume is just some Node2D, Node2D or Control derived type, depending on your game type.

Then, as you said - your Level should have a defined list of required answer types, which is Array[Answer Type]. You loop through them to see if all of them have been selected by the player, or if anything is still missing or wrongly selected. Depends on your structure, but Level could also be just a Node derived scene, then you don’t need a Resource to hold the information. But if your Level design is exactly the same each time and te only difference is the answer, then it might make sense to contain the answer in a Resource that you apply to the Level at runtime.

I’m currently structuring it like this: each element is a Node2D with a CollisionShape2D. When it enters a slot (which is an Area2D with its own CollisionShape2D), it triggers a function that adds itself to player_answer, and then checks whether player_answer is equal to or sufficient for level_answer.

The level itself is the larger scene that represents the game stage. For example, if level_answer requires 2 elements of type A and 1 element of type B, and I have two different slots containing one A element and one AB element, I would already be meeting the requirements. In that case, player_answer would be equivalent to level_answer.

player_answer starts empty when the level begins and is gradually filled as elements enter the slots. Because of this, my initial idea was to use a dictionary-based answer system and compare two different dictionaries.

However, after reading some discussions, I saw that Resources are often recommended as data containers, and that’s where my confusion started. I’m unsure what the best way is to structure and operationalize these answers: should I stick with dictionaries, use custom Resources, or combine both somehow?