Ported verbose deserialization.
[tagua.git] / src / hlvariant / chess / icsverbose.cpp
blobd77f7f498676be4eeaae2dbef2f048d0f7a37514
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 namespace HLVariant {
14 namespace Chess {
16 // 1 2 3 5
17 QRegExp ICSVerbose::pattern("([PRNBKQ])/([a-zA-Z]\\d+|@@)-([a-zA-Z]\\d+)(=([PRNBKQ]))?");
18 QRegExp ICSVerbose::kingCastlingPattern("[oO0]-[oO0]");
19 QRegExp ICSVerbose::queenCastlingPattern("[oO0]-[oO0]-[oO0]");
20 QRegExp ICSVerbose::nonePattern("none");
22 ICSVerbose::ICSVerbose()
23 : from(Point::invalid())
24 , to(Point::invalid())
25 , promotion(-1)
26 , castling(SAN::NoCastling) { }
29 void ICSVerbose::load(const QString& str, int ysize) {
30 if (nonePattern.indexIn(str) == 0) {
31 from = Point::invalid();
32 to = Point::invalid();
34 else if (pattern.indexIn(str) == 0) {
35 if (pattern.cap(2) == "@@")
36 from = Point::invalid();
37 else
38 from = Point(pattern.cap(2), ysize);
40 to = Point(pattern.cap(3), ysize);
42 type = SAN::getType(pattern.cap(1));
43 if (!pattern.cap(5).isEmpty())
44 promotion = SAN::getType(pattern.cap(6));
45 else
46 promotion = -1;
47 castling = SAN::NoCastling;
49 else if (queenCastlingPattern.indexIn(str) == 0)
50 castling = SAN::QueenSide;
51 else if (kingCastlingPattern.indexIn(str) == 0)
52 castling = SAN::KingSide;
53 else {
54 from = Point::invalid();
55 to = Point::invalid();
56 castling = SAN::NoCastling;
60 } // namespace HLVariant
61 } // namespace Chess