• Create Account

### #Actualblack_darkness

Posted 13 December 2012 - 04:47 PM

Hello. I am writing an algorithm that paints an 8 x 8 checkerboard red, and white. However the algorithm at this moment is 87 lines long. Sadly It would be only 64 lines to individually color all 64 squares. Please give me feedback.

Here is some more relevant information. At first I tried to paint every other square red. However it looked like this. (rough illustration)

Now after implementing my algorithm it looks like this.

Variable k represents the current square. j is the counter. So I use it to run a % on in order to determine even or odd.

if(rects.size()<=8)
{
if(j%2 == 0  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 1)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=16)
{
if(j%2 == 1  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 0)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=24)
{
if(j%2 == 0  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 1)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=32)
{
if(j%2 == 1  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 0)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=40)
{
if(j%2 == 0  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 1)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=48)
{
if(j%2 == 1  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 0)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=56)
{
if(j%2 == 0  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 1)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=64)
{
if(j%2 == 1  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 0)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}


### #1black_darkness

Posted 13 December 2012 - 04:43 PM

Hello. I am writing an algorithm that paints an 8 x 8 checkerboard red, and white. However the algorithm at this moment is 87 lines long. Sadly It would be only 64 lines to individually color all 64 squares. Please give me feedback.

Here is some more relevant information. At first I tried to paint every other square red. However it looked like this. (rough illustration)

Now after implementing my algorithm it looks like this.

Variable k represents the current square.

if(rects.size()<=8)
{
if(j%2 == 0  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 1)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=16)
{
if(j%2 == 1  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 0)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=24)
{
if(j%2 == 0  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 1)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=32)
{
if(j%2 == 1  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 0)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=40)
{
if(j%2 == 0  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 1)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=48)
{
if(j%2 == 1  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 0)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=56)
{
if(j%2 == 0  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 1)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}
else if(rects.size()<=64)
{
if(j%2 == 1  )
{
(*rects[(k)]).set_fill_color(Color::red);
}
else if(j%2 == 0)
{
(*rects[(k)]).set_fill_color(Color::white);
}
}


PARTNERS