This is a temporary, read-only recovery of the chessprogrammingwiki while a longer-term plan is worked out. Editing is not possible right now, but will be again soon.
Chess Programming Wiki All pages Other namespaces

Color

Home * Chess * Color

Viktor Vasnetsov - Last Judgment 1Viktor Vasnetsov - Last Judgment 1


  1. Last Judgment fresco by Viktor Vasnetsov, between 1885 and 1896, St. Vladimir's Cathedral, Kiev, Ukraine, Black-and-white dualism from Wikipedia, Wikimedia Commons↩︎

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.

Contents
  1. Color Definition
  2. Toggle Color
  3. See also
  4. External Links
  5. References

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 the color as left operand inside a register or memory cell with an immediate constant (ecBlack).

inline enumColor toggleColor(enumColor color) {
   return color ^ ecBlack;
}

See also

References

Up one Level

Categories: Viktor Vasnetsov

What links here

Contributors: GerdIsenberg.