Adding values of a kind? Making a weight puzzle

Hello! I’m making a game for my thesis and part of it is a weights-in-scale puzzle. What I want to achieve with this puzzle is a) for the player always to be able to see the state of the scales (equal, leaning on the right, leaning on the left) according to their weights and b) for the puzzle to be solved when the weights are equal. I can’t think of a way to add the values of each container(scale pans), and the documentation on lists wasn’t very helpful. The way I thought I’d achieve it is brute forcing it with ifs, but before I do that, is there something I’m missing? This is my (relevant) code so far:

A mass is a kind of value. 1dr specifies a mass. The plural of mass is masses.
A weight is a kind of thing. The plural of weight is weights. A weight has a mass. Definition: A weight is heavy if its mass is 1dr or more.

A compartment is a closed unopenable container. (It is in the room).

A weight1 is a weight. It is in the compartment. The mass of weight1 is 2dr.
A weight2 is a weight. It is in the compartment. The mass of weight2 is 5dr.
A weight3 is a weight. It is in the compartment. The mass of weight3 is 3dr.
A weight4 is a weight. It is in the compartment. The mass of weight4 is 4dr.

A scale is a thing in (the room). It is fixed in place. 
A left pan is part of the scale. It is a container.
A right pan is part of the scale. It is a container.

By adding Definition: A weight is heavy if its mass is 1dr or more. I have realized it recognizes if one weight is heavier than the other, but I can’t find a way to do that with a sum of weights. Thank you in advance!

Try adding this to your code:

Scale-state is a kind of value. The scale-states are left-leaning, right-leaning, and centered.

To decide what scale-state is --/a/the scale-state of (S - the scale):
	if the total mass of weights enclosed by the left part of S is greater than the total mass of weights enclosed by the right part of S, decide on left-leaning;
	if the total mass of weights enclosed by the right part of S is greater than the total mass of weights enclosed by the left part of S, decide on right-leaning;
	decide on centered.
	
The description of the scale is "It is currently [scale-state of the scale].".

(See WWI §15.17 - Totals )

[Edit: I changed “in” to “enclosed by” in the above code to account for weights not directly in the pans, but indirectly as well (for example, weights in boxes placed in the scale pans.]

1 Like

Edited your code a bit into this so it compiles, and it worked like a charm! Thanks a lot!

To decide what scale-state is --/a/the scale-state of (S - the scale):
	if the total mass of weights in the left pan is greater than the total mass of weights in the right part of S, decide on left-leaning;
	if the total mass of weights in the right pan is greater than the total mass of weights in the left part of S, decide on right-leaning;
	decide on centered.