Variants are not singletons anymore.
[tagua/yd.git] / src / poolinfo.cpp
blob221e4422eb3d5cffd9b4f65df4d621af851fbb32
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.h"
15 QRegExp PoolInfo::s_pattern("^<b1>\\s+game\\s+(\\d+)" //game num
16 "\\s+white\\s+\\[([QKBNRP]*)\\]" // white pieces
17 "\\s+black\\s+\\[([QKBNRP]*)\\]" // black pieces
18 "(?:\\s+<\\-\\s+([WB][QKBNRP]))?" // added piece
21 PoolInfo::PoolInfo(const std::map<int, ICSGameData>& games, const QString& str)
22 : m_valid(false)
23 , m_pos_index(-1) {
25 // if (s_pattern.indexIn(str) != 0)
26 // return;
27 //
28 // m_game_num = s_pattern.cap(1).toInt();
29 // std::map<int, ICSGameData>::const_iterator gi = games.find(m_game_num);
30 // if (gi == games.end())
31 // return;
32 //
33 // QString var = !gi->second.variant.isEmpty() ? gi->second.variant : QString("chess");
34 // VariantInfo* variant = Variant::variant(GameInfo::variantCode(var));
35 // m_pos_index = gi->second.index;
36 //
37 // m_pool =
38 //BROKEN
39 #if 0
40 if (s_pattern.indexIn(str) != 0)
41 return;
43 m_game_num = s_pattern.cap(1).toInt();
44 std::map<int, ICSGameData>::const_iterator gi = games.find(m_game_num);
46 if(gi == games.end())
47 return;
49 QString var = !gi->second.variant.isEmpty() ? gi->second.variant : QString("chess");
50 VariantInfo* variant = Variant::variant(GameInfo::variantCode(var));
51 m_pos_index = gi->second.index;
53 m_pool = AbstractPosition::PoolPtr(new AbstractPosition::AbstractPool);
54 for(int i=0;i<2;i++) {
55 QString cap = s_pattern.cap(i+2);
56 int color = (i==0) ? WHITE : BLACK;
58 for(int j=0;j<cap.length();j++) {
59 int type = variant->type(cap.at(j));
60 AbstractPiece::Ptr p = variant->createPiece(color, type);
61 (*m_pool)[p]++;
65 QString added = s_pattern.cap(4);
66 if(!added.isEmpty()) {
67 int color = (added.at(0) == 'W') ? WHITE : BLACK;
68 int type = variant->type(added.at(1));
69 m_added_piece = variant->createPiece(color, type);
71 m_valid = true;
72 #endif