File: PentobiTreeWriter.cpp

package info (click to toggle)
pentobi 29.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,892 kB
  • sloc: cpp: 25,719; javascript: 875; xml: 40; makefile: 13; sh: 6
file content (74 lines) | stat: -rw-r--r-- 2,500 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//-----------------------------------------------------------------------------
/** @file libpentobi_base/PentobiTreeWriter.cpp
    @author Markus Enzenberger
    @copyright GNU General Public License version 3 or later */
//-----------------------------------------------------------------------------

#include "PentobiTreeWriter.h"

namespace libpentobi_base {

//-----------------------------------------------------------------------------

PentobiTreeWriter::PentobiTreeWriter(ostream& out, const PentobiTree& tree)
    : libboardgame_base::TreeWriter(out, tree.get_root()),
      m_variant(tree.get_variant())
{
}

void PentobiTreeWriter::write_property(const string& id,
                                       const vector<string>& values)
{
    auto nu_colors = get_nu_colors(m_variant);
    // Replace obsolete move property IDs or multi-valued move properties
    // as used by early versions of Pentobi
    if (id == "BLUE" || id == "YELLOW" || id == "GREEN" || id == "RED"
        || ((id == "1" || id == "2" || id == "3" || id == "4" || id == "B"
             || id == "W")
            && values.size() > 1))
    {
        string new_id;
        if (id == "BLUE")
            new_id = (nu_colors == 2 ? "B" : "1");
        else if (id == "YELLOW")
            new_id = "2";
        else if (id == "GREEN")
            new_id = (nu_colors == 2 ? "W" : "4");
        else if (id == "RED")
            new_id = "3";
        else
            new_id = id;
        if (values.size() < 2)
            libboardgame_base::TreeWriter::write_property(new_id, values);
        else
        {
            string val = values[0];
            for (size_t i = 1; i < values.size(); ++i)
                val += "," + values[i];
            vector<string> new_values;
            new_values.push_back(val);
            libboardgame_base::TreeWriter::write_property(new_id, new_values);
        }
        return;
    }
    // Pentobi 12.0 versions erroneously used multi-player properties for
    // two-player Callisto.
    if (nu_colors == 2)
    {
        if (id == "1")
        {
            libboardgame_base::TreeWriter::write_property("B", values);
            return;
        }
        if (id == "2")
        {
            libboardgame_base::TreeWriter::write_property("W", values);
            return;
        }
    }
    libboardgame_base::TreeWriter::write_property(id, values);
}

//-----------------------------------------------------------------------------

} // namespace libpentobi_base