TheChess

chess/field.hpp

00001 /*
00002  * thechess, chess game web application written in C++ and based on Wt
00003  * Copyright (C) 2010 Boris Nagaev
00004  *
00005  * thechess is licensed under the GNU GPL Version 2.
00006  * Other versions of the GPL do not apply.
00007  * See the LICENSE file for terms of use.
00008  */
00009 
00010 //
00011 #ifndef FIELD_H_
00012 #define FIELD_H_
00013 
00014 #include <boost/format.hpp>
00015 
00016 #include <Wt/WString>
00017 
00018 namespace thechess {
00019 namespace chess {
00020 
00021 enum Color {
00022     white = 0,
00023     black = 1,
00024     color_null = 2
00025 };
00026 
00027 const int Color_count = 3;
00028 
00029 enum Chessman {
00030     chessman_null = 0,
00031     bishop = 1, // слон
00032     king   = 2,
00033     knight = 3, // конь
00034     pawn   = 4, // пешка
00035     queen  = 5,
00036     rock   = 6  // ладья
00037 };
00038 
00039 const int Chessman_count = 7;
00040 const char* const letters_chessmen = "-BKNPQR";
00041 
00042 //~ inline bool operator !(const Color& c) { return (Color)((bool)c); }
00043 
00044 Wt::WString color2str(Color color);
00045 
00046 inline Color other_color(Color color) {
00047     return color == white ? black : white;
00048 }
00049 
00050 inline char chessman_char(Chessman chessman) {
00051     return letters_chessmen[(int)chessman];
00052 }
00053 
00054 class Field { // Color & Chessman
00055 public:
00056     Field(Color color, Chessman chessman);
00057     bool operator==(const Field& field) const {
00058         return color() == field.color() && chessman() == field.chessman();
00059     }
00060     bool operator!=(const Field& field) const {
00061         return color() != field.color() || chessman() != field.chessman();
00062     }
00063 
00064     Color color() const {
00065         return color_;
00066     }
00067     Chessman chessman() const {
00068         return chessman_;
00069     }
00070     void color(Color v) {
00071         color_ = v;
00072     }
00073     void chessman(Chessman v) {
00074         chessman_ = v;
00075     }
00076 
00077 
00078 private:
00079     Color color_;
00080     Chessman chessman_;
00081 };
00082 
00083 }
00084 }
00085 
00086 #endif // FIELD_H_
 All Classes Functions Enumerations Enumerator