Alice Community  

Go Back   Alice Community > General Discussion > Questions and Comments

Reply
 
Thread Tools Display Modes
A question about arrays and boolean
Old
cubeNoob
Junior Member
 
Status: Offline
Posts: 4
Join Date: Nov 2011
Location: North Carolina
Default 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
   
Reply With Quote
Old
Mr Kidnapper
Senior Member
 
Status: Offline
Posts: 442
Join Date: Feb 2011
Default 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.
   
Reply With Quote
well....
Old
cubeNoob
Junior Member
 
Status: Offline
Posts: 4
Join Date: Nov 2011
Location: North Carolina
Default well.... - 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
Attached Files
File Type: a2w cube project methods.a2w (5.51 MB, 9 views)
   
Reply With Quote
Old
Mr Kidnapper
Senior Member
 
Status: Offline
Posts: 442
Join Date: Feb 2011
Default 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.
   
Reply With Quote
hmm
Old
cubeNoob
Junior Member
 
Status: Offline
Posts: 4
Join Date: Nov 2011
Location: North Carolina
Default hmm - 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?
   
Reply With Quote
Old
Mr Kidnapper
Senior Member
 
Status: Offline
Posts: 442
Join Date: Feb 2011
Default 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.
   
Reply With Quote
=(
Old
cubeNoob
Junior Member
 
Status: Offline
Posts: 4
Join Date: Nov 2011
Location: North Carolina
Default =( - 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
   
Reply With Quote
Old
davidghemer
Member
 
Status: Offline
Posts: 38
Join Date: Nov 2011
Default 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.
Attached Files
File Type: a2w cube_test.a2w (168.9 KB, 3 views)


For video tutorials on programming in Alice 2.2 check out my YouTube channel

http://www.youtube.com/user/drdave785

Also check out my Programming in Alice blog at

http://programminginalice.com
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.