
-----------------------------------
edwardz
Sun Apr 26, 2009 9:22 pm

Compsci class help(classes and methods)
-----------------------------------
What is it you are trying to achieve?
Create a Chuckaluck dice game for my computer science class
Rules
Chuck-a-luck is very simple. The gambler selects an integer from 1 to 6, and then the three dice are rolled. if exactly k dice show the gambler's number, the payoff is K:1. Design your main to test the outcome of allowing the user to select a value for k and n. have the computer play n simulated rounds of chuck-a-luck using k as the user's value for each of the n rounds. output the outcome of the n plays along with how many time k occured by itself, as a double, as a triple and not at all.
We are learning about classes. So yeah. Dice class and shit like that.>.> 

What is the problem you are having?
Program has minor flaws at end

Describe what you have tried to solve this problem
Making the variable global..passing the parameters


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
%============================================================================
class Dice

    export rollDie, drawDie, valueOfDie, value


    var value : int := 1


    procedure rollDie
        randint (value, 1, 6)
    end rollDie

    function valueOfDie : int
        result value
    end valueOfDie

    procedure drawDie (x, y, o : int)


        if value = 1 then
            Draw.FillOval (x + 10, y + 10, 2, 2, black)
            Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
        elsif value = 2 then
            Draw.FillOval (5 + x, 5 + y, 2, 2, black)
            Draw.FillOval (16 + x, 16 + y, 2, 2, black)
            Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
        elsif value = 3 then
            Draw.FillOval (16 + x, 5 + y, 2, 2, black)
            Draw.FillOval (10 + x, 10 + y, 2, 2, black)
            Draw.FillOval (5 + x, 16 + y, 2, 2, black)
            Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
        elsif value = 4 then
            Draw.FillOval (16 + x, 5 + y, 2, 2, black)
            Draw.FillOval (5 + x, 16 + y, 2, 2, black)
            Draw.FillOval (16 + x, 16 + y, 2, 2, black)
            Draw.FillOval (5 + x, 5 + y, 2, 2, black)
            Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
        elsif value = 5 then
            Draw.FillOval (16 + x, 16 + y, 2, 2, black)
            Draw.FillOval (5 + x, 5 + y, 2, 2, black)
            Draw.FillOval (10 + x, 10 + y, 2, 2, black)
            Draw.FillOval (5 + x, 16 + y, 2, 2, black)
            Draw.FillOval (16 + x, 5 + y, 2, 2, black)
            Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
        elsif value = 6 then
            Draw.FillOval (7 + x, 16 + y, 2, 2, black)
            Draw.FillOval (7 + x, 10 + y, 2, 2, black)
            Draw.FillOval (7 + x, 4 + y, 2, 2, black)
            Draw.FillOval (15 + x, 16 + y, 2, 2, black)
            Draw.FillOval (15 + x, 10 + y, 2, 2, black)
            Draw.FillOval (15 + x, 4 + y, 2, 2, black)
            Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
        end if
    end drawDie

end Dice
%=============================================================================
class Chuckaluck
    import Dice
    export rollDice, drawDice, getPoint

    var die1 : ^Dice
    var die2 : ^Dice
    var die3 : ^Dice

    new die1
    new die2
    new die3

    procedure Sort2 (var A : ^Dice, var B : ^Dice)
        var C : ^Dice

        if A -> valueOfDie > B -> valueOfDie then
            C := A
            A := B
            B := A
        end if

    end Sort2

    procedure Sort
        Sort2 (die1, die2)
        Sort2 (die2, die3)
        Sort2 (die1, die2)
    end Sort

    procedure rollDice
        die1 -> rollDie
        die2 -> rollDie
        die3 -> rollDie
        Sort

    end rollDice

    procedure drawDice
        var number : int
        var value : int
        var intx : int
        var into : int
        var inty : int
        rollDice
        intx := 1
        inty := 1
        into := 0

        die1 -> drawDie (intx, inty, into)
        intx := 25
        inty := 1
        into := 25

        die2 -> drawDie (intx, inty, into)
        intx := 50
        inty := 1
        into := 50

        die3 -> drawDie (intx, inty, into)
    end drawDice

    procedure getPoint (var k : int, var point : int)

        
        if die1 -> valueOfDie = k then
            point := point + 1
        end if
        if die1 -> valueOfDie = k then
            point := point + 1
        end if
        if die1 -> valueOfDie = k then
            point := point + 1
        end if

    end getPoint

end Chuckaluck
%=========================================================================


var die1 : int
var die2 : int
var die3 : int
var answer : int
var answer2 : int
var value : int
var n, k : ^Chuckaluck
var rounds : int
var values : int
var point : int
var counter : int
new Chuckaluck, n
new k
counter := 0
randomize
View.Set ("graphics")
point:=0
put "Enter K value"
get answer
put "Enter N value"
get answer2

loop
    
    n -> rollDice
    k -> drawDice
    n -> getPoint (answer, point)
    counter := counter + 1
    put "The number of dice equal to the number is", " ", point
%-     delay (50)
    cls
    exit when counter = answer2
end loop







Please specify what version of Turing you are using
3.1.1a

-----------------------------------
Dusk Eagle
Sun Apr 26, 2009 9:59 pm

Re: Compsci class help(classes and methods)
-----------------------------------
Your code goes inside the syntax tags, like this: 
x="turing"]

CODE HERE!!!

[/syntax]

-----------------------------------
edwardz
Sun Apr 26, 2009 10:04 pm

Re: Compsci class help(classes and methods)
-----------------------------------
What is it you are trying to achieve?
Create a Chuckaluck dice game for my computer science class
Rules
Chuck-a-luck is very simple. The gambler selects an integer from 1 to 6, and then the three dice are rolled. if exactly k dice show the gambler's number, the payoff is K:1. Design your main to test the outcome of allowing the user to select a value for k and n. have the computer play n simulated rounds of chuck-a-luck using k as the user's value for each of the n rounds. output the outcome of the n plays along with how many time k occured by itself, as a double, as a triple and not at all.
We are learning about classes. So yeah. Dice class and shit like that.>.>

What is the problem you are having?
Program has minor flaws at end

Describe what you have tried to solve this problem
Making the variable global..passing the parameters


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
 
%============================================================================
class Dice

export rollDie, drawDie, valueOfDie, value


var value : int := 1


procedure rollDie
randint (value, 1, 6)
end rollDie

function valueOfDie : int
result value
end valueOfDie

procedure drawDie (x, y, o : int)


if value = 1 then
Draw.FillOval (x + 10, y + 10, 2, 2, black)
Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
elsif value = 2 then
Draw.FillOval (5 + x, 5 + y, 2, 2, black)
Draw.FillOval (16 + x, 16 + y, 2, 2, black)
Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
elsif value = 3 then
Draw.FillOval (16 + x, 5 + y, 2, 2, black)
Draw.FillOval (10 + x, 10 + y, 2, 2, black)
Draw.FillOval (5 + x, 16 + y, 2, 2, black)
Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
elsif value = 4 then
Draw.FillOval (16 + x, 5 + y, 2, 2, black)
Draw.FillOval (5 + x, 16 + y, 2, 2, black)
Draw.FillOval (16 + x, 16 + y, 2, 2, black)
Draw.FillOval (5 + x, 5 + y, 2, 2, black)
Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
elsif value = 5 then
Draw.FillOval (16 + x, 16 + y, 2, 2, black)
Draw.FillOval (5 + x, 5 + y, 2, 2, black)
Draw.FillOval (10 + x, 10 + y, 2, 2, black)
Draw.FillOval (5 + x, 16 + y, 2, 2, black)
Draw.FillOval (16 + x, 5 + y, 2, 2, black)
Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
elsif value = 6 then
Draw.FillOval (7 + x, 16 + y, 2, 2, black)
Draw.FillOval (7 + x, 10 + y, 2, 2, black)
Draw.FillOval (7 + x, 4 + y, 2, 2, black)
Draw.FillOval (15 + x, 16 + y, 2, 2, black)
Draw.FillOval (15 + x, 10 + y, 2, 2, black)
Draw.FillOval (15 + x, 4 + y, 2, 2, black)
Draw.Box (1 * x, 1 * y, 20 + o, 20, black)
end if
end drawDie

end Dice
%=============================================================================
class Chuckaluck
import Dice
export rollDice, drawDice, getPoint

var die1 : ^Dice
var die2 : ^Dice
var die3 : ^Dice

new die1
new die2
new die3

procedure Sort2 (var A : ^Dice, var B : ^Dice)
var C : ^Dice

if A -> valueOfDie > B -> valueOfDie then
C := A
A := B
B := A
end if

end Sort2

procedure Sort
Sort2 (die1, die2)
Sort2 (die2, die3)
Sort2 (die1, die2)
end Sort

procedure rollDice
die1 -> rollDie
die2 -> rollDie
die3 -> rollDie
Sort

end rollDice

procedure drawDice
var number : int
var value : int
var intx : int
var into : int
var inty : int
rollDice
intx := 1
inty := 1
into := 0

die1 -> drawDie (intx, inty, into)
intx := 25
inty := 1
into := 25

die2 -> drawDie (intx, inty, into)
intx := 50
inty := 1
into := 50

die3 -> drawDie (intx, inty, into)
end drawDice

procedure getPoint (var k : int, var point : int)


if die1 -> valueOfDie = k then
point := point + 1
end if
if die1 -> valueOfDie = k then
point := point + 1
end if
if die1 -> valueOfDie = k then
point := point + 1
end if

end getPoint

end Chuckaluck
%=========================================================================


var die1 : int
var die2 : int
var die3 : int
var answer : int
var answer2 : int
var value : int
var n, k : ^Chuckaluck
var rounds : int
var values : int
var point : int
var counter : int
new Chuckaluck, n
new k
counter := 0
randomize
View.Set ("graphics")
point:=0
put "Enter K value"
get answer
put "Enter N value"
get answer2

loop

n -> rollDice
k -> drawDice
n -> getPoint (answer, point)
counter := counter + 1
put "The number of dice equal to the number is", " ", point
%- delay (50)
cls
exit when counter = answer2
end loop







Please specify what version of Turing you are using
3.1.1a

-----------------------------------
wtd
Sun Apr 26, 2009 10:22 pm

RE:Compsci class help(classes and methods)
-----------------------------------
[url=http://wiki.compsci.ca/index.php?title=Turing_Style_Guideline#Indentation]Indenting helps.

-----------------------------------
Dusk Eagle
Sun Apr 26, 2009 10:38 pm

Re: Compsci class help(classes and methods)
-----------------------------------
In your getPoint procedure, (which should be a [url=http://compsci.ca/v3/viewtopic.php?t=14665]function, btw), you are calling  "die1 -> valueOfDie" three times. Shouldn't you be using die2 and die3? (It would also be better practice to make die1, die2, and die3 into a single [url=http://compsci.ca/v3/viewtopic.php?t=14333]array, but this isn't essential.)
