
-----------------------------------
japer88
Thu Jun 10, 2010 11:31 am

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 :)"
put ""

put "how many square's would you like?? " ..
get num_square

Checker_board

-----------------------------------
Cezna
Thu Jun 10, 2010 11:44 am

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
Thu Jun 10, 2010 11:51 am

Re: I need help !!!
-----------------------------------
thx but i tryed that and it doesent work.

-----------------------------------
USEC_OFFICER
Thu Jun 10, 2010 11:55 am

RE:I need help !!!
-----------------------------------
Did you draw it before the other boxes, i.e. before the main loop/procedure?

-----------------------------------
Cezna
Thu Jun 10, 2010 11:56 am

RE:I need help !!!
-----------------------------------
You tried drawing a box, or changing the background colour?

-----------------------------------
TheGuardian001
Thu Jun 10, 2010 12:06 pm

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
[/code]

-----------------------------------
chrisbrown
Thu Jun 10, 2010 12:31 pm

Re: I need help !!!
-----------------------------------
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
Fri Jun 11, 2010 9:28 am

Re: I need help !!!
-----------------------------------
wow sweet, but were would i put the if statment???

-----------------------------------
andrew.
Fri Jun 11, 2010 10:23 am

RE:I need help !!!
-----------------------------------
In your draw square procedure. So it would be something like:
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
Fri Jun 11, 2010 11:10 am

Re: RE:I need help !!!
-----------------------------------
Actually, I was thinking something more along the lines of:
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:
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
Fri Jun 11, 2010 11:14 am

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
Fri Jun 11, 2010 11:27 am

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.
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.


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
Mon Jun 14, 2010 11:36 am

Re: I need help !!!
-----------------------------------
hey thx guys/girls

but could u maybe give me all of the code plz  :lol:

-----------------------------------
chrisbrown
Mon Jun 14, 2010 11:50 am

Re: I need help !!!
-----------------------------------
could u maybe give me all of the code plz  :lol:
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.
