Fix Shogi::Piece::OppositeColor.
[tagua/yd.git] / src / poolinfo.cpp
blobe90d159d3e3a97b886828d4e547fd15b0813f864
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 #include "poolinfo.h"
12 #include "gameinfo.h"
13 #include "variants/chess.h"
14 #include "variants/variants.h"
16 QRegExp PoolInfo::s_pattern("^<b1>\\s+game\\s+(\\d+)" //game num
17 "\\s+white\\s+\\[([QKBNRP]*)\\]" // white pieces
18 "\\s+black\\s+\\[([QKBNRP]*)\\]" // black pieces
19 "(?:\\s+<\\-\\s+([WB][QKBNRP]))?" // added piece
22 PoolInfo::PoolInfo(const std::map<int, ICSGameData>& games, const QString& str)
23 : m_valid(false)
24 , m_pos_index(-1) {
26 // if (s_pattern.indexIn(str) != 0)
27 // return;
28 //
29 // m_game_num = s_pattern.cap(1).toInt();
30 // std::map<int, ICSGameData>::const_iterator gi = games.find(m_game_num);
31 // if (gi == games.end())
32 // return;
33 //
34 // QString var = !gi->second.variant.isEmpty() ? gi->second.variant : QString("chess");
35 // VariantInfo* variant = Variant::variant(GameInfo::variantCode(var));
36 // m_pos_index = gi->second.index;
37 //
38 // m_pool =
39 //BROKEN
40 #if 0
41 if (s_pattern.indexIn(str) != 0)
42 return;
44 m_game_num = s_pattern.cap(1).toInt();
45 std::map<int, ICSGameData>::const_iterator gi = games.find(m_game_num);
47 if(gi == games.end())
48 return;
50 QString var = !gi->second.variant.isEmpty() ? gi->second.variant : QString("chess");
51 VariantInfo* variant = Variant::variant(GameInfo::variantCode(var));
52 m_pos_index = gi->second.index;
54 m_pool = AbstractPosition::PoolPtr(new AbstractPosition::AbstractPool);
55 for(int i=0;i<2;i++) {
56 QString cap = s_pattern.cap(i+2);
57 int color = (i==0) ? WHITE : BLACK;
59 for(int j=0;j<cap.length();j++) {
60 int type = variant->type(cap.at(j));
61 AbstractPiece::Ptr p = variant->createPiece(color, type);
62 (*m_pool)[p]++;
66 QString added = s_pattern.cap(4);
67 if(!added.isEmpty()) {
68 int color = (added.at(0) == 'W') ? WHITE : BLACK;
69 int type = variant->type(added.at(1));
70 m_added_piece = variant->createPiece(color, type);
72 m_valid = true;
73 #endif