Home * Chess * Color
DayandNight.jpg

In Chess, Color refers to the color of the two piece sets, the color each player is assigned to, the side to move and the color of a square.

The pieces are divided, into white and black sets, but their colors should not taken literally. The players are referred to as "White" and "Black", they control their associated pieces. The colors of the sixty-four squares alternate and are referred to "light squares" and "dark squares", sometimes also referred to "White" and "Black" squares.
M. C. Escher, Day and Night, 1938 [1]

Color Definition

Since there are only two colors, one bit is sufficient to encode them. This is how one may define colors in C++:
enum enumColor {
   ecWhite = 0,
   ecBlack = 1
};

Toggle Color

Since the players alternately move, one need to toggle the side to move color after each move made inside the Chess Position object. This can be done by subtracting color from one (ecBlack), ...
inline enumColor toggleColor(enumColor color) {
   return ecBlack - color;
}
... or a little bit cheaper by xoring with the color with one (ecBlack).
inline enumColor toggleColor(enumColor color) {
   return color ^ ecBlack;
}

See also


External Links


References

  1. ^ Picture gallery "Switzerland and Belgium 1935 - 1941" from The Official M.C. Escher Website

What links here?


Up one Level