1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
inline safe_highlight(int x,int y){
if (is_inside(x,y))
highlight(x,y);
}
void highlight_knight(int x,int y){
static const int offsets[][2]={
{1,-2},
{2,-1},
{2,1},
{1,2},
//Note that the elements below this point are the opposite signs of the
//previous ones, so the array could be cut in half by adding a little
//more logic to the loop.
//It doesn't matter much, though.
{-1,2},
{-2,1},
{-2,-1},
{-1,-2}
};
for (int i=0;i<8;i++)
safe_highlight(x+offsets[i][0],y+offsets[i][1]);
}
|