View Full Version : A question about arrays and boolean

12-03-2011, 02:08 PM
is it possible to put all items in an array into a boolean function?

example: if all objects (a, b, c) are within 1 meter of object d then true

thanks any help will be most appreciated :D

Mr Kidnapper
12-03-2011, 04:42 PM
It's the other way around. Use a Do All Together block and insert an if/else statement in there. It will check the if/else statement on all items in an array at the same time.

12-03-2011, 05:20 PM
so i tried that, unfortunately when i try to loop it or use a recursive method on it it throws an error. im trying to create a win situation for a rubiks cube program. program works fine but the win situation doesnt i feel like i have tried everything ill post my program so you can see what im talking about, look in the events for my win conditions and look at the back square and front square objects for the methods used to create my win situation. any advice is much appreciated

Mr Kidnapper
12-03-2011, 05:43 PM
I have no idea what this is win situation is trying to do. I also do not understand how the criteria for winning is chosen.
Now, the way I would do it is by detecting a number of matching pieces. For each side there is an array of 6 numbers, each representing a color. This number goes from 1-9, and when one of the numbers in the array equal 9, the side is considered complete. You can do this by making a For All In Order to check for a 9, which will mark a true/false variable named colorComplete or something true, and this will be done for all 6 sides until all 6 equal true. After all of them equal true at the same time, winner sequence.

12-03-2011, 06:12 PM
i only see one problem with that solution, when solving a rubiks cube there are often times when there sides that are solved and then you have to unsolve the side to solve another, will it detect when you unsolve a side and re-solve it?

Mr Kidnapper
12-03-2011, 06:20 PM
I imagine you would be able to figure out that it would mark the sides as solved or unsolved by yourself, since it's supposed to check the sides every time a turn is made.

12-03-2011, 07:21 PM
well i appreciate your advice, unfortunately i cant figure out how to put it into alice lol i feel like such a noob

12-05-2011, 04:07 PM
The attached world contains a function, faceSameColour, which tests whether an array with nine elements contains the same values (it is with the World object functions). You could use this by representing each face of the cube with an array of 9 elements. Each element of the array is a number, different numbers represent different colours.

The cube will be solved if each face of the cube satisfies the faceSameColour function.

Importantly you need some abstract representation of the cube before you can do any tests.