
-----------------------------------
glitchy_gal12
Sun May 28, 2006 3:07 pm

Help Needed Related to Randomizing Pictures
-----------------------------------
Ok, I have to create this slot machine program, from which I have to randomize 4 different shapes into 3 seperate square boxes on the same screen, and that the program's purpose is for the user to keep pushing a button until all three slot boxes have 3 identical shapes. The shapes that I am using are a star, an oval, a square, and a maple leaf. The program I'm using is Turing. I'm kind of struggling with this randomizing stuff. If you can, please help me with producing the code   :(

-----------------------------------
Cervantes
Sun May 28, 2006 3:28 pm


-----------------------------------
You've got 4 possible shapes to produce on screen one. You can pick a random number between 1 and 4 using
Rand.Int (1, 4)

-----------------------------------
glitchy_gal12
Sun May 28, 2006 3:37 pm


-----------------------------------
You've got 4 possible shapes to produce on screen one. You can pick a random number between 1 and 4 using
Rand.Int (1, 4)

Thanks for replying  :)  Thanks for the tip, but out of curiousity, is the answer to my problem within to the following thread? http://www.compsci.ca/v2/viewtopic.php?t=12451&highlight=randomize

-----------------------------------
Cervantes
Sun May 28, 2006 3:58 pm


-----------------------------------
Maybe.

As for drawing your actual picture, the easiest thing to do would be to create an array of procedures.


var outcome : array 1 .. 4 of procedure p (x1, y1, x2, y2 : int)

procedure box (x1, y1, x2, y2 : int)
    Draw.FillBox (x1, y1, x2, y2, black)
end box
% Do the same for the other shapes

outcome (1) := box
% Do the same for the other shapes

outcome (Rand.Int (1, 4)) (100, 100, 200, 200)


Not sure I've got the syntax right, here. Can't test it at the moment. Try playing around with it if it's not right, then post back here with the syntax error.

-----------------------------------
HellblazerX
Sun May 28, 2006 4:09 pm


-----------------------------------
an array of procedures.
What?!!!!  :shock: Wow, never knew that.  Does this only apply to Turing, or does this ability extend to other languages?

-----------------------------------
Cervantes
Sun May 28, 2006 4:17 pm


-----------------------------------
Yes, it extends to other languages. It extends especially well to functional languages (a procedure is just a function to a language that doesn't have a defined unit (nil) value, to paraphrase wtd).

For an in-depth explanation of this phenomenon, see [url=http://www.compsci.ca/v2/viewtopic.php?t=12376]Turing as a Functional Programming Lanugage.

-----------------------------------
glitchy_gal12
Sun May 28, 2006 4:29 pm


-----------------------------------
Maybe.

As for drawing your actual picture, the easiest thing to do would be to create an array of procedures.


var outcome : array 1 .. 4 of procedure p (x1, y1, x2, y2 : int)

procedure box (x1, y1, x2, y2 : int)
    Draw.FillBox (x1, y1, x2, y2, black)
end box
% Do the same for the other shapes

outcome (1) := box
% Do the same for the other shapes

outcome (Rand.Int (1, 4)) (100, 100, 200, 200)


Not sure I've got the syntax right, here. Can't test it at the moment. Try playing around with it if it's not right, then post back here with the syntax error.

Ok, I found no syntax errors (Horray!).  :D However, now that I've figured out how to randomize the outcome once, how would I display 2 more seperate random outcomes on the same screen, in addition to my first outcome display?  :? Here's the code I have so far:

var outcome : array 1 .. 4 of procedure p (x1, y1, x2, y2 : int) 

var outcome2 : array 1..4 of procedure p (x1,y1,x2,y2:int)


procedure box (x1, y1, x2, y2 : int) 
    Draw.FillBox (120, 280, 180, 340, black) 
end box 

procedure star (x1,y1,x2,y2:int)
    Draw.FillStar (120,280,180,340,black)
end star

procedure oval (x1,y1,x2,y2:int)
    Draw.FillOval (150,310,30,30,black)
end oval

procedure mapleleaf (x1,y1,x2,y2:int)
    Draw.FillMapleLeaf (120,280,180,340,black)
end mapleleaf




outcome (1) := box
outcome (2) := star 
outcome (3) := oval
outcome (4) := mapleleaf


outcome (Rand.Int (1, 4)) (100, 100, 200, 200) [/code]

-----------------------------------
Cervantes
Sun May 28, 2006 4:33 pm


-----------------------------------

for i : 1 .. 3
    outcome (Rand.Int (1, 4)) (100 * i, 100, 100 * i + 75, 175)
end for


-----------------------------------
glitchy_gal12
Sun May 28, 2006 4:42 pm


-----------------------------------

for i : 1 .. 3
    outcome (Rand.Int (1, 4)) (100 * i, 100, 100 * i + 75, 175)
end for


Would that code cause the shapes to overlap each other? I tried testing it onto Turing, and the shapes ended up overlapping. Is it possible for the three seperate outcomes to be in spaced out positions so that the different outcomes can be viewed more easily? By the way, thanks a million for helping me.   :)

-----------------------------------
Cervantes
Sun May 28, 2006 5:02 pm


-----------------------------------
They're overlapping because you hardcoded the values into the box, star, oval, and mapleleaf procedures. Use the parameters.


procedure box (x1, y1, x2, y2 : int)
    Draw.FillBox (x1, y1, x2, y2, black)
end box 


-----------------------------------
glitchy_gal12
Sun May 28, 2006 5:12 pm


-----------------------------------
They're overlapping because you hardcoded the values into the box, star, oval, and mapleleaf procedures. Use the parameters.


procedure box (x1, y1, x2, y2 : int)
    Draw.FillBox (x1, y1, x2, y2, black)
end box 


Oh ok. I get it now. Once again. thanks so much for your time!  :D Really appreciate it.

-----------------------------------
Cervantes
Sun May 28, 2006 6:16 pm


-----------------------------------
Once again. thanks so much for your time!  :D Really appreciate it.

It was my pleasure. :)
