TheChess

chess/move.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 THECHESS_MOVE_H_
00012 #define THECHESS_MOVE_H_
00013 
00014 namespace thechess {
00015 namespace chess {
00016 class Move;
00017 }
00018 }
00019 
00020 #include "xy.hpp"
00021 #include "field.hpp"
00022 #include "board.hpp"
00023 
00024 namespace thechess {
00025 namespace chess {
00026 
00027 class Move {
00028 public:
00029     Move(Xy from, Xy to, Chessman turn_into)
00030         : from_(from), to_(to), turn_into_(turn_into) {}
00031 
00032     Move(Xy from, Xy to);
00033     Move(Xy from, Xy packed_to, const Board& board);
00034     Move();
00035 
00036     Xy from() const {
00037         return from_;
00038     }
00039     Xy to() const {
00040         return to_;
00041     }
00042     Chessman turn_into() const {
00043         return turn_into_;
00044     }
00045     void from(Xy v) {
00046         from_ = v;
00047     }
00048     void to(Xy v) {
00049         to_ = v;
00050     }
00051     void turn_into(Chessman v) {
00052         turn_into_ = v;
00053     }
00054 
00055     int dx() const {
00056         return to().x_() - from().x_();
00057     }
00058     int dy() const {
00059         return to().y_() - from().y_();
00060     }
00061 
00062     Xy packed_to() const;
00063 
00064     bool could_turn_into(const Board& board) const;
00065 
00066     bool operator==(const Move& other) const {
00067         return from() == other.from() && to() == other.to();
00068     }
00069 
00070     bool operator!=(const Move& other) const {
00071         return !(*this == other);
00072     }
00073 
00074     std::string pgn_from(const Board& board) const;
00075     std::string pgn(const Board& board, const Board& board_after,
00076                     bool skip_chessmen=false) const;
00077 
00078 private:
00079     unsigned from_ : 7;
00080     unsigned to_ : 7;
00081     Chessman turn_into_ : 3;
00082 };
00083 
00084 const Move move_null(xy_null, xy_null);
00085 
00086 }
00087 }
00088 
00089 #endif // THECHESS_MOVE_H_
00090 
 All Classes Functions Enumerations Enumerator