Removed AlgebraicNotation from the variant API.
[tagua/yd.git] / src / algebraicnotation.h
blobea6c5472cb90e3e00418258c89fe3747b17e5bb5
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef ALGEBRAICNOTATION_H
12 #define ALGEBRAICNOTATION_H
14 #include <iosfwd>
15 #include "common.h"
16 #include "point.h"
18 class QRegExp;
19 class QString;
21 class AlgebraicNotation {
22 friend std::ostream& operator<<(std::ostream& os, const AlgebraicNotation& move);
24 static QRegExp pattern;
25 static QRegExp kingCastlingPattern;
26 static QRegExp queenCastlingPattern;
27 static QRegExp nonePattern;
28 public:
29 enum CastlingType {
30 NoCastling,
31 KingSide,
32 QueenSide
35 AlgebraicNotation(const QString&, int& offset, int ysize);
36 explicit AlgebraicNotation(const QString&, int ysize);
37 AlgebraicNotation();
39 void init(const QString&, int& offset, int ysize);
41 Point from, to;
42 int type;
43 int promotion;
44 CastlingType castling;
45 bool drop;
47 inline bool invalid() const { return (to == Point::invalid()) && (castling == NoCastling); }
48 inline bool valid() const { return !invalid(); }
51 class VerboseNotation {
52 static QRegExp pattern;
53 static QRegExp kingCastlingPattern;
54 static QRegExp queenCastlingPattern;
55 static QRegExp nonePattern;
57 public:
58 explicit VerboseNotation(const QString&, int ysize);
59 Point from, to;
60 int type, promotion;
61 AlgebraicNotation::CastlingType castling;
62 inline bool invalid() const { return (from == Point::invalid() && to == Point::invalid()); }
63 inline bool valid() const { return !invalid(); }
66 // IMPLEMENTATION
69 #define TRY(x) ref.getMove(x, ok); if (ok) return;
70 template <typename Pos>
71 void minimalNotation(AlgebraicNotation& san, const Pos& ref) {
72 Point from = san.from;
73 san.castling = AlgebraicNotation::NoCastling;
74 bool ok;
76 // try notation without starting point
77 san.from = Point::invalid();
78 TRY(san);
80 // add column indication
81 san.from = Point(from.x, -1);
82 TRY(san);
84 // add row indication
85 san.from = Point(-1, from.y);
86 TRY(san);
88 // add complete starting point
89 san.from = from;
91 #undef TRY
94 #endif // ALGEBRAICNOTATION_H