• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Math Help with i = mod 2, why?

J

jb skaggs

Guest
I am following chess tutorial for GM. My question is concerning the following code:

inside of the for loop to create the chess board is this little piece of math.

if ((i mod 2==0 && j mod 2==0) || (i mod 2 ==1 && j mod 2 ==1))

What specifically is happening here?

thanks JB
 
M

Musehill

Guest
if both i and j are even numbers -OR- both i and j are odd numbers, the following code will run. I haven't seen the tutorial, but maybe that will help you figure it out. Ii would guess it determines whether to place a black or white square?
 
S

SyntaxError

Guest
Esentially, (Im probably stating the obvious but...)
If (the remainder of i divided by 2 is equal to 0 and the remainder of j divided by 2 is equal to 0) is true or (the remainder of i divided by 2 equals 1 and the remainder of j divided by 2 equals 1) is true then...

Does that clear it up?
 
J

JFitch

Guest
This can be simplified to:

Code:
if (i+j) mod 2 == 0
{
}
assuming that i and j are both integers.
 
Last edited by a moderator:
Top