73 |
history.back()->setPlayedRack(iPld); |
history.back()->setPlayedRack(iPld); |
74 |
} |
} |
75 |
|
|
|
// vector |
|
|
// size : number of elements |
|
|
// back : last element |
|
|
// pop_back : remove at the end |
|
|
// push_back : add at the end |
|
76 |
|
|
77 |
const Turn History::getPreviousTurn() const |
const Turn History::getPreviousTurn() const |
78 |
{ |
{ |
82 |
} |
} |
83 |
|
|
84 |
|
|
85 |
|
const Turn History::getTurn(unsigned int n) const |
86 |
|
{ |
87 |
|
ASSERT(0 <= n && n < history.size(), "Wrong turn number"); |
88 |
|
return *(history[ n ]); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
void History::playRound(int player, int turn, const Round& round) |
void History::playRound(int player, int turn, const Round& round) |
93 |
{ |
{ |
94 |
Rack rack; |
Rack rack; |
95 |
Turn * current_turn; |
Turn * current_turn; |
|
Turn * next_turn; |
|
96 |
|
|
97 |
current_turn = history.back(); |
current_turn = history.back(); |
98 |
|
|
117 |
} |
} |
118 |
|
|
119 |
/* create a new turn */ |
/* create a new turn */ |
120 |
next_turn = new Turn(); |
Turn * next_turn = new Turn(); |
121 |
next_turn->getPlayedRack().setOld(rack); |
PlayedRack pldrack; |
122 |
|
pldrack.setOld(rack); |
123 |
|
next_turn->setPlayedRack(pldrack); |
124 |
history.push_back ( next_turn ); |
history.push_back ( next_turn ); |
125 |
} |
} |
126 |
|
|
151 |
std::string |
std::string |
152 |
History::toString() const |
History::toString() const |
153 |
{ |
{ |
154 |
std::string rs = ""; |
char buff[20]; |
155 |
unsigned int i; |
unsigned int i; |
156 |
|
std::string rs(""); |
157 |
|
#ifdef DEBUG |
158 |
|
sprintf(buff,"%d",history.size()); |
159 |
|
rs = "hitory size = " + std::string(buff) + "\n\n"; |
160 |
|
#endif |
161 |
for ( i = 0; i < history.size(); i++) |
for ( i = 0; i < history.size(); i++) |
162 |
{ |
{ |
163 |
string pr,ro; |
Turn *t = history[i]; |
164 |
pr = history[i]->getPlayedRack().toString(); |
rs += t->toString() + std::string("\n"); |
|
ro = history[i]->getRound().toString(); |
|
|
rs += string(" ") + pr + string(" ") + ro + string("\n"); |
|
165 |
} |
} |
166 |
return rs; |
return rs; |
167 |
} |
} |