7 #include "spriteloader.h"
8 #include "serverreference.h"
25 typedef PieceColor Color;
30 bool checkPawnCapture(const UltimaPosition& position, const Point& pos, const Point& direction, std::vector<Point>& targets) const;
32 UltimaPiece(const Color& color, const Type& type)
33 : m_color(color), m_type(type) { }
34 UltimaPiece& operator=(const UltimaPiece& other) {
35 m_color = other.m_color;
36 m_type = other.m_type;
39 bool operator==(const UltimaPiece& other) const {
40 return equals(&other);
43 Color color() const { return m_color; }
44 Type type() const { return m_type; }
45 QString typeName() const;
47 bool equals(const UltimaPiece* other) const;
48 bool sameColor(const UltimaPiece* other) const;
49 static QString typeSymbol(Type type);
51 bool canMove(UltimaMove& m, const UltimaPosition& pos) const;
52 bool canMoveAs(const UltimaMove& m, const UltimaPosition& pos,
53 std::vector<Point>& targets, Type actualType) const;
60 std::vector<Point> targets;
62 UltimaMove(const Point& from, const Point& to, PieceType /* ignored */ = INVALID_TYPE)
66 static UltimaMove invalid() {
67 return UltimaMove(Point::invalid(), Point::invalid());
71 return from != Point::invalid();
74 ChessMove::Type type() const { return ChessMove::Normal; }
77 class UltimaPosition {
79 typedef UltimaPiece Piece;
80 typedef UltimaMove Move;
81 typedef ChessPosition::State State;
84 virtual ~UltimaPosition();
85 virtual UltimaPosition* clone() const { return new UltimaPosition(*this); }
89 PointerGrid<Piece> m_board;
93 Piece::Color turn() const { return m_turn; }
94 Piece* operator[](const Point& p) const;
95 void setPiece(const Point& p, Piece* piece);
96 bool operator==(const UltimaPosition& other) const;
98 Point findKing(Piece::Color color) const;
99 PathInfo path(const Point& from, const Point& to) const {
100 return m_board.path(from, to);
103 bool valid(const Point& p) const;
104 Move getMove(const AlgebraicNotation&, bool&) const {
105 Q_ASSERT(!"unimplemented"); return *(Move*)0; }
106 bool testMove(Move&) const;
107 bool pseudolegal(Move&) const;
108 void move(const Move& mv);
110 State state() const { return ChessPosition::BlackWins; }
116 class LoadPieces<UltimaPosition> : public LoadPiecesBase<UltimaPosition> {
117 typedef LoadPiecesBase<UltimaPosition> Base;
118 typedef UltimaPiece Piece;
120 LoadPieces(InnerSpriteLoader& data, InnerSpriteLoader::Pixmaps& cache, int size)
121 : Base(data, cache, size) { }
123 #define LOAD(color, type) \
124 load(Piece(color, Piece::type))
125 virtual void apply() {
127 LOAD(WHITE, Withdrawer);
128 LOAD(WHITE, Coordinator);
129 LOAD(WHITE, Chameleon);
130 LOAD(WHITE, LongLeaper);
133 LOAD(BLACK, Withdrawer);
134 LOAD(BLACK, Coordinator);
135 LOAD(BLACK, Chameleon);
136 LOAD(BLACK, LongLeaper);
139 loadUpsideDownRook(WHITE);
140 loadUpsideDownRook(BLACK);
144 void loadUpsideDownRook(Piece::Color color) {
145 Piece coo(color, Piece::Coordinator);
146 Piece imm(color, Piece::Immobilizer);
148 SpriteStore::Token rookToken = PieceToken<Piece>::get(&coo);
149 SpriteStore::Token immToken = PieceToken<UltimaPiece>::get(&imm);
150 QImage rookImage = m_data.store->get(rookToken);
151 QImage res = rookImage.transformed(
152 QMatrix(1, 0, 0, -1, 0, rookImage.height()));
153 m_data.store->add(immToken, res);
160 class MoveSerializer<UltimaPosition> {
161 typedef UltimaPosition::Move Move;
164 MoveSerializer(const Move& m, const UltimaPosition& /*ref*/)
167 virtual QString SAN() const { return ""; }
172 struct ComparePosition<UltimaPosition> {
173 static bool apply(const UltimaPosition& /*chessPos*/, const UltimaPosition& /*pos*/) {