push 98438d20051787465e7a05f4aa66ab452afb1c14
[tagua/yd.git] / src / variants / chess / icsverbose.cpp
blob7d65f2b97fcb2274f62477d652b7bcec88cc613a
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2007 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 #include "icsverbose.h"
13 // 1 2 3 5
14 QRegExp ICSVerbose::pattern("([PRNBKQ])/([a-zA-Z]\\d+|@@)-([a-zA-Z]\\d+)(=([PRNBKQ]))?");
15 QRegExp ICSVerbose::kingCastlingPattern("[oO0]-[oO0]");
16 QRegExp ICSVerbose::queenCastlingPattern("[oO0]-[oO0]-[oO0]");
17 QRegExp ICSVerbose::nonePattern("none");
19 ICSVerbose::ICSVerbose()
20 : src(Point::invalid())
21 , dst(Point::invalid())
22 , promotion(0)
23 , castling(SAN::NoCastling) { }
26 void ICSVerbose::load(const QString& str, int ysize) {
27 if (nonePattern.indexIn(str) == 0) {
28 src = Point::invalid();
29 dst = Point::invalid();
31 else if (pattern.indexIn(str) == 0) {
32 if (pattern.cap(2) == "@@")
33 src = Point::invalid();
34 else
35 src = Point(pattern.cap(2), ysize);
37 dst = Point(pattern.cap(3), ysize);
39 type = SAN::getType(pattern.cap(1));
40 if (!pattern.cap(5).isEmpty())
41 promotion = SAN::getType(pattern.cap(6));
42 else
43 promotion = 0;
44 castling = SAN::NoCastling;
46 else if (queenCastlingPattern.indexIn(str) == 0)
47 castling = SAN::QueenSide;
48 else if (kingCastlingPattern.indexIn(str) == 0)
49 castling = SAN::KingSide;
50 else {
51 src = Point::invalid();
52 dst = Point::invalid();
53 castling = SAN::NoCastling;