Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   The Binary game (http://www.alice.org/community/showthread.php?t=10050)

 Kelrizzo 04-25-2013 04:40 PM

The Binary game

I'm working my way through the Alice Textbook and I think my brain is not making connections with how variables get assigned to objects.

In the game from the text, you have the three switches. Each switch is assigned a 0 or 1. You now have a binary number (000, 001, 010, 011, etc). In my example the switch being up represents 1 and the switch begins in the up position. If you get the number correct, a light bulb lights up.

I have a world level variable for the Object switch so I can modify which switch I'm using, and I also have a world level variable to hold the random number.

I really think I'm going about this the wrong way, but it's taking me quite long to do so I figured I'd stop desk/head and ask for help.

 MrMoke 04-25-2013 08:51 PM

Simple

Don't know about the book, but
Click on any object.
Click the properties tab in details.
Click the Create Variable button and make one for that object.

 Kelrizzo 04-26-2013 01:07 PM

Oh I understand the physical steps to make a variable. Maybe I'm too tired to make sense :) I was talking about the theoretical...when to use a variable versus a parameter.

I'm going to work on the project again now so I may get somewhere on my own, but I need to assign a random value 0 or 1 to each of the three switches. The user guesses what each switch is by flipping it up or down. Up represents 1, down represents 0. So you have a binary number with 3 digits.

If you guess the right number, the lightbulb goes on.

 chickentree 04-27-2013 01:10 PM

[QUOTE=Kelrizzo;52812]Oh I understand the physical steps to make a variable. Maybe I'm too tired to make sense :) I was talking about the theoretical...when to use a variable versus a parameter.

I'm going to work on the project again now so I may get somewhere on my own, but I need to assign a random value 0 or 1 to each of the three switches. The user guesses what each switch is by flipping it up or down. Up represents 1, down represents 0. So you have a binary number with 3 digits.

If you guess the right number, the lightbulb goes on.[/QUOTE]

If I understand correctly you have a target value from 0 to 7 and you want to use this to tell when the switches are in the correct position. Each switch can either be off-0 or on-1 what you may be missing is the binary math here. Using three bits in binary I can represent any number from 0 to 7. Here is the binary:

000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7

Why did I go through all that? Well since each switch can be either a 0 or a 1 we need to scale the value of two of the switches to create the three binary digits above.
So your switches value would be something like "set currentVal = sw1 + sw2 * 2 + sw3 *4"
Now you have converted the individual switches into one value between 0 and 7.

PS the values 2 and 4 in the conversion come from binary positional notation. If you want to look this up, start with decimal positional notation. This will make the concept clear and then see how it would be done for numbering systems in other bases.

Mark

 Kelrizzo 04-27-2013 02:43 PM

1 Attachment(s)
Ahhhh ok. It's all a matter of setting up a way in which Alice can understand what you are trying to accomplish. Thank you!

As I was muddling through this, it came to mind that I would like a way to indicate whether the switch was on or off (1 or 0), so I developed a light system and named the method "moveSwitch" with a parameter "whichSwitch".

I had it working perfectly...then I broke it. I actually only had it working for the one switch, but of course I want it to work for all the switches.

[HTML]<del>Two issues:
1) When I tell the switch to move forward simply by playing with the object alone, the "turn forward" command works the way I wish it to. When I call it with my method, it no longer turns in that way. I've played with several "as seen by" commands, but to no avail.

2) The light was changing from green to red, and back to green, then stopped working as I added the parameter.

What did I do to break it?</del>
[/HTML]I'll keep playing with it, maybe I will figure it out, and will let you know if I do. In the meantime, I will also begin working on the binary portion.

EDIT: Fixed it. Now to apply it to the other lights and switches then incorporate the binary.

EDIT2: Applied to all lights and it works. Now the last step. Thanks for all the assistance.

EDIT3: Yeay Got it! Thanks :D

 KentuckyFriedJesus 05-01-2013 01:52 PM

I have a suggestion for you.

Since your game is a binary game, I have a message for you from me via binary language:

01000010 01100101 00100000 01110011 01110101 01110010 01100101 00100000 01110100 01101111 00100000 01100100 01110010 01101001 01101110 01101011 00100000 01111001 01101111 01110101 01110010 00100000 01001111 01110110 01100001 01101100 01110100 01101001 01101110 01100101 00101110

 All times are GMT -5. The time now is 04:21 PM.