Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 I need help !!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
japer88




PostPosted: Thu Jun 10, 2010 11:31 am   Post subject: I need help !!!

hey, can someone tell how to make a black and red checker board on turing

i have made a one that is black and white and one that is red and white. heres the code i used.

const SIZE := 50

var num_square : int

procedure Draw_square (row, colum : int)
drawfillbox (row * SIZE, colum * SIZE - 1, row * SIZE - SIZE, colum * SIZE - SIZE, ((row + colum * 7) mod 2) * black)
end Draw_square

procedure Checker_board
for row : 1 .. num_square
for colum : 1 .. num_square
Draw_square (row, colum)
end for
end for
end Checker_board

setscreen ("graphics:1000;650")

put " welcome to my cheaker board program Smile"
put ""

put "how many square's would you like?? " ..
get num_square

Checker_board
Sponsor
Sponsor
Sponsor
sponsor
Cezna




PostPosted: Thu Jun 10, 2010 11:44 am   Post subject: RE:I need help !!!

Just draw a red box in the area that the checker board pattern will be drawn over, or have colourback (red) at the top.

For future reference, look at the sticky topic at the top of the topic list for the help section, titled: "Don't post I need help topics"
japer88




PostPosted: Thu Jun 10, 2010 11:51 am   Post subject: Re: I need help !!!

thx but i tryed that and it doesent work.
USEC_OFFICER




PostPosted: Thu Jun 10, 2010 11:55 am   Post subject: RE:I need help !!!

Did you draw it before the other boxes, i.e. before the main loop/procedure?
Cezna




PostPosted: Thu Jun 10, 2010 11:56 am   Post subject: RE:I need help !!!

You tried drawing a box, or changing the background colour?
TheGuardian001




PostPosted: Thu Jun 10, 2010 12:06 pm   Post subject: Re: I need help !!!

Neither will work. The drawing code draws both black and white squares. The colour parameter:

((row + colum * 7) mod 2) * black

Will return either white or black depending on the row and column.

Instead of using math based colour choosing, you should just use an if statement, IE:

code:

if (row_is_even and column_is_odd) or (row_is_odd and column_is_even)
    draw_black_square
else if (row_is even and column_is_even) or (row_is_odd and column_is_odd)
    draw_coloured_square
end if
chrisbrown




PostPosted: Thu Jun 10, 2010 12:31 pm   Post subject: Re: I need help !!!

TheGuardian001 @ Thu Jun 10, 2010 12:06 pm wrote:
Instead of using math based colour choosing, you should just use an if statement

Or an array with 2 elements, one for each colour. Then draw(..., colours(column mod 2 xor row mod 2) )
japer88




PostPosted: Fri Jun 11, 2010 9:28 am   Post subject: Re: I need help !!!

wow sweet, but were would i put the if statment???
Sponsor
Sponsor
Sponsor
sponsor
andrew.




PostPosted: Fri Jun 11, 2010 10:23 am   Post subject: RE:I need help !!!

In your draw square procedure. So it would be something like:
Turing:
proc drawSquare (row, column : int)
    if row mod 2 = 0 xor column mod 2 = 0 then:
        put "Draw a black square"
    else
        put "Draw a white square"
    end if
end drawSquare


Edit: I would like to say what the xor function is because it may be new to you. Basically "xor", or "exclusive or", works like this: it's either one or the other, but not both. So for example, if both are the same (ie. true and true, or false and false) it will return false. If they are different, it will return true. It's pretty much TheGuardian's method, but simplified with a different operator. I hope I explained it well enough.
chrisbrown




PostPosted: Fri Jun 11, 2010 11:10 am   Post subject: Re: RE:I need help !!!

Actually, I was thinking something more along the lines of:
Turing:
var colours : array 0 .. 1 of string := init ("white", "black")

proc drawSquare (row, column : int)
    put "Draw a " + colours(row mod 2 xor column mod 2) + " square"
end drawSquare


A slightly different example:
Turing:
var colours : array 0 .. 1 of string := init ("white", "black")

for y : 1 .. 8
    for x : 1 .. 8
        put colours (x mod 2 xor y mod 2), " " ..
    end for
    put ""
    put ""
end for


I really don't like code repetition.
TheGuardian001




PostPosted: Fri Jun 11, 2010 11:14 am   Post subject: Re: I need help !!!

using an array seems somewhat more complicated in this case. I wouldn't bother using an array for 2 colours, it's short enough to just throw it in a conditional.

Also, I'm pretty sure you can't specify a string as a colour parameter. You'd need to replace those with the number constants to draw a box.
chrisbrown




PostPosted: Fri Jun 11, 2010 11:27 am   Post subject: Re: I need help !!!

TheGuardian001 @ Fri Jun 11, 2010 11:14 am wrote:
using an array seems somewhat more complicated in this case. I wouldn't bother using an array for 2 colours, it's short enough to just throw it in a conditional.

True, it's pretty trivial; I just find functional solutions more elegant, and since he was using a formula to determine his colours, I just wanted to demonstrate a more abstracted solution.


TheGuardian001 @ Fri Jun 11, 2010 11:14 am wrote:
Also, I'm pretty sure you can't specify a string as a colour parameter. You'd need to replace those with the number constants to draw a box.

Also true, but that's a simple change and the concept still holds.
japer88




PostPosted: Mon Jun 14, 2010 11:36 am   Post subject: Re: I need help !!!

hey thx guys/girls

but could u maybe give me all of the code plz Laughing
chrisbrown




PostPosted: Mon Jun 14, 2010 11:50 am   Post subject: Re: I need help !!!

japer88 @ Mon Jun 14, 2010 11:36 am wrote:
could u maybe give me all of the code plz Laughing

Nope. You have more than enough information to figure it out. If you're still stuck, ask specific questions and we'll point you in the right direction, but you're not going to get free answers.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: