-
Notifications
You must be signed in to change notification settings - Fork 0
/
rearrange.cpp
130 lines (123 loc) · 2.52 KB
/
rearrange.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "db.h"
#include "dbUtils.h"
//#include <boost/algorithm/string.hpp>
//#include <boost/serialization/singleton.hpp> // has nothing to do with s11n
//
//#include <boost/lexical_cast.hpp>
//#include <boost/filesystem.hpp>
//#include <boost/filesystem/fstream.hpp>
//#include <boost/foreach.hpp>
//
//#include <boost/bind.hpp>
//#include <boost/ref.hpp>
//
//#include <boost/assign.hpp>
//using namespace boost::assign;
//
//namespace fs = boost::filesystem;
//
//#include <boost/scoped_ptr.hpp>
#include <iostream>
#include <sstream>
#include <string>
bool FixDeck(Game &g, std::deque<int> &cards)
{
int d = cards[0];
cards.pop_front();
Deck deck;
Hand discard;
for(int i = 0; i < cards.size(); i++)
{
deck.push_back(g._decks[d][cards[i]]);
}
for(int i = 0; i < g._decks[d].size(); i++)
{
if (std::find(cards.begin(), cards.end(), i) == cards.end())
{
std::cout << "Discarding " << i << " " << g._decks[d][i]->_name << std::endl;
discard.insert(g._decks[d][i]);
}
}
g._decks[d] = deck;
g._discards[d].insert(discard.begin(), discard.end());
return true;
}
int main(int argc, char *argv[])
{
std::string cmd(argv[0]);
std::cout << cmd << std::endl;
if (argc != 2)
{
std::cerr << argv[0] << " dbName" << std::endl;
return ErrQuit;
}
Game g(argv[1]);
while(std::cin.good())
{
std::string line;
std::cout << "> ";
std::getline(std::cin, line);
if (line.size())
{
if (line[0] == 'p')
{
std::stringstream ss(line);
char c;
ss >> c;
if (line.size() == 2)
{
int deck = line[1]-'0';
if (deck > 9)
{
deck = line[1]-'a'+1;
std::cout << deck << std::endl;
if (deck > 9)
continue;
for(auto i = g._discards[deck].begin(); i != g._discards[deck].end(); i++)
{
std::cout << (*i)->_name << std::endl;
}
}
else
for(int i = 0; i < g._decks[deck].size(); i++)
{
std::cout << i << '\t' << g._decks[deck][i]->_name << std::endl;
}
}
}
if (line[0] == 'r')
{
if (line.size() > 2)
{
std::stringstream ss(line);
char c;
ss >> c;
std::deque<int> cards;
while(ss.good())
{
int v = -1;
ss >> v;
if (v > -1 || ss.good())
cards.push_back(v);
}
if (!FixDeck(g, cards))
{
g.Abandon();
std::cerr << "I can't understand you, collapsing\n";
return ErrQuit;
}
}
}
if (line[0] == 'q')
{
return ErrQuit;
}
if (line[0] == 'a')
{
g.Abandon();
return ErrQuit;
}
}
}
return ErrNone;
}