Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
run some kind of check maybe?
Old
sibhod
Guest
 
Status:
Posts: n/a
Default run some kind of check maybe? - 10-09-2007, 08:41 PM

ok so I have an assignment to make a Guessing Game in which Alice will ask questions like "Is it alive?" in regards to 10 other objects on the screen.

What i have set up is that for example i have a Tree, Man, Cow, Jet, Tank, and Blimp

"Is it alive?"

if i pick yes then the Jet, tank, and blimp all get their opacity set to 0 making them invisible.

All of that is the easy stuff, but the hard part is that i dont know how to make a kind of Check to see if 9 objects have opacity set to 0, then have Alice Say something like "I found it." or maybe even more technical, have her say what the object Is that still has Opacity set to 1 (100%).

I'm tried making some kind of list where it was like.. Objects, and then I put in Camera, Light, Ground, Alice, and then tried to make a "random" object for the last one or something like that. Random would really be more of a variable representing the final object with 100% opacity so now that i think about it, i might have to set Alice, Light, Ground, and Camera all to like.. 99% Opacity, (or the other 10 objects) before i start it so that there will only be 1 object in the end that still has 100% (or 99 depending on which ones i change in the beginning)... Please correct me if i'm wrong about that part.


The problem with the list, if i was on the right track, is that i dont know where i can implement the actual thing because it wouldnt let me make something like "If (List blah blah) is True...", and i also dont even know if that is a possible way of doing what i want.


All help will be appreciated
   
Reply With Quote
Old
Maggie
Guest
 
Status:
Posts: n/a
Default 10-10-2007, 12:05 PM

Dear sibhod,

I may be misunderstanding your question, and I am assuming that you are allowed to ask questions on this board in order to do your school work, and that it doesn't constitute a breach of the academic honesty policy at your institution. If you are not allowed any outside help, please don't read my answer.

I understand the game to be this: the user picks an object on the screen and Alice tries to guess by asking questions such as "is it alive," and objects disappear that don't meet the criteria, based on the user's answer. When there is only one object left, Alice has won.

Is Alice going to do this intelligently? That's very interesting. I'll assume you've got preset questions based on the objects that are there and you're going to ask them whether they eliminate any objects or not. So Alice might ask "is it alive," when all that is left is the blimp and the truck, thus eliminating nothing.

To know how many objects are left, you could keep a counter and decrement it every time an object is eliminated. Then you will know if one object is left.

There are many ways to know which object is left. One possibility would be to check each object's visibility (or opacity). The visible one is still there. I don't know why you would worry about the visibility of the light, the ground, etc. Why would you even bother to check those? Just check the objects that the user is guessing about.

Another would be to set up two parallel arrays -- one with the objects, and the other of boolean, indicating if the object is visible or not. So if item 0 of the object array is a truck and item 0 of visibility is false, then the truck is invisible. If item 2 of the object array is the frog, and item 2 of the visibility array is the only item with a value of true, then the frog is the only item left visible.

I hope this helps.
Maggie
   
Reply With Quote
Old
sibhod
Guest
 
Status:
Posts: n/a
Default 10-10-2007, 02:23 PM

eehhhuu

ok well yes, you did get the basic concept of the game, but I'm not going so far as to have alice be super intelligent and so she could possible ask a question that doesn't relate to any on-screen objects, but right now my main problem is i dont know how to actually make a kind of Check system thing. My teacher has not.. forebode us from asking for help, he encourages us to ask him for help, but when i did and told him what i was trying to do, "make a list of objects and perform some kind of check" he said something along the lines of "well we are not that far into Alice yet so i'm not going to explain how to do those things"

the problem is though, that he wants it to be efficient and i can't really do that with many many basic choppy commands. Else i would have to make 10 preset paths for each individual object, and the way i have mine coded right now (if statements within if statements within if statements basically..) that would make so much useless code.

Basically though, i understand what you are suggesting in your post, i just dont know how to actually implement those things because those are what i was already trying to figure out when my teacher gave us this assignment.



I had an idea like the counter but i dont know how to generalize my commands like "if ANY object becomes invisible then blah blah blah..." i mean is there a way to re-class all 10 of my objects into 1 thing and then have it read something like "if 1 instance of class Choice becomes invisible then blah blah"

once again, any help will be very much appreciated.
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Exclamation 10-11-2007, 07:07 PM

Quote:
Originally Posted by sibhod View Post
... My teacher has not.. forebode us from asking for help, he encourages us to ask him for help, but when i did and told him what i was trying to do, "make a list of objects and perform some kind of check" he said something along the lines of "well we are not that far into Alice yet so i'm not going to explain how to do those things"

the problem is though, that he wants it to be efficient and i can't really do that with many many basic choppy commands. Else i would have to make 10 preset paths for each individual object, and the way i have mine coded right now (if statements within if statements within if statements basically..) that would make so much useless code. ...
I imagine that, from your viewpoint, you may be having some difficulty understanding why your teacher would respond the way that he did. While this is purely speculation on my part, I suspect that he may want you to solve the problem with the tools that you have been given up to this point in the course rather than to jump ahead and use more powerful tools. At least, that is what I often do in the classes that I teach.

Consider an analogy. Assume that you have been tasked to put a bullet through a bullseye on a target at the local shooting range. You would probably have no trouble demolishing the target with an AK47 assault rifle, 30 rounds of ammunition, and a laser sight. On the other hand, you may not even be able to hit the target with a 9-mm handgun and three rounds of ammunition. It would hardly be a test of your skill as a marksman to allow you to use the AK47.

But then again, I may be completely wrong on this. That is just a thought.

For example, in the Alice course that I teach, the two most recent lessons have been designed to solve the same programming problem. The first of the two lessons taught the student how to write the program without the use of variables.

See http://www.dickbaldwin.com/alice/Alice0135.htm

The second of the two lessons taught the student about types and variables and then taught the student how to write the same program using variables.

See http://www.dickbaldwin.com/alice/Alice0140.htm

My purpose in taking this approach was not only to teach the students about types and variables, but also to illustrate the value of using variables.

You may be missing some important lessons by trying to jump ahead instead of giving a lot of thought to the proper use of the tools currently in your toolbox.

Just the thoughts of someone who started programming computers in 1962.
Dick Baldwin
http://www.dickbaldwin.com/toc.htm
http://www.dickbaldwin.com/tocalice.htm

Last edited by DickBaldwin; 10-11-2007 at 10:10 PM. Reason: Correct grammar and spelling.
   
Reply With Quote
Old
Maggie
Guest
 
Status:
Posts: n/a
Default 10-11-2007, 08:23 PM

Quote:
Originally Posted by sibhod View Post
I had an idea like the counter but i dont know how to generalize my commands like "if ANY object becomes invisible then blah blah blah..." i mean is there a way to re-class all 10 of my objects into 1 thing and then have it read something like "if 1 instance of class Choice becomes invisible then blah blah"
I do not think there's a way to do that in Alice, but you are thinking in an object-oriented way. If you move on to Java you'll be able to write code like that.

How are you checking to see if an object is alive, for example, and then what do you do if the object is not alive and the user said that the object s/he's thinking of is alive? That would mean you have to eliminate that specific object. When you're eliminating that object, you can decrement your counter. (You don't have to answer this question to me, it can be rhetorical. If you're going to use a counter, this is probably the way to do it.)

If you want your code to be more efficient but you're not sure how to make it more efficient, write it the brute force way. Once you've written it the brute force way, then you might see how to make it more efficient. (e.g., "hey, I'm repeating that action five times, I should make that a loop." Or, "hey, those methods are really similar. They could be the same if I just used a parameter," or repeating code could be made into a method -- that sort of thing.)
   
Reply With Quote
Old
sibhod
Guest
 
Status:
Posts: n/a
Default 10-11-2007, 09:11 PM

Though I do understand your point fully Dick, I dont think that was entirely what his intentions were.

Maggie, I do understand your idea about using methods for similar things, but it wouldnt really clean it up because i would still have to use an individual method for each time something disappeared and so basically what my code is looking like is

If [ask the user for yes or no "is it alive?"]
Then DO TOGETHER[set truck able to be seen False]
[set jet able to be seen false]
If [ask the user for yes or no "is it a mammal"]
Then DO TOGETHER[set chicken able to see false]
[set penguin able to see false]
Else <<<Blah blah blah>>>
Else [set cow able to be seen false]
[set chicken able to be seen false]
<<<<<BLah blah blah>>>>
(or whatever the command is)


and so it's basically just a long series of If statements in a chain that stem off from the exact same path, but altering it just slightly on the last question so as to get a specific object. Pretty much i have 4 questions minimum per object.

I suppose i could make a method to set all the living objects and one for all non living to False for able to be seen, but then i would only use them once and it wouldn't be very efficient, in my mind at least.
   
Reply With Quote
Old
Maggie
Guest
 
Status:
Posts: n/a
Default 10-12-2007, 09:02 AM

Dear Sibhod,

I guess it depends on what you mean by "efficient." It would certainly be easier to read and modify if you did move each check into a method. It's inefficient to modify complicated code. However I wasn't making a specific suggestion to write methods, I was just remarking generally that if you do something brute force, sometimes you see a way to generalize and write better code.

The code you've written could be a little more general, I think, although I don't see a way to make it a lot more general in Alice. In another programming language, even without an "implements" kind of inheritance, you could put all of your objects in a list and ask them if they were alive, blue, whatever your questions are. I don't think there's a way to do that in Alice unless you're sending them primitive functions or asking about properties (so "blue" you could do with objects in a list, but not "alive"). I may be wrong about that, I've only been using Alice for a few months, but I've been frustrated by that aspect of the language.

Maggie
   
Reply With Quote
Reply


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.