29 |
#include "ai_percent.h" |
#include "ai_percent.h" |
30 |
#include "game.h" |
#include "game.h" |
31 |
#include "game_factory.h" |
#include "game_factory.h" |
32 |
|
#include "turn.h" |
33 |
|
|
34 |
#include "debug.h" |
#include "debug.h" |
35 |
|
|
49 |
|
|
50 |
Game::~Game() |
Game::~Game() |
51 |
{ |
{ |
52 |
for (unsigned int i = 0; i < m_roundHistory.size(); i++) |
for (unsigned int i = 0; i < m_history.size(); i++) |
53 |
{ |
{ |
54 |
delete m_roundHistory[i]; |
delete m_history[i]; |
|
} |
|
|
for (unsigned int i = 0; i < m_rackHistory.size(); i++) |
|
|
{ |
|
|
delete m_rackHistory[i]; |
|
55 |
} |
} |
56 |
for (int i = 0; i < getNPlayers(); i++) |
for (int i = 0; i < getNPlayers(); i++) |
57 |
{ |
{ |
305 |
out << decal << "===|==========|=================|=====|=====|===|======" << endl; |
out << decal << "===|==========|=================|=====|=====|===|======" << endl; |
306 |
|
|
307 |
// Print the game itself |
// Print the game itself |
308 |
for (int i = 0; i < getNRounds(); i++) |
for (int i = 0; i < getNTurns(); i++) |
309 |
{ |
{ |
310 |
string word = getPlayedWord(i); |
string word = getPlayedWord(i); |
311 |
string coord = getPlayedCoords(i); |
string coord = getPlayedCoords(i); |
340 |
*/ |
*/ |
341 |
|
|
342 |
// History of the game |
// History of the game |
343 |
m_roundHistory.push_back(new Round(iRound)); |
m_history.push_back(new Turn(m_history.size(), m_currPlayer, |
344 |
m_rackHistory.push_back(new PlayedRack(m_players[m_currPlayer]->getLastRack())); |
m_players[m_currPlayer]->getLastRack(), |
345 |
m_playerHistory.push_back(m_currPlayer); |
iRound)); |
346 |
|
|
347 |
m_points += iRound.getPoints(); |
m_points += iRound.getPoints(); |
348 |
|
|
423 |
|
|
424 |
for (i = 0; i < n; i++) |
for (i = 0; i < n; i++) |
425 |
{ |
{ |
426 |
if (m_roundHistory.size()) |
if (m_history.size()) |
427 |
{ |
{ |
428 |
prevPlayer(); |
prevPlayer(); |
429 |
player = m_players[m_currPlayer]; |
player = m_players[m_currPlayer]; |
430 |
const Round &lastround = *m_roundHistory.back(); |
const Round &lastround = m_history.back()->getRound(); |
431 |
|
|
432 |
/* Remove the points of this round */ |
/* Remove the points of this round */ |
433 |
player->addPoints(- lastround.getPoints()); |
player->addPoints(- lastround.getPoints()); |
446 |
} |
} |
447 |
} |
} |
448 |
delete &lastround; |
delete &lastround; |
449 |
m_roundHistory.pop_back(); |
m_history.pop_back(); |
|
m_playerHistory.pop_back(); |
|
450 |
} |
} |
451 |
else |
else |
452 |
{ |
{ |
563 |
} |
} |
564 |
// 2 vowels and 2 consonants are needed up to the 15th turn |
// 2 vowels and 2 consonants are needed up to the 15th turn |
565 |
if (bag.nVowels() > 1 && bag.nConsonants() > 1 |
if (bag.nVowels() > 1 && bag.nConsonants() > 1 |
566 |
&& getNRounds() < 15) |
&& getNTurns() < 15) |
567 |
min = 2; |
min = 2; |
568 |
else |
else |
569 |
min = 1; |
min = 1; |
693 |
if (iCheck) |
if (iCheck) |
694 |
{ |
{ |
695 |
if (m_bag.nVowels() > 1 && m_bag.nConsonants() > 1 |
if (m_bag.nVowels() > 1 && m_bag.nConsonants() > 1 |
696 |
&& getNRounds() < 15) |
&& getNTurns() < 15) |
697 |
min = 2; |
min = 2; |
698 |
else |
else |
699 |
min = 1; |
min = 1; |
711 |
|
|
712 |
string Game::getPlayedRack(int num) const |
string Game::getPlayedRack(int num) const |
713 |
{ |
{ |
714 |
ASSERT(0 <= num && num < getNRounds(), "Wrong turn number"); |
ASSERT(0 <= num && num < getNTurns(), "Wrong turn number"); |
715 |
return m_rackHistory[num]->toString(); |
return m_history[num]->getPlayedRack().toString(); |
716 |
} |
} |
717 |
|
|
718 |
|
|
719 |
string Game::getPlayedWord(int num) const |
string Game::getPlayedWord(int num) const |
720 |
{ |
{ |
721 |
ASSERT(0 <= num && num < getNRounds(), "Wrong turn number"); |
ASSERT(0 <= num && num < getNTurns(), "Wrong turn number"); |
722 |
char c; |
char c; |
723 |
string s; |
string s; |
724 |
const Round &r = *m_roundHistory[num]; |
const Round &r = m_history[num]->getRound(); |
725 |
for (int i = 0; i < r.getWordLen(); i++) |
for (int i = 0; i < r.getWordLen(); i++) |
726 |
{ |
{ |
727 |
c = r.getTile(i).toChar(); |
c = r.getTile(i).toChar(); |
735 |
|
|
736 |
string Game::getPlayedCoords(int num) const |
string Game::getPlayedCoords(int num) const |
737 |
{ |
{ |
738 |
ASSERT(0 <= num && num < getNRounds(), "Wrong turn number"); |
ASSERT(0 <= num && num < getNTurns(), "Wrong turn number"); |
739 |
return m_roundHistory[num]->getCoord().toString(); |
return m_history[num]->getRound().getCoord().toString(); |
740 |
} |
} |
741 |
|
|
742 |
|
|
743 |
int Game::getPlayedPoints(int num) const |
int Game::getPlayedPoints(int num) const |
744 |
{ |
{ |
745 |
ASSERT(0 <= num && num < getNRounds(), "Wrong turn number"); |
ASSERT(0 <= num && num < getNTurns(), "Wrong turn number"); |
746 |
return m_roundHistory[num]->getPoints(); |
return m_history[num]->getRound().getPoints(); |
747 |
} |
} |
748 |
|
|
749 |
|
|
750 |
int Game::getPlayedBonus(int num) const |
int Game::getPlayedBonus(int num) const |
751 |
{ |
{ |
752 |
ASSERT(0 <= num && num < getNRounds(), "Wrong turn number"); |
ASSERT(0 <= num && num < getNTurns(), "Wrong turn number"); |
753 |
return m_roundHistory[num]->getBonus(); |
return m_history[num]->getRound().getBonus(); |
754 |
} |
} |
755 |
|
|
756 |
|
|
757 |
int Game::getPlayedPlayer(int num) const |
int Game::getPlayedPlayer(int num) const |
758 |
{ |
{ |
759 |
ASSERT(0 <= num && num < getNRounds(), "Wrong turn number"); |
ASSERT(0 <= num && num < getNTurns(), "Wrong turn number"); |
760 |
return m_playerHistory[num]; |
return m_history[num]->getPlayer(); |
761 |
} |
} |
762 |
|
|
763 |
/********************************************************* |
/********************************************************* |
866 |
|
|
867 |
/* Check the word position, compute its points, |
/* Check the word position, compute its points, |
868 |
* and specify the origin of each letter (board or rack) */ |
* and specify the origin of each letter (board or rack) */ |
869 |
res = m_board.checkRound(oRound, getNRounds() == 0); |
res = m_board.checkRound(oRound, getNTurns() == 0); |
870 |
if (res != 0) |
if (res != 0) |
871 |
return res + 4; |
return res + 4; |
872 |
|
|