Tentative Randomless-Entropy variant.
[tagua/yd.git] / src / poolinfo.cpp
blob01e73c09e9cefd218808d373a3597fe0beb2085b
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
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"
14 QRegExp PoolInfo::s_pattern("^<b1>\\s+game\\s+(\\d+)" //game num
15 "\\s+white\\s+\\[([QKBNRP]*)\\]" // white pieces
16 "\\s+black\\s+\\[([QKBNRP]*)\\]" // black pieces
17 "(?:\\s+<\\-\\s+([WB][QKBNRP]))?" // added piece
20 PoolInfo::PoolInfo(const std::map<int, ICSGameData>& games, const QString& str)
21 : m_valid(false)
22 , m_pos_index(-1) {
24 // if (s_pattern.indexIn(str) != 0)
25 // return;
26 //
27 // m_game_num = s_pattern.cap(1).toInt();
28 // std::map<int, ICSGameData>::const_iterator gi = games.find(m_game_num);
29 // if (gi == games.end())
30 // return;
31 //
32 // QString var = !gi->second.variant.isEmpty() ? gi->second.variant : QString("chess");
33 // VariantInfo* variant = Variant::variant(GameInfo::variantCode(var));
34 // m_pos_index = gi->second.index;
35 //
36 // m_pool =
37 //BROKEN
38 #if 0
39 if (s_pattern.indexIn(str) != 0)
40 return;
42 m_game_num = s_pattern.cap(1).toInt();
43 std::map<int, ICSGameData>::const_iterator gi = games.find(m_game_num);
45 if(gi == games.end())
46 return;
48 QString var = !gi->second.variant.isEmpty() ? gi->second.variant : QString("chess");
49 VariantInfo* variant = Variant::variant(GameInfo::variantCode(var));
50 m_pos_index = gi->second.index;
52 m_pool = AbstractPosition::PoolPtr(new AbstractPosition::AbstractPool);
53 for(int i=0;i<2;i++) {
54 QString cap = s_pattern.cap(i+2);
55 int color = (i==0) ? WHITE : BLACK;
57 for(int j=0;j<cap.length();j++) {
58 int type = variant->type(cap.at(j));
59 AbstractPiece::Ptr p = variant->createPiece(color, type);
60 (*m_pool)[p]++;
64 QString added = s_pattern.cap(4);
65 if(!added.isEmpty()) {
66 int color = (added.at(0) == 'W') ? WHITE : BLACK;
67 int type = variant->type(added.at(1));
68 m_added_piece = variant->createPiece(color, type);
70 m_valid = true;
71 #endif