2005-02-05 12:14:56 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (C) 1999-2005 Eliot
|
|
|
|
* Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
|
|
|
|
* Olivier Teuliere <ipkiss@via.ecp.fr>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-23 16:53:42 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-02-05 12:14:56 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-11-22 14:09:28 +01:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
#include <iomanip>
|
2005-02-26 23:57:34 +01:00
|
|
|
#include <string>
|
2008-01-08 14:52:32 +01:00
|
|
|
#include <stdlib.h>
|
2005-02-05 12:14:56 +01:00
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
#include <dic.h>
|
2005-02-26 23:57:34 +01:00
|
|
|
#include "game_io.h"
|
2008-11-30 21:53:44 +01:00
|
|
|
#include "public_game.h"
|
|
|
|
#include "bag.h"
|
|
|
|
#include "board.h"
|
|
|
|
#include "results.h"
|
2005-11-05 16:48:59 +01:00
|
|
|
#include "player.h"
|
2006-01-22 13:23:52 +01:00
|
|
|
#include "encoding.h"
|
2005-02-05 12:14:56 +01:00
|
|
|
|
2005-02-26 23:57:34 +01:00
|
|
|
using namespace std;
|
2005-02-05 12:14:56 +01:00
|
|
|
|
2007-08-04 22:01:27 +02:00
|
|
|
#define __UNUSED__ __attribute__((unused))
|
2005-02-26 23:57:34 +01:00
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printBoard(ostream &out, const PublicGame &iGame)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
|
|
|
int row, col;
|
|
|
|
|
|
|
|
out << " ";
|
|
|
|
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
|
|
|
|
out << setw(3) << col - BOARD_MIN + 1;
|
|
|
|
out << endl;
|
|
|
|
for (row = BOARD_MIN; row <= BOARD_MAX; row++)
|
|
|
|
{
|
|
|
|
out << " " << (char)(row - BOARD_MIN + 'A') << " ";
|
|
|
|
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
wchar_t l = iGame.getBoard().getChar(row, col);
|
|
|
|
if (l == 0)
|
|
|
|
out << " -";
|
|
|
|
else
|
|
|
|
out << padAndConvert(wstring(1, l), 3);
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
out << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-05 14:27:49 +01:00
|
|
|
/* this mode is used for regression tests */
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printBoardDebug(ostream &out, const PublicGame &iGame)
|
2006-11-05 14:27:49 +01:00
|
|
|
{
|
|
|
|
int row, col;
|
|
|
|
|
|
|
|
/* first printf row cell contents */
|
|
|
|
for (row = BOARD_MIN; row <= BOARD_MAX; row++)
|
|
|
|
{
|
|
|
|
out << " " << (char)(row - BOARD_MIN + 'A') << "r ";
|
|
|
|
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
out << iGame.getBoard().getCellContent_row(row, col);
|
2006-11-05 14:27:49 +01:00
|
|
|
}
|
|
|
|
out << endl;
|
|
|
|
}
|
|
|
|
out << " -" << endl;
|
|
|
|
for (row = BOARD_MIN; row <= BOARD_MAX; row++)
|
|
|
|
{
|
|
|
|
out << " " << (char)(row - BOARD_MIN + 'A') << "c ";
|
|
|
|
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
out << iGame.getBoard().getCellContent_col(row, col);
|
2006-11-05 14:27:49 +01:00
|
|
|
}
|
|
|
|
out << endl;
|
|
|
|
}
|
|
|
|
}
|
2005-02-05 12:14:56 +01:00
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printBoardJoker(ostream &out, const PublicGame &iGame)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
|
|
|
int row,col;
|
|
|
|
|
|
|
|
out << " ";
|
|
|
|
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
|
|
|
|
out << setw(3) << col - BOARD_MIN + 1;
|
|
|
|
out << endl;
|
|
|
|
|
|
|
|
for (row = BOARD_MIN; row <= BOARD_MAX; row++)
|
|
|
|
{
|
|
|
|
out << " " << (char)(row - BOARD_MIN + 'A') << " ";
|
|
|
|
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
wchar_t l = iGame.getBoard().getChar(row, col);
|
2009-06-23 14:56:40 +02:00
|
|
|
bool j = iGame.getBoard().isJoker(row, col);
|
2005-02-05 12:14:56 +01:00
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
if (l == 0)
|
|
|
|
out << " " << (j ? "." : "--");
|
|
|
|
else
|
|
|
|
out << " " << (j ? "." : " ") << convertToMb(l);
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
out << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printBoardMultipliers(ostream &out, const PublicGame &iGame)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
|
|
|
int row, col;
|
|
|
|
|
|
|
|
out << " ";
|
|
|
|
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
|
|
|
|
out << setw(3) << col - BOARD_MIN + 1;
|
|
|
|
out << endl;
|
|
|
|
|
|
|
|
for (row = BOARD_MIN; row <= BOARD_MAX; row++)
|
|
|
|
{
|
|
|
|
out << " " << (char)(row - BOARD_MIN + 'A') << " ";
|
|
|
|
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
wchar_t l = iGame.getBoard().getChar(row, col);
|
2005-02-05 12:14:56 +01:00
|
|
|
if (l != 0)
|
2008-01-08 14:52:32 +01:00
|
|
|
out << padAndConvert(wstring(1, l), 3);
|
2005-02-05 12:14:56 +01:00
|
|
|
else
|
|
|
|
{
|
2008-01-09 11:48:19 +01:00
|
|
|
int wm = iGame.getBoard().GetWordMultiplier(row, col);
|
|
|
|
int tm = iGame.getBoard().GetLetterMultiplier(row, col);
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
if (wm > 1)
|
|
|
|
out << " " << ((wm == 3) ? '@' : '#');
|
|
|
|
else if (tm > 1)
|
|
|
|
out << " " << ((tm == 3) ? '*' : '+');
|
|
|
|
else
|
|
|
|
out << " -";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printBoardMultipliers2(ostream &out, const PublicGame &iGame)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
|
|
|
int row, col;
|
|
|
|
|
|
|
|
out << " ";
|
|
|
|
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
|
|
|
|
out << setw(3) << col - BOARD_MIN + 1;
|
|
|
|
out << endl;
|
|
|
|
|
|
|
|
for (row = BOARD_MIN; row <= BOARD_MAX; row++)
|
|
|
|
{
|
|
|
|
out << " " << (char)(row - BOARD_MIN + 'A') << " ";
|
|
|
|
for (col = BOARD_MIN; col <= BOARD_MAX; col++)
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
wchar_t l = iGame.getBoard().getChar(row, col);
|
2008-01-09 11:48:19 +01:00
|
|
|
int wm = iGame.getBoard().GetWordMultiplier(row, col);
|
|
|
|
int tm = iGame.getBoard().GetLetterMultiplier(row, col);
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
if (wm > 1)
|
|
|
|
out << " " << ((wm == 3) ? '@' : '#');
|
|
|
|
else if (tm > 1)
|
|
|
|
out << " " << ((tm == 3) ? '*' : '+');
|
|
|
|
else
|
|
|
|
out << " -";
|
2006-01-22 13:23:52 +01:00
|
|
|
out << (l ? convertToMb(l) : "-");
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
out << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printNonPlayed(ostream &out, const PublicGame &iGame)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2008-11-22 14:09:28 +01:00
|
|
|
const Bag &bag = iGame.getBag();
|
|
|
|
BOOST_FOREACH(const Tile &tile, iGame.getDic().getAllTiles())
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2008-11-22 14:09:28 +01:00
|
|
|
if (bag.in(tile) > 9)
|
2005-02-05 12:14:56 +01:00
|
|
|
out << " ";
|
2009-06-23 14:41:53 +02:00
|
|
|
out << setw(2) << convertToMb(tile.getDisplayStr());
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
out << endl;
|
|
|
|
|
2008-11-22 14:09:28 +01:00
|
|
|
BOOST_FOREACH(const Tile &tile, iGame.getDic().getAllTiles())
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2008-11-22 14:09:28 +01:00
|
|
|
out << " " << bag.in(tile);
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
out << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printPlayedRack(ostream &out, const PublicGame &iGame, int __UNUSED__ n)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
out << convertToMb(iGame.getCurrentPlayer().getCurrentRack().toString(PlayedRack::RACK_SIMPLE)) << endl;
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printAllRacks(ostream &out, const PublicGame &iGame)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2008-11-30 21:53:44 +01:00
|
|
|
for (unsigned int j = 0; j < iGame.getNbPlayers(); j++)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
|
|
|
out << "Joueur " << j << ": ";
|
2006-01-22 13:23:52 +01:00
|
|
|
out << convertToMb(iGame.getPlayer(j).getCurrentRack().toString(PlayedRack::RACK_SIMPLE)) << endl;
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
static void searchResultLine(ostream &out, const Results &iResults, int num)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2008-11-30 21:53:44 +01:00
|
|
|
const Round &r = iResults.get(num);
|
|
|
|
const wstring &word = r.getWord();
|
2005-02-05 12:14:56 +01:00
|
|
|
if (word.size() == 0)
|
|
|
|
return;
|
2006-01-22 13:23:52 +01:00
|
|
|
out << convertToMb(word) << string(16 - word.size(), ' ')
|
2005-12-27 00:35:03 +01:00
|
|
|
<< (r.getBonus() ? '*' : ' ')
|
|
|
|
<< setw(4) << r.getPoints()
|
2006-01-22 13:23:52 +01:00
|
|
|
<< ' ' << convertToMb(r.getCoord().toString());
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printSearchResults(ostream &out, const Results &iResults, int num)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2008-11-30 21:53:44 +01:00
|
|
|
for (int i = 0; i < num && i < (int)iResults.size(); i++)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
|
|
|
out << setw(3) << i + 1 << ": ";
|
2008-11-30 21:53:44 +01:00
|
|
|
searchResultLine(out, iResults, i);
|
2005-02-05 12:14:56 +01:00
|
|
|
out << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printPoints(ostream &out, const PublicGame &iGame)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2005-11-05 16:48:59 +01:00
|
|
|
out << iGame.getPlayer(0).getPoints() << endl;
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printAllPoints(ostream &out, const PublicGame &iGame)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2008-11-30 21:53:44 +01:00
|
|
|
for (unsigned int i = 0; i < iGame.getNbPlayers(); i++)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
|
|
|
out << "Joueur " << i << ": "
|
2005-11-05 16:48:59 +01:00
|
|
|
<< setw(4) << iGame.getPlayer(i).getPoints() << endl;
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-05 14:27:49 +01:00
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void GameIO::printGameDebug(ostream &out, const PublicGame &iGame)
|
2006-11-05 14:27:49 +01:00
|
|
|
{
|
2008-11-30 21:53:44 +01:00
|
|
|
out << "Game:: joueur en cours " << iGame.getCurrentPlayer().getId()
|
|
|
|
<< " sur " << iGame.getNbPlayers() << endl;
|
2008-01-08 14:52:32 +01:00
|
|
|
out << "Game:: mode " << iGame.getModeAsString() << endl;
|
|
|
|
out << "Game:: variante ";
|
|
|
|
switch (iGame.getVariant())
|
2006-11-05 14:27:49 +01:00
|
|
|
{
|
2008-11-30 21:53:44 +01:00
|
|
|
case PublicGame::kNONE:
|
2008-01-08 14:52:32 +01:00
|
|
|
out << "aucune" << endl;
|
|
|
|
break;
|
2008-11-30 21:53:44 +01:00
|
|
|
case PublicGame::kJOKER:
|
2008-01-08 14:52:32 +01:00
|
|
|
out << "joker" << endl;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
out << "inconnu" << endl;
|
|
|
|
break;
|
2006-11-05 14:27:49 +01:00
|
|
|
}
|
2008-01-08 14:52:32 +01:00
|
|
|
out << "Game:: history --" << endl;
|
|
|
|
out << convertToMb(iGame.getHistory().toString());
|
|
|
|
out << "--" << endl;
|
|
|
|
out << "" << endl;
|
2006-11-05 14:27:49 +01:00
|
|
|
}
|