Saved games: do not support the (very) old format anymore

This commit is contained in:
Olivier Teulière 2012-04-08 19:50:22 +02:00
parent 9f2ea4f340
commit 53adb5d91b
11 changed files with 0 additions and 683 deletions

View file

@ -60,7 +60,6 @@ libgame_a_SOURCES= \
training.cpp training.h \
public_game.cpp public_game.h \
game_factory.cpp game_factory.h \
game_io.cpp \
xml_writer.cpp xml_writer.h \
xml_reader.cpp xml_reader.h

View file

@ -158,19 +158,6 @@ public:
// XXX: not very nice API, should be a player property...
virtual bool hasPlayed(unsigned int player) const { return player != currPlayer(); }
/***************
* Saved games handling
***************/
/**
* XXX FIXME XXX: these methods are deprecated, don't use them anymore.
* load() returns the loaded game, or NULL if there was a problem
* load() does need some more work to be robust enough to
* handle "hand written" files
*/
static Game * load(FILE *fin, const Dictionary &iDic);
static Game * load(const string &iFileName, const Dictionary &iDic);
/***************
* Setting the rack
***************/
@ -295,30 +282,6 @@ protected:
*/
bool rackInBag(const Rack &iRack, const Bag &iBag) const;
/**
* load games from File using the first format.
* This format is used for Training games
*/
static Game* gameLoadFormat_14(FILE *fin, const Dictionary& iDic);
/**
* load games from File using advanced format (since Eliot 1.5)
* This format is used for Duplicate, FreeGame, ...
*/
static Game* gameLoadFormat_15(FILE *fin, const Dictionary& iDic);
#if 0
/**
* Training games ares saved using the initial Eliot format
*/
void gameSaveFormat_14(ostream &out) const;
/**
* Advanced game file format output
*/
void gameSaveFormat_15(ostream &out) const;
#endif
};
#endif /* _GAME_H_ */

View file

@ -1,435 +0,0 @@
/*****************************************************************************
* Eliot
* Copyright (C) 2002-2008 Antoine Fraboulet & Olivier Teulière
* Authors: Antoine Fraboulet <antoine.fraboulet @@ free.fr>
* Olivier Teulière <ipkiss @@ gmail.com>
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#include <cstring>
#include <cstdlib> // For atoi
#include <cwctype> // For iswlower
#include <cstdio>
#include "dic.h"
#include "pldrack.h"
#include "round.h"
#include "turn.h"
#include "player.h"
#include "ai_percent.h"
#include "game_params.h"
#include "game.h"
#include "game_factory.h"
#include "training.h"
#include "freegame.h"
#include "duplicate.h"
#include "encoding.h"
#include "game_exception.h"
#include "game_move_cmd.h"
using namespace std;
/*************************
* Ident string used to identify saved Eliot games
*************************/
#define IDENT_STRING "Eliot"
#define IDENT_FORMAT_14 ""
#define IDENT_FORMAT_15 "1.5"
/********************************************************
*
* Loading games
*
********************************************************/
Game * Game::load(FILE *fin, const Dictionary& iDic)
{
char buff[4096];
// 10d is \012
// 13d is \015
char delim[] = " \t\n\012\015|";
char *token;
// Check characteristic string
if (fgets(buff, sizeof(buff), fin) == NULL)
{
throw GameException("Cannot recognize the first line");
}
if ((token = strtok(buff, delim)) == NULL)
{
throw GameException("The first line is empty");
}
/* checks for IDENT_STRING and file format */
if (string(token) != IDENT_STRING)
{
throw GameException("Invalid identity string: " + string(token));
}
if ((token = strtok(NULL, delim)) == NULL)
{
return Game::gameLoadFormat_14(fin,iDic);
}
if (string(token) == string(IDENT_FORMAT_15))
{
return Game::gameLoadFormat_15(fin,iDic);
}
throw GameException("Unknown format: " + string(token));
}
Game* Game::gameLoadFormat_14(FILE *fin, const Dictionary& iDic)
{
int ret = 0;
int line = 0;
Tile tile;
char buff[4096];
char rack[20];
char word[20];
char pos [5];
char delim[]=" \t\n\012\015";
char *token;
Game *pGame = NULL;
pGame = GameFactory::Instance()->createGame(GameParams(iDic, GameParams::kTRAINING));
pGame->addPlayer(new HumanPlayer);
pGame->start();
/* rack word ?bonus pts coord */
/* EUOFMIE FUMEE * 26 H 4 */
/* read all turns until total */
while (fgets(buff, sizeof(buff), fin))
{
line++;
token = strtok(buff, delim);
if (token != NULL)
{
if (strcmp(token, "total") == 0)
{
break;
}
/* rack */
strncpy(rack, token, sizeof(rack));
static_cast<Training*>(pGame)->setRackManual(false, wfl(rack));
/* word */
token = strtok(NULL, delim);
if (!token || strcmp(token, "total") == 0)
{
break;
}
strncpy(word, token, sizeof(word));
/* bonus */
if ((token = strtok(NULL, delim)) == NULL)
break;
/* points */
if (token[0] == '*')
{
if ((token = strtok(NULL, delim)) == NULL)
break;
}
/* pos 1 */
if ((token = strtok(NULL, delim)) == NULL)
break;
//debug("(%s ", token);
strncpy(pos, token, sizeof(pos));
/* pos 2 */
if ((token = strtok(NULL, delim)) == NULL)
break;
//debug("%s)", token);
strncat(pos, token, sizeof(pos) - strlen(pos) - 1);
if ((ret = pGame->play(wfl(pos), wfl(word))))
{
GameFactory::Instance()->releaseGame(*pGame);
char tmp1[10];
snprintf(tmp1, 10, "%d", ret);
char tmp2[10];
snprintf(tmp2, 10, "%d", ret);
throw GameException("Loading error " + string(tmp1) +
" on line " + string(tmp2));
}
}
}
return pGame;
}
Game* Game::gameLoadFormat_15(FILE *fin, const Dictionary& iDic)
{
Game *pGame = NULL;
char buff[4096];
char *pos;
/*************/
/* Game type */
/*************/
while (fgets(buff, sizeof(buff), fin))
{
// Indication of game type
pos = strstr(buff, "Game type: ");
if (pos != NULL)
{
// No Game object should have been created yet
if (pGame != NULL)
{
delete pGame;
return NULL;
}
// Create the correct Game object
GameParams::GameMode mode;
if (strstr(buff, "Training"))
mode = GameParams::kTRAINING;
else if (strstr(buff, "Free game"))
mode = GameParams::kFREEGAME;
else if (strstr(buff, "Duplicate"))
mode = GameParams::kDUPLICATE;
else if (strstr(buff, "Arbitration"))
mode = GameParams::kARBITRATION;
else
throw GameException("Unknown game type");
pGame = GameFactory::Instance()->createGame(GameParams(iDic, mode));
}
}
/***************/
/* Player List */
/***************/
while (fgets(buff, sizeof(buff), fin))
{
// Players type
pos = strstr(buff, "Player ");
if (pos != NULL)
{
int nb = 0;
char type[20];
if (sscanf(pos, "Player %d: %19s", &nb, type) > 1)
{
if (string(type) == "Human")
{
pGame->addPlayer(new HumanPlayer);
}
else if (string(type) == "Computer")
{
if (pGame->getMode() == GameParams::kTRAINING)
{
break;
}
else
{
pGame->addPlayer(new AIPercent(1));
}
}
else
{
delete pGame;
return NULL;
}
}
}
else if (strstr(buff," N | RACK "))
{
break;
}
}
/*************/
/* Turn list */
/*************/
while (fgets(buff, sizeof(buff), fin))
{
// Skip columns title
if (strstr(buff,"| PTS | P |") != NULL)
{
continue;
}
// Skip columns title
if (strstr(buff, "==") != NULL)
{
continue;
}
if (string(buff) == "\n")
{
continue;
}
int num;
char rack[20];
char tmpWord[20];
char ref[4];
int pts;
unsigned int player;
char bonus = 0;
int res = sscanf(buff, " %2d | %8s | %s | %3s | %3d | %1u | %c",
&num, rack, tmpWord, ref, &pts, &player, &bonus);
if (res < 6)
{
continue;
}
//debug(" %2d | %8s | %s | %3s | %3d | %1d | %c \n",
// num, rack, tmpWord, ref, pts, player, bonus);
// Integrity checks
// TODO: add more checks
if (pts < 0)
{
continue;
}
if (player > pGame->getNPlayers())
{
continue;
}
if (bonus && bonus != '*')
{
continue;
}
// Build a rack for the correct player
PlayedRack pldrack;
if (!iDic.validateLetters(wfl(rack)))
{
throw GameException("Rack invalid for the current dictionary");
}
pldrack.setManual(wfl(rack));
// Build a round
Round round;
round.setPoints(pts);
if (bonus == '*')
round.setBonus(1);
wstring word = wfl(tmpWord);
Tile tile;
if (isalpha(ref[0]))
{
// Horizontal word
round.accessCoord().setDir(Coord::HORIZONTAL);
round.accessCoord().setRow(ref[0] - 'A' + 1);
round.accessCoord().setCol(atoi(ref + 1));
for (unsigned int i = 0; i < word.size(); i++)
{
tile = Tile(word[i]);
if (!pGame->m_board.getTile(round.getCoord().getRow(), round.getCoord().getCol() + i).isEmpty())
{
round.addRightFromBoard(tile);
}
else
{
round.addRightFromRack(tile, iswlower(word[i]));
pGame->m_bag.takeTile((iswlower(word[i])) ? Tile::Joker() : tile);
}
}
}
else
{
// Vertical word
round.accessCoord().setDir(Coord::VERTICAL);
round.accessCoord().setRow(ref[strlen(ref) - 1] - 'A' + 1);
round.accessCoord().setCol(atoi(ref));
for (unsigned int i = 0; i < word.size(); i++)
{
tile = Tile(word[i]);
if (!pGame->m_board.getTile(round.getCoord().getRow() + i, round.getCoord().getCol()).isEmpty())
{
round.addRightFromBoard(tile);
}
else
{
round.addRightFromRack(tile, iswlower(word[i]));
pGame->m_bag.takeTile((iswlower(word[i])) ? Tile::Joker() : tile);
}
}
}
// pGame->m_currPlayer = player;
// // Update the rack for the player
// pGame->m_players[player]->setCurrentRack(pldrack);
// // End the turn for the current player (this creates a new rack)
// pGame->m_players[player]->endTurn(round,num - 1);
// Play the round
GameMoveCmd cmd(*pGame, Move(round), pGame->m_currPlayer);
cmd.execute();
}
/**************************************/
/* End of turn list, switching to ... */
/**************************************/
// Last racks
pos = strstr(buff, "Rack ");
if (pos != NULL && pGame != NULL)
{
int nb = 0;
char letters[20];
if (sscanf(pos, "Rack %d: %19s", &nb, letters) > 1)
{
// Create the played rack
PlayedRack pldrack;
pldrack.setManual(wfl(letters));
// Give the rack to the player
pGame->m_players[nb]->setCurrentRack(pldrack);
}
// Read next line
// continue;
}
// Finalize the game
if (pGame)
{
// We don't really know whose turn it is, but at least we know that
// the game was saved while a human was to play.
for (unsigned int i = 0; i < pGame->getNPlayers(); i++)
{
if (pGame->m_players[i]->isHuman())
{
pGame->m_currPlayer = i;
break;
}
}
}
return pGame;
}

View file

@ -59,33 +59,8 @@ INIT_LOGGER(game, XmlReader);
Game * XmlReader::read(const string &iFileName, const Dictionary &iDic)
{
// Try to load the old format first
LOG_INFO("Parsing savegame '" << iFileName << "'");
try
{
LOG_DEBUG("Trying old format");
FILE *fin = fopen(iFileName.c_str(), "r");
if (fin != NULL)
{
Game *game = Game::load(fin, iDic);
fclose(fin);
if (game != NULL)
{
LOG_INFO("Savegame parsed successfully");
return game;
}
}
}
catch (const GameException &e)
{
// Ignore the exception
LOG_DEBUG("This doesn't look like the old format");
}
LOG_DEBUG("Trying XML format");
ifstream is(iFileName.c_str());
if (!is.is_open())
throw LoadGameException("Cannot open file '" + iFileName + "'");

View file

@ -48,9 +48,6 @@ training_cross3 0
# Search with best word having a joker on the cross-set
training_cross4 0
# Joker problem on game load
training_joker 0
#################
# Duplicate mode
#################
@ -99,8 +96,6 @@ freegame_7among8_variant 20
# Load / Save
##############
# load a standard training game (fumee)
load_game 0
# save and reload a training game, standard format
load_saved_game 0 # randseed unused
# save and load a game combining 2 variants

View file

@ -1,27 +0,0 @@
Eliot
EUOFMIE FUMEE 26 H 4
IO+EOKAN KIMONO 38 6 F
AE+EWTIS WESTIE 49 L 4
A+EAVSLS LAVASSE * 86 10 H
BTUOMEQ LOQUET 63 H 10
BM+UNOSI OMNIBUS * 94 O 4
IOZXEGP EXPIEZ 52 N 10
GO+AETPI TOPAZE 60 15 J
GI+AVNCO VAINCU 28 13 C
GO+ESRAS ESSORAGE * 80 8 A
JEUDIDR JOUR 44 K 5
DDEI+ALY DIALYSE 56 C 3
D+IHUEEB HEU 32 10 B
BDEI+CIL CIEL 25 D 1
BDI+RRA? BRADeRIE * 86 A 1
EUGTDEA DUT 29 M 3
AEEG+LR? CERcLAGE * 80 1 D
TFLATNN JOURNAL 30 K 5
AFNTT+HM MATH 24 D 12
AFNT+NRE FANON 23 I 3
ERT ET 18 I 13
R
total 1023

View file

@ -1,26 +0,0 @@
Eliot
UTEHJDT HUTTE 24 H 4
DJ+NGILE JUNGLE 28 5 G
DI+OBURX DOUX 54 4 L
BIR+EEGI EXIGER 48 O 3
BI+TNE?N oBTIENNE * 80 8 A
AMIEOLE METEO 28 6 F
AIL+NEID ENLAIDIT * 70 C 1
WABFUNO BOEUF 33 1 A
ANW+OALU WON 32 3 K
AALU+PI? MANiPULAI * 69 F 6
ELSUICS CELSIUS * 92 15 C
ETFYUSR FRAYES 44 4 A
TU+DEMNH HAUTE 31 7 E
DMNT+ARA DAMNA 26 9 K
RT+SAIVI SUIVRAIT * 94 11 E
ACAOVEP AVEC 28 12 L
AOP+ARZO CZAR 45 O 12
AOOP+REK POKER 42 14 H
AO+TSTEM MIES 34 9 E
AOTT+LEQ QAT 26 J 10
AELOT+RS VASE 31 M 12
LORT FORET 16 E 1
total 975

View file

@ -1,6 +0,0 @@
c fumee
a g
a l
a p
q
q

View file

@ -1,59 +0,0 @@
Using seed: 0
[?] pour l'aide
commande> c fumee
mode entraînement
[?] pour l'aide
commande> a g
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
A B R A D e R I E - - - - - - -
B - - - - - - - S - H - - - - -
C - - D I A L Y S E E - - V - -
D C I E L - - - O - U - M A T H
E E - - - - - - R - - - - I - -
F R - - - - K - A - - - - N - -
G c - - - - I - G - - - - C - -
H L - - F U M E E - L O Q U E T
I A - F A N O N - - A - - E T -
J G - - - - N - - - V - - - - T
K E - - - J O U R N A L - - - O
L - - - W E S T I E S - - - - P
M - - D U T - - - - S - - - - A
N - - - - - - - - - E X P I E Z
O - - - O M N I B U S - - - - E
commande> a l
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ?
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
commande> a p
Game: player 1 out of 1
Game: mode=Training
Game: history:
N | P | RACK | SOLUTION | REF | PTS | BONUS
===|===|==========|================|=====|=====|======
1 | 0 | EUOFMIE | FUMEE | H4 | 26 |
2 | 0 | IO+EOKAN | KIMONO | 6F | 38 |
3 | 0 | AE+EWTIS | WESTIE | L4 | 49 |
4 | 0 | A+EAVSLS | LAVASSE | 10H | 86 | *
5 | 0 | BTUOMEQ | LOQUET | H10 | 63 |
6 | 0 | BM+UNOSI | OMNIBUS | O4 | 94 | *
7 | 0 | IOZXEGP | EXPIEZ | N10 | 52 |
8 | 0 | GO+AETPI | TOPAZE | 15J | 60 |
9 | 0 | GI+AVNCO | VAINCU | 13C | 28 |
10 | 0 | GO+ESRAS | ESSORAGE | 8A | 80 | *
11 | 0 | JEUDIDR | JOUR | K5 | 44 |
12 | 0 | DDEI+ALY | DIALYSE | C3 | 56 |
13 | 0 | D+IHUEEB | HEU | 10B | 32 |
14 | 0 | BDEI+CIL | CIEL | D1 | 25 |
15 | 0 | BDI+RRA? | BRADeRIE | A1 | 86 | *
16 | 0 | EUGTDEA | DUT | M3 | 29 |
17 | 0 | AEEG+LR? | CERcLAGE | 1D | 80 | *
18 | 0 | TFLATNN | JOURNAL | K5 | 30 |
19 | 0 | AFNTT+HM | MATH | D12 | 24 |
20 | 0 | AFNT+NRE | FANON | I3 | 23 |
21 | 0 | ERT | ET | I13 | 18 |
Rack 0: R
Score 0: 1023
commande> q
fin du mode entraînement
commande> q

View file

@ -1,5 +0,0 @@
c hutte
a g
a p
q
q

View file

@ -1,57 +0,0 @@
Using seed: 0
[?] pour l'aide
commande> c hutte
mode entraînement
[?] pour l'aide
commande> a g
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
A B - - F - - - o - - - - - - -
B O - - R - - - B - - - - - - -
C E N L A I D I T - - - - - - C
D U - - Y - - - I - - - - - - E
E F O R E T - H E M - S - - - L
F - - - S - M A N i P U L A I S
G - - - - J E U N E - I - - - I
H - - - H U T T E S - V - - P U
I - - - - N E E - - - R - - O S
J - - - - G O - - - Q A T - K -
K - - W - L - - - D - I - - E -
L - - O D E - - - A - T A - R -
M - - N O - - - - M - - V A S E
N - - - U - - - - N - - E - - -
O - - E X I G E R A - - C Z A R
commande> a p
Game: player 1 out of 1
Game: mode=Training
Game: history:
N | P | RACK | SOLUTION | REF | PTS | BONUS
===|===|==========|================|=====|=====|======
1 | 0 | UTEHJDT | HUTTE | H4 | 24 |
2 | 0 | DJ+NGILE | JUNGLE | 5G | 28 |
3 | 0 | DI+OBURX | DOUX | 4L | 54 |
4 | 0 | BIR+EEGI | EXIGER | O3 | 48 |
5 | 0 | BI+TNE?N | oBTIENNE | 8A | 80 | *
6 | 0 | AMIEOLE | METEO | 6F | 28 |
7 | 0 | AIL+NEID | ENLAIDIT | C1 | 70 | *
8 | 0 | WABFUNO | BOEUF | 1A | 33 |
9 | 0 | ANW+OALU | WON | 3K | 32 |
10 | 0 | AALU+PI? | MANiPULAI | F6 | 69 | *
11 | 0 | ELSUICS | CELSIUS | 15C | 92 | *
12 | 0 | ETFYUSR | FRAYES | 4A | 44 |
13 | 0 | TU+DEMNH | HAUTE | 7E | 31 |
14 | 0 | DMNT+ARA | DAMNA | 9K | 26 |
15 | 0 | RT+SAIVI | SUIVRAIT | 11E | 94 | *
16 | 0 | ACAOVEP | AVEC | 12L | 28 |
17 | 0 | AOP+ARZO | CZAR | O12 | 45 |
18 | 0 | AOOP+REK | POKER | 14H | 42 |
19 | 0 | AO+TSTEM | MIES | 9E | 34 |
20 | 0 | AOTT+LEQ | QAT | J10 | 26 |
21 | 0 | AELOT+RS | VASE | M12 | 31 |
22 | 0 | LORT | FORET | E1 | 16 |
Rack 0: L
Score 0: 975
commande> q
fin du mode entraînement
commande> q