2005-02-05 12:14:56 +01:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* Copyright (C) 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
|
|
|
|
*****************************************************************************/
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <wchar.h>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <iostream>
|
2004-04-08 11:43:06 +02:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <string.h>
|
2006-01-22 13:23:52 +01:00
|
|
|
|
#include <locale.h>
|
|
|
|
|
#include <wctype.h>
|
2008-01-08 14:52:32 +01:00
|
|
|
|
#if HAVE_READLINE_READLINE_H
|
|
|
|
|
# include <stdio.h>
|
|
|
|
|
# include <readline/readline.h>
|
|
|
|
|
# include <readline/history.h>
|
|
|
|
|
#endif
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
|
|
|
|
#include "dic.h"
|
2008-08-31 13:48:11 +02:00
|
|
|
|
#include "dic_exception.h"
|
2005-02-26 23:57:34 +01:00
|
|
|
|
#include "game_io.h"
|
2005-02-24 09:06:24 +01:00
|
|
|
|
#include "game_factory.h"
|
2005-02-05 12:14:56 +01:00
|
|
|
|
#include "training.h"
|
|
|
|
|
#include "duplicate.h"
|
|
|
|
|
#include "freegame.h"
|
2008-01-28 20:17:33 +01:00
|
|
|
|
#include "player.h"
|
|
|
|
|
#include "ai_percent.h"
|
2006-01-22 13:23:52 +01:00
|
|
|
|
#include "encoding.h"
|
2008-09-13 23:32:45 +02:00
|
|
|
|
#include "game_exception.h"
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2005-04-27 19:55:32 +02:00
|
|
|
|
/* A static variable for holding the line. */
|
2006-01-22 13:23:52 +01:00
|
|
|
|
static wchar_t *wline_read = NULL;
|
2005-04-27 19:55:32 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read a string, and return a pointer to it.
|
|
|
|
|
* Returns NULL on EOF.
|
|
|
|
|
*/
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *rl_gets()
|
2005-04-27 19:55:32 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
#if HAVE_READLINE_READLINE_H
|
2005-04-27 19:55:32 +02:00
|
|
|
|
// If the buffer has already been allocated, return the memory to the free
|
|
|
|
|
// pool
|
2006-01-22 13:23:52 +01:00
|
|
|
|
if (wline_read)
|
|
|
|
|
{
|
2006-01-29 13:40:49 +01:00
|
|
|
|
delete[] wline_read;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
}
|
2005-04-27 19:55:32 +02:00
|
|
|
|
|
|
|
|
|
// Get a line from the user
|
2008-01-08 14:52:32 +01:00
|
|
|
|
static char *line_read;
|
2005-04-27 19:55:32 +02:00
|
|
|
|
line_read = readline("commande> ");
|
|
|
|
|
|
|
|
|
|
// If the line has any text in it, save it on the history
|
|
|
|
|
if (line_read && *line_read)
|
|
|
|
|
add_history(line_read);
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
// Convert the line into wide characters
|
|
|
|
|
// Get the needed length (we _can't_ use string::size())
|
|
|
|
|
size_t len = mbstowcs(NULL, line_read, 0);
|
|
|
|
|
if (len == (size_t)-1)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
wline_read = new wchar_t[len + 1];
|
2008-01-08 14:52:32 +01:00
|
|
|
|
mbstowcs(wline_read, line_read, len + 1);
|
|
|
|
|
|
|
|
|
|
if (line_read)
|
|
|
|
|
{
|
|
|
|
|
free(line_read);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if (!cin.good())
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
cout << "commande> ";
|
|
|
|
|
string line;
|
|
|
|
|
std::getline(cin, line);
|
|
|
|
|
|
|
|
|
|
// Get the needed length (we _can't_ use string::size())
|
|
|
|
|
size_t len = mbstowcs(NULL, line.c_str(), 0);
|
|
|
|
|
if (len == (size_t)-1)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
wline_read = new wchar_t[len + 1];
|
|
|
|
|
mbstowcs(wline_read, line.c_str(), len + 1);
|
|
|
|
|
#endif
|
2006-01-22 13:23:52 +01:00
|
|
|
|
|
|
|
|
|
return wline_read;
|
2005-04-27 19:55:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t * next_token_alpha(wchar_t *cmd, const wchar_t *delim, wchar_t **state)
|
2004-04-08 11:43:06 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
wchar_t *token = _wcstok(cmd, delim, state);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
if (token == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
return NULL;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; token[i] && iswalpha(token[i]); i++)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token[i] = L'\0';
|
2004-04-08 11:43:06 +02:00
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t * next_token_alphanum(wchar_t *cmd, const wchar_t *delim, wchar_t **state)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
wchar_t *token = _wcstok(cmd, delim, state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
return NULL;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; token[i] && iswalnum(token[i]); i++)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token[i] = L'\0';
|
2004-08-07 20:10:42 +02:00
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t * next_token_alphaplusjoker(wchar_t *cmd, const wchar_t *delim, wchar_t **state)
|
2004-04-08 11:43:06 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
wchar_t *token = _wcstok(cmd, delim, state);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
if (token == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
return NULL;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; token[i] && (iswalpha(token[i]) ||
|
|
|
|
|
token[i] == L'?' ||
|
|
|
|
|
token[i] == L'+');
|
2004-04-08 11:43:06 +02:00
|
|
|
|
i++)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token[i] = L'\0';
|
2004-04-08 11:43:06 +02:00
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t * next_token_digit(wchar_t *cmd, const wchar_t *delim, wchar_t **state)
|
2004-04-08 11:43:06 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
wchar_t *token = _wcstok(cmd, delim, state);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
if (token == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
return NULL;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; token[i] && (iswdigit(token[i]) || token[i] == L'-'); i++)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token[i] = L'\0';
|
2004-04-08 11:43:06 +02:00
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t * next_token_cross(wchar_t *cmd, const wchar_t *delim, wchar_t **state)
|
2004-04-08 11:43:06 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
wchar_t *token = _wcstok(cmd, delim, state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
return NULL;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
int i;
|
2004-08-07 20:10:42 +02:00
|
|
|
|
for (i = 0; token[i] &&
|
2006-01-22 13:23:52 +01:00
|
|
|
|
(iswalpha(token[i]) || token[i] == L'.');
|
2004-08-07 20:10:42 +02:00
|
|
|
|
i++)
|
|
|
|
|
;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token[i] = L'\0';
|
2004-08-07 20:10:42 +02:00
|
|
|
|
return token;
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t * next_token_filename(wchar_t *cmd, const wchar_t *delim, wchar_t **state)
|
2004-04-08 11:43:06 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
wchar_t *token = _wcstok(cmd, delim, state);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
if (token == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
return NULL;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; token[i] && (iswalnum(token[i]) ||
|
|
|
|
|
token[i] == L'.' ||
|
|
|
|
|
token[i] == L'_'); i++)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token[i] = L'\0';
|
2004-04-08 11:43:06 +02:00
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
void eliottxt_get_cross(const Dictionary &iDic, const wstring &iCros)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-03-02 19:45:10 +01:00
|
|
|
|
vector<wstring> wordList;
|
2008-01-08 14:52:32 +01:00
|
|
|
|
iDic.searchCross(iCros, wordList);
|
|
|
|
|
|
2008-03-02 19:45:10 +01:00
|
|
|
|
vector<wstring>::const_iterator it;
|
2008-01-08 14:52:32 +01:00
|
|
|
|
for (it = wordList.begin(); it != wordList.end(); it++)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
printf(" %s\n", convertToMb(*it).c_str());
|
2004-08-07 20:10:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
void help_training()
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
|
|
|
|
printf(" ? : aide -- cette page\n");
|
|
|
|
|
printf(" a [g|l|p|r|t] : afficher :\n");
|
|
|
|
|
printf(" g -- grille\n");
|
|
|
|
|
printf(" gj -- grille + jokers\n");
|
|
|
|
|
printf(" gm -- grille + valeur des cases\n");
|
|
|
|
|
printf(" gn -- grille + valeur des cases (variante)\n");
|
2006-11-05 14:27:49 +01:00
|
|
|
|
printf(" gd -- grille + debug cross (debug only)\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf(" l -- lettres non jou<6F>es\n");
|
|
|
|
|
printf(" p -- partie\n");
|
2006-11-05 14:27:49 +01:00
|
|
|
|
printf(" pd -- partie (debug)\n");
|
2006-01-01 20:32:44 +01:00
|
|
|
|
printf(" P -- partie (format standard)\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf(" r -- recherche\n");
|
|
|
|
|
printf(" s -- score\n");
|
|
|
|
|
printf(" S -- score de tous les joueurs\n");
|
|
|
|
|
printf(" t -- tirage\n");
|
|
|
|
|
printf(" d [] : v<>rifier le mot []\n");
|
2008-01-08 14:52:32 +01:00
|
|
|
|
printf(" b [b|p|r] [] : effectuer une recherche speciale <20> partir de []\n");
|
|
|
|
|
printf(" b -- benjamins\n");
|
|
|
|
|
printf(" p -- 7 + 1\n");
|
|
|
|
|
printf(" r -- raccords\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf(" * : tirage al<61>atoire\n");
|
|
|
|
|
printf(" + : tirage al<61>atoire ajouts\n");
|
|
|
|
|
printf(" t [] : changer le tirage\n");
|
|
|
|
|
printf(" j [] {} : jouer le mot [] aux coordonn<6E>es {}\n");
|
|
|
|
|
printf(" n [] : jouer le r<>sultat num<75>ro []\n");
|
2005-12-27 01:30:56 +01:00
|
|
|
|
printf(" r : rechercher les meilleurs r<>sultats\n");
|
2005-02-05 12:14:56 +01:00
|
|
|
|
printf(" s [] : sauver la partie en cours dans le fichier []\n");
|
2008-11-23 09:18:03 +01:00
|
|
|
|
printf(" h [p|n|f|l] : naviguer dans l'historique (prev, next, first, last\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf(" q : quitter le mode entra<72>nement\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
void help_freegame()
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
|
|
|
|
printf(" ? : aide -- cette page\n");
|
|
|
|
|
printf(" a [g|l|p|s|t] : afficher :\n");
|
|
|
|
|
printf(" g -- grille\n");
|
|
|
|
|
printf(" gj -- grille + jokers\n");
|
|
|
|
|
printf(" gm -- grille + valeur des cases\n");
|
|
|
|
|
printf(" gn -- grille + valeur des cases (variante)\n");
|
|
|
|
|
printf(" j -- joueur courant\n");
|
|
|
|
|
printf(" l -- lettres non jou<6F>es\n");
|
|
|
|
|
printf(" p -- partie\n");
|
2006-01-01 20:32:44 +01:00
|
|
|
|
printf(" P -- partie (format standard)\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf(" s -- score\n");
|
|
|
|
|
printf(" S -- score de tous les joueurs\n");
|
|
|
|
|
printf(" t -- tirage\n");
|
|
|
|
|
printf(" T -- tirage de tous les joueurs\n");
|
|
|
|
|
printf(" d [] : v<>rifier le mot []\n");
|
|
|
|
|
printf(" j [] {} : jouer le mot [] aux coordonn<6E>es {}\n");
|
|
|
|
|
printf(" p [] : passer son tour en changeant les lettres []\n");
|
2005-02-05 12:14:56 +01:00
|
|
|
|
printf(" s [] : sauver la partie en cours dans le fichier []\n");
|
2008-11-23 09:18:03 +01:00
|
|
|
|
printf(" h [p|n|f|l] : naviguer dans l'historique (prev, next, first, last\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf(" q : quitter le mode partie libre\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
void help_duplicate()
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
|
|
|
|
printf(" ? : aide -- cette page\n");
|
|
|
|
|
printf(" a [g|l|p|s|t] : afficher :\n");
|
|
|
|
|
printf(" g -- grille\n");
|
|
|
|
|
printf(" gj -- grille + jokers\n");
|
|
|
|
|
printf(" gm -- grille + valeur des cases\n");
|
|
|
|
|
printf(" gn -- grille + valeur des cases (variante)\n");
|
|
|
|
|
printf(" j -- joueur courant\n");
|
|
|
|
|
printf(" l -- lettres non jou<6F>es\n");
|
|
|
|
|
printf(" p -- partie\n");
|
2006-01-01 20:32:44 +01:00
|
|
|
|
printf(" P -- partie (format standard)\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf(" s -- score\n");
|
|
|
|
|
printf(" S -- score de tous les joueurs\n");
|
|
|
|
|
printf(" t -- tirage\n");
|
|
|
|
|
printf(" d [] : v<>rifier le mot []\n");
|
|
|
|
|
printf(" j [] {} : jouer le mot [] aux coordonn<6E>es {}\n");
|
2005-02-05 12:14:56 +01:00
|
|
|
|
printf(" n [] : passer au joueur n<>[]\n");
|
|
|
|
|
printf(" s [] : sauver la partie en cours dans le fichier []\n");
|
2008-11-23 09:18:03 +01:00
|
|
|
|
printf(" h [p|n|f|l] : naviguer dans l'historique (prev, next, first, last\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf(" q : quitter le mode duplicate\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
void help()
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
|
|
|
|
printf(" ? : aide -- cette page\n");
|
|
|
|
|
printf(" e : d<>marrer le mode entra<72>nement\n");
|
2006-08-12 00:06:53 +02:00
|
|
|
|
printf(" c [] : charger la partie du fichier []\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf(" d [] {} : d<>marrer une partie duplicate avec\n");
|
|
|
|
|
printf(" [] joueurs humains et {} joueurs IA\n");
|
|
|
|
|
printf(" l [] {} : d<>marrer une partie libre avec\n");
|
|
|
|
|
printf(" [] joueurs humains et {} joueurs IA\n");
|
|
|
|
|
printf(" D : raccourci pour d 1 1\n");
|
|
|
|
|
printf(" L : raccourci pour l 1 1\n");
|
2006-01-01 20:32:44 +01:00
|
|
|
|
printf(" x [] {1} {2} {3} : expressions rationnelles\n");
|
|
|
|
|
printf(" [] expression <20> rechercher\n");
|
|
|
|
|
printf(" {1} nombre de r<>sultats <20> afficher\n");
|
|
|
|
|
printf(" {2} longueur minimum d'un mot\n");
|
|
|
|
|
printf(" {3} longueur maximum d'un mot\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf(" q : quitter\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
void display_data(const Game &iGame, const wchar_t *delim, wchar_t **state)
|
2004-04-08 11:43:06 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
const wchar_t *token;
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token = next_token_alpha(NULL, delim, state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
{
|
2005-02-05 12:14:56 +01:00
|
|
|
|
cout << "commande incompl<70>te\n";
|
2004-08-07 20:10:42 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (token[0])
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'g':
|
2004-08-07 20:10:42 +02:00
|
|
|
|
switch (token[1])
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'\0':
|
2005-02-26 23:57:34 +01:00
|
|
|
|
GameIO::printBoard(cout, iGame);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-11-05 14:27:49 +01:00
|
|
|
|
case L'd':
|
|
|
|
|
GameIO::printBoardDebug(cout, iGame);
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'j':
|
2005-02-26 23:57:34 +01:00
|
|
|
|
GameIO::printBoardJoker(cout, iGame);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'm':
|
2005-02-26 23:57:34 +01:00
|
|
|
|
GameIO::printBoardMultipliers(cout, iGame);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'n':
|
2005-02-26 23:57:34 +01:00
|
|
|
|
GameIO::printBoardMultipliers2(cout, iGame);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("commande inconnue\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'j':
|
2005-02-05 12:14:56 +01:00
|
|
|
|
cout << "Joueur " << iGame.currPlayer() << endl;
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'l':
|
2005-02-26 23:57:34 +01:00
|
|
|
|
GameIO::printNonPlayed(cout, iGame);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'p':
|
2006-11-05 14:27:49 +01:00
|
|
|
|
switch (token[1])
|
|
|
|
|
{
|
|
|
|
|
case '\0':
|
|
|
|
|
iGame.save(cout,Game::FILE_FORMAT_ADVANCED);
|
|
|
|
|
break;
|
|
|
|
|
case 'd':
|
|
|
|
|
GameIO::printGameDebug(cout, iGame);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("commande inconnue\n");
|
|
|
|
|
}
|
2006-01-01 20:32:44 +01:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'P':
|
2006-01-01 20:32:44 +01:00
|
|
|
|
iGame.save(cout,Game::FILE_FORMAT_STANDARD);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'r':
|
|
|
|
|
token = next_token_digit(NULL, delim, state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
2005-02-26 23:57:34 +01:00
|
|
|
|
GameIO::printSearchResults(cout,
|
|
|
|
|
static_cast<const Training&>(iGame),
|
|
|
|
|
10);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
else
|
2005-02-26 23:57:34 +01:00
|
|
|
|
GameIO::printSearchResults(cout,
|
|
|
|
|
static_cast<const Training&>(iGame),
|
2006-01-22 13:23:52 +01:00
|
|
|
|
_wtoi(token));
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L's':
|
2005-02-26 23:57:34 +01:00
|
|
|
|
GameIO::printPoints(cout, iGame);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'S':
|
2005-02-26 23:57:34 +01:00
|
|
|
|
GameIO::printAllPoints(cout, iGame);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L't':
|
2005-12-27 00:35:03 +01:00
|
|
|
|
GameIO::printPlayedRack(cout, iGame, iGame.getHistory().getSize());
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'T':
|
2005-02-26 23:57:34 +01:00
|
|
|
|
GameIO::printAllRacks(cout, iGame);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2005-02-05 12:14:56 +01:00
|
|
|
|
cout << "commande inconnue\n";
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
void loop_training(Training &iGame)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
const wchar_t *token;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *state;
|
|
|
|
|
wchar_t *commande = NULL;
|
|
|
|
|
wchar_t delim[] = L" \t";
|
2004-08-07 20:10:42 +02:00
|
|
|
|
int quit = 0;
|
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
|
cout << "mode entra<72>nement\n";
|
|
|
|
|
cout << "[?] pour l'aide\n";
|
2004-08-07 20:10:42 +02:00
|
|
|
|
while (quit == 0)
|
|
|
|
|
{
|
2005-04-27 19:55:32 +02:00
|
|
|
|
commande = rl_gets();
|
2008-01-08 14:52:32 +01:00
|
|
|
|
token = _wcstok(commande, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token)
|
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
try
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
switch (token[0])
|
|
|
|
|
{
|
|
|
|
|
case L'?':
|
2008-01-08 14:52:32 +01:00
|
|
|
|
help_training();
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L'a':
|
|
|
|
|
display_data(iGame, delim, &state);
|
|
|
|
|
break;
|
|
|
|
|
case L'b':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
if (token == NULL)
|
2008-01-08 14:52:32 +01:00
|
|
|
|
help_training();
|
|
|
|
|
else
|
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
const wchar_t *word = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
if (word == NULL)
|
|
|
|
|
help_training();
|
|
|
|
|
else
|
2008-01-08 14:52:32 +01:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
switch (token[0])
|
2008-01-08 14:52:32 +01:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
case L'b':
|
2008-01-08 14:52:32 +01:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
vector<wstring> wordList;
|
|
|
|
|
iGame.getDic().searchBenj(word, wordList);
|
|
|
|
|
vector<wstring>::const_iterator it;
|
|
|
|
|
for (it = wordList.begin(); it != wordList.end(); ++it)
|
|
|
|
|
cout << convertToMb(*it) << endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case L'p':
|
|
|
|
|
{
|
|
|
|
|
map<wchar_t, vector<wstring> > wordMap;
|
|
|
|
|
iGame.getDic().search7pl1(word, wordMap, false);
|
|
|
|
|
map<wchar_t, vector<wstring> >::const_iterator it;
|
|
|
|
|
for (it = wordMap.begin(); it != wordMap.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (it->first)
|
|
|
|
|
cout << "+" << convertToMb(it->first) << endl;
|
|
|
|
|
vector<wstring>::const_iterator itWord;;
|
|
|
|
|
for (itWord = it->second.begin(); itWord != it->second.end(); itWord++)
|
|
|
|
|
{
|
|
|
|
|
cout << " " << convertToMb(*itWord) << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case L'r':
|
|
|
|
|
{
|
|
|
|
|
vector<wstring> wordList;
|
|
|
|
|
iGame.getDic().searchRacc(word, wordList);
|
|
|
|
|
vector<wstring>::const_iterator it;
|
|
|
|
|
for (it = wordList.begin(); it != wordList.end(); ++it)
|
|
|
|
|
cout << convertToMb(*it) << endl;
|
|
|
|
|
break;
|
2008-01-08 14:52:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L'd':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_training();
|
2004-08-07 20:10:42 +02:00
|
|
|
|
else
|
2006-01-22 13:23:52 +01:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
if (iGame.getDic().searchWord(token))
|
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- existe\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- n'existe pas\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L'j':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
if (token == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
help_training();
|
2008-09-13 23:32:45 +02:00
|
|
|
|
else
|
2006-11-05 14:27:49 +01:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
int res;
|
|
|
|
|
wchar_t *coord = next_token_alphanum(NULL, delim, &state);
|
|
|
|
|
if (coord == NULL)
|
|
|
|
|
{
|
|
|
|
|
help_training();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ((res = iGame.play(coord, token)) != 0)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stdout, "Mot incorrect ou mal plac<61> (%i)\n",
|
|
|
|
|
res);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-11-05 14:27:49 +01:00
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L'n':
|
|
|
|
|
token = next_token_digit(NULL, delim, &state);
|
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_training();
|
2004-08-07 20:10:42 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
int n = _wtoi(token);
|
|
|
|
|
if (n <= 0)
|
|
|
|
|
{
|
|
|
|
|
iGame.back(n == 0 ? 1 : -n);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (iGame.playResult(--n))
|
|
|
|
|
printf("mauvais argument\n");
|
|
|
|
|
}
|
2004-08-07 20:10:42 +02:00
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L'r':
|
|
|
|
|
iGame.search();
|
|
|
|
|
break;
|
|
|
|
|
case L't':
|
|
|
|
|
token = next_token_alphaplusjoker(NULL, delim, &state);
|
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_training();
|
|
|
|
|
else
|
|
|
|
|
if (iGame.setRackManual(0, token))
|
|
|
|
|
printf("le sac ne contient pas assez de lettres\n");
|
|
|
|
|
break;
|
|
|
|
|
case L'x':
|
|
|
|
|
token = next_token_cross(NULL, delim, &state);
|
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_training();
|
|
|
|
|
else
|
|
|
|
|
eliottxt_get_cross(iGame.getDic(), token);
|
|
|
|
|
break;
|
|
|
|
|
case L'*':
|
|
|
|
|
iGame.setRackRandom(false, Game::RACK_ALL);
|
|
|
|
|
break;
|
|
|
|
|
case L'+':
|
|
|
|
|
iGame.setRackRandom(false, Game::RACK_NEW);
|
|
|
|
|
break;
|
|
|
|
|
case L's':
|
|
|
|
|
token = next_token_filename(NULL, delim, &state);
|
|
|
|
|
if (token != NULL)
|
2005-02-05 12:14:56 +01:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
string filename = convertToMb(token);
|
|
|
|
|
ofstream fout(filename.c_str());
|
|
|
|
|
if (fout.rdstate() == ios::failbit)
|
|
|
|
|
{
|
|
|
|
|
printf("impossible d'ouvrir %s\n",
|
|
|
|
|
filename.c_str());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
iGame.save(fout);
|
|
|
|
|
fout.close();
|
2005-02-05 12:14:56 +01:00
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
2008-11-23 09:18:03 +01:00
|
|
|
|
case L'h':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
if (token != NULL)
|
|
|
|
|
{
|
|
|
|
|
switch (token[0])
|
|
|
|
|
{
|
|
|
|
|
case L'p':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().prevTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
case L'n':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().nextTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
case L'f':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().firstTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
case L'l':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().lastTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2008-09-13 23:32:45 +02:00
|
|
|
|
case L'q':
|
|
|
|
|
quit = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("commande inconnue\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (GameException &e)
|
|
|
|
|
{
|
|
|
|
|
printf("%s\n", e.what());
|
2004-08-07 20:10:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("fin du mode entra<72>nement\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
void loop_freegame(FreeGame &iGame)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
const wchar_t *token;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *state;
|
|
|
|
|
wchar_t *commande = NULL;
|
|
|
|
|
wchar_t delim[] = L" \t";
|
2004-08-07 20:10:42 +02:00
|
|
|
|
int quit = 0;
|
|
|
|
|
|
|
|
|
|
printf("mode partie libre\n");
|
|
|
|
|
printf("[?] pour l'aide\n");
|
|
|
|
|
while (quit == 0)
|
|
|
|
|
{
|
2005-04-27 19:55:32 +02:00
|
|
|
|
commande = rl_gets();
|
2008-01-08 14:52:32 +01:00
|
|
|
|
token = _wcstok(commande, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token)
|
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
try
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
switch (token[0])
|
|
|
|
|
{
|
|
|
|
|
case L'?':
|
2004-08-07 20:10:42 +02:00
|
|
|
|
help_freegame();
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L'a':
|
|
|
|
|
display_data(iGame, delim, &state);
|
|
|
|
|
break;
|
|
|
|
|
case L'd':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_freegame();
|
2004-08-07 20:10:42 +02:00
|
|
|
|
else
|
2006-01-22 13:23:52 +01:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
if (iGame.getDic().searchWord(token))
|
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- existe\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- n'existe pas\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L'j':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
if (token == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
help_freegame();
|
2008-09-13 23:32:45 +02:00
|
|
|
|
else
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
int res;
|
|
|
|
|
wchar_t *coord = next_token_alphanum(NULL, delim, &state);
|
|
|
|
|
if (coord == NULL)
|
|
|
|
|
{
|
|
|
|
|
help_freegame();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ((res = iGame.play(coord, token)) != 0)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stdout, "Mot incorrect ou mal plac<61> (%i)\n",
|
|
|
|
|
res);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-08-07 20:10:42 +02:00
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L'p':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
/* You can pass your turn without changing any letter */
|
|
|
|
|
if (token == NULL)
|
|
|
|
|
token = L"";
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2008-09-13 23:32:45 +02:00
|
|
|
|
if (iGame.pass(token) != 0)
|
|
|
|
|
break;
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2008-09-13 23:32:45 +02:00
|
|
|
|
case L's':
|
|
|
|
|
token = next_token_filename(NULL, delim, &state);
|
|
|
|
|
if (token != NULL)
|
2005-02-05 12:14:56 +01:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
string filename = convertToMb(token);
|
|
|
|
|
ofstream fout(filename.c_str());
|
|
|
|
|
if (fout.rdstate() == ios::failbit)
|
|
|
|
|
{
|
|
|
|
|
printf("impossible d'ouvrir %s\n",
|
|
|
|
|
filename.c_str());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
iGame.save(fout);
|
|
|
|
|
fout.close();
|
2005-02-05 12:14:56 +01:00
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
2008-11-23 09:18:03 +01:00
|
|
|
|
case L'h':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
if (token != NULL)
|
|
|
|
|
{
|
|
|
|
|
switch (token[0])
|
|
|
|
|
{
|
|
|
|
|
case L'p':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().prevTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
case L'n':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().nextTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
case L'f':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().firstTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
case L'l':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().lastTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2008-09-13 23:32:45 +02:00
|
|
|
|
case L'q':
|
|
|
|
|
quit = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("commande inconnue\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (GameException &e)
|
|
|
|
|
{
|
|
|
|
|
printf("%s\n", e.what());
|
2004-08-07 20:10:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("fin du mode partie libre\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
void loop_duplicate(Duplicate &iGame)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
const wchar_t *token;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *state;
|
|
|
|
|
wchar_t *commande = NULL;
|
|
|
|
|
wchar_t delim[] = L" \t";
|
2004-08-07 20:10:42 +02:00
|
|
|
|
int quit = 0;
|
|
|
|
|
|
|
|
|
|
printf("mode duplicate\n");
|
|
|
|
|
printf("[?] pour l'aide\n");
|
|
|
|
|
while (quit == 0)
|
|
|
|
|
{
|
2005-04-27 19:55:32 +02:00
|
|
|
|
commande = rl_gets();
|
2008-01-08 14:52:32 +01:00
|
|
|
|
token = _wcstok(commande, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token)
|
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
try
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
switch (token[0])
|
|
|
|
|
{
|
|
|
|
|
case L'?':
|
2004-08-07 20:10:42 +02:00
|
|
|
|
help_duplicate();
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L'a':
|
|
|
|
|
display_data(iGame, delim, &state);
|
|
|
|
|
break;
|
|
|
|
|
case L'd':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_duplicate();
|
2004-08-07 20:10:42 +02:00
|
|
|
|
else
|
2006-01-22 13:23:52 +01:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
if (iGame.getDic().searchWord(token))
|
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- existe\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- n'existe pas\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L'j':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
if (token == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
help_duplicate();
|
2008-09-13 23:32:45 +02:00
|
|
|
|
else
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
int res;
|
|
|
|
|
wchar_t *coord = next_token_alphanum(NULL, delim, &state);
|
|
|
|
|
if (coord == NULL)
|
|
|
|
|
{
|
|
|
|
|
help_duplicate();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ((res = iGame.play(coord, token)) != 0)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stdout, "Mot incorrect ou mal plac<61> (%i)\n",
|
|
|
|
|
res);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-08-07 20:10:42 +02:00
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L'n':
|
|
|
|
|
token = next_token_digit(NULL, delim, &state);
|
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_duplicate();
|
|
|
|
|
else
|
2008-01-08 14:52:32 +01:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
int n = _wtoi(token);
|
|
|
|
|
if (n < 0 || n >= (int)iGame.getNPlayers())
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Num<EFBFBD>ro de joueur invalide\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
int res = iGame.setPlayer(_wtoi(token));
|
|
|
|
|
if (res == 1)
|
|
|
|
|
fprintf(stderr, "Impossible de choisir un joueur non humain\n");
|
2008-01-08 14:52:32 +01:00
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
|
|
|
|
case L's':
|
|
|
|
|
token = next_token_filename(NULL, delim, &state);
|
|
|
|
|
if (token != NULL)
|
2005-02-05 12:14:56 +01:00
|
|
|
|
{
|
2008-09-13 23:32:45 +02:00
|
|
|
|
string filename = convertToMb(token);
|
|
|
|
|
ofstream fout(filename.c_str());
|
|
|
|
|
if (fout.rdstate() == ios::failbit)
|
|
|
|
|
{
|
|
|
|
|
printf("impossible d'ouvrir %s\n",
|
|
|
|
|
filename.c_str());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
iGame.save(fout);
|
|
|
|
|
fout.close();
|
2005-02-05 12:14:56 +01:00
|
|
|
|
}
|
2008-09-13 23:32:45 +02:00
|
|
|
|
break;
|
2008-11-23 09:18:03 +01:00
|
|
|
|
case L'h':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
|
|
|
|
if (token != NULL)
|
|
|
|
|
{
|
|
|
|
|
switch (token[0])
|
|
|
|
|
{
|
|
|
|
|
case L'p':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().prevTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
case L'n':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().nextTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
case L'f':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().firstTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
case L'l':
|
2008-11-23 17:55:28 +01:00
|
|
|
|
iGame.accessNavigation().lastTurn();
|
2008-11-23 09:18:03 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2008-09-13 23:32:45 +02:00
|
|
|
|
case L'q':
|
|
|
|
|
quit = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("commande inconnue\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (GameException &e)
|
|
|
|
|
{
|
|
|
|
|
printf("%s\n", e.what());
|
2004-08-07 20:10:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("fin du mode duplicate\n");
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2008-09-13 23:32:45 +02:00
|
|
|
|
void eliot_regexp(const Dictionary& iDic,
|
2006-01-22 13:23:52 +01:00
|
|
|
|
const wchar_t *delim, wchar_t **state)
|
2006-01-01 20:32:44 +01:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
printf(" x [] {1} {2} {3} : expressions rationnelles\n");
|
|
|
|
|
printf(" [] expression <20> rechercher\n");
|
|
|
|
|
printf(" {1} nombre de r<>sultats <20> afficher\n");
|
|
|
|
|
printf(" {2} longueur minimum d'un mot\n");
|
|
|
|
|
printf(" {3} longueur maximum d'un mot\n");
|
|
|
|
|
*/
|
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
wchar_t *regexp = _wcstok(NULL, delim, state);
|
|
|
|
|
wchar_t *cnres = _wcstok(NULL, delim, state);
|
|
|
|
|
wchar_t *clmin = _wcstok(NULL, delim, state);
|
|
|
|
|
wchar_t *clmax = _wcstok(NULL, delim, state);
|
2006-01-22 13:23:52 +01:00
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
if (regexp == NULL)
|
2006-01-01 20:32:44 +01:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-07-27 15:32:47 +02:00
|
|
|
|
unsigned int nres = cnres ? _wtoi(cnres) : 50;
|
|
|
|
|
unsigned int lmin = clmin ? _wtoi(clmin) : 1;
|
|
|
|
|
unsigned int lmax = clmax ? _wtoi(clmax) : DIC_WORD_MAX - 1;
|
2006-01-01 20:32:44 +01:00
|
|
|
|
|
2008-07-27 15:32:47 +02:00
|
|
|
|
if (lmax > (DIC_WORD_MAX - 1) || lmin < 1 || lmin > lmax)
|
2006-01-01 20:32:44 +01:00
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
printf("bad length -%s,%s-\n", (const char*)clmin, (const char*)clmax);
|
2006-01-01 20:32:44 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
printf("search for %s (%d,%d,%d)\n", convertToMb(regexp).c_str(),
|
2006-01-22 13:23:52 +01:00
|
|
|
|
nres, lmin, lmax);
|
2008-01-08 14:52:32 +01:00
|
|
|
|
|
2008-03-02 19:45:10 +01:00
|
|
|
|
vector<wstring> wordList;
|
2008-08-31 13:48:11 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
iDic.searchRegExp(regexp, wordList, lmin, lmax, nres);
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidRegexpException &e)
|
|
|
|
|
{
|
|
|
|
|
printf("Invalid regular expression: %s\n", e.what());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
|
2008-03-02 19:45:10 +01:00
|
|
|
|
vector<wstring>::const_iterator it;
|
2008-07-27 15:32:47 +02:00
|
|
|
|
for (it = wordList.begin(); it != wordList.end(); it++)
|
2006-01-01 20:32:44 +01:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
printf("%s\n", convertToMb(*it).c_str());
|
2006-01-01 20:32:44 +01:00
|
|
|
|
}
|
2008-07-27 15:32:47 +02:00
|
|
|
|
printf("%d printed results\n", wordList.size());
|
2006-01-01 20:32:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
|
|
|
|
|
void main_loop(const Dictionary &iDic)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
const wchar_t *token;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *state;
|
|
|
|
|
wchar_t *commande = NULL;
|
|
|
|
|
wchar_t delim[] = L" \t";
|
2004-08-07 20:10:42 +02:00
|
|
|
|
int quit = 0;
|
|
|
|
|
|
|
|
|
|
printf("[?] pour l'aide\n");
|
2005-02-05 12:14:56 +01:00
|
|
|
|
while (quit == 0)
|
|
|
|
|
{
|
2005-04-27 19:55:32 +02:00
|
|
|
|
commande = rl_gets();
|
2008-01-08 14:52:32 +01:00
|
|
|
|
token = _wcstok(commande, delim, &state);
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (token)
|
|
|
|
|
{
|
2004-08-07 20:10:42 +02:00
|
|
|
|
switch (token[0])
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'?':
|
2004-08-07 20:10:42 +02:00
|
|
|
|
help();
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'c':
|
|
|
|
|
token = next_token_filename(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
{}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
string filename = convertToMb(token);
|
2006-08-12 00:06:53 +02:00
|
|
|
|
Game *game = GameFactory::Instance()->load(filename, iDic);
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (game == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2006-08-12 00:06:53 +02:00
|
|
|
|
printf("erreur pendant le chargement de la partie\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
}
|
2005-02-05 12:14:56 +01:00
|
|
|
|
else
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2006-08-12 00:06:53 +02:00
|
|
|
|
switch (game->getMode())
|
|
|
|
|
{
|
|
|
|
|
case Game::kTRAINING:
|
|
|
|
|
loop_training((Training&)*game);
|
|
|
|
|
break;
|
|
|
|
|
case Game::kFREEGAME:
|
|
|
|
|
loop_freegame((FreeGame&)*game);
|
|
|
|
|
break;
|
|
|
|
|
case Game::kDUPLICATE:
|
|
|
|
|
loop_duplicate((Duplicate&)*game);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-08-07 20:10:42 +02:00
|
|
|
|
}
|
2006-08-12 00:06:53 +02:00
|
|
|
|
GameFactory::Instance()->releaseGame(*game);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'e':
|
2005-02-05 12:14:56 +01:00
|
|
|
|
{
|
2005-02-24 09:06:24 +01:00
|
|
|
|
// New training game
|
|
|
|
|
Training *game = GameFactory::Instance()->createTraining(iDic);
|
|
|
|
|
game->start();
|
|
|
|
|
loop_training(*game);
|
|
|
|
|
GameFactory::Instance()->releaseGame(*game);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2005-02-05 12:14:56 +01:00
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'd':
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2005-02-24 09:06:24 +01:00
|
|
|
|
// New duplicate game
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token = next_token_digit(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
{
|
|
|
|
|
help();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-24 09:06:24 +01:00
|
|
|
|
Duplicate *game = GameFactory::Instance()->createDuplicate(iDic);
|
2006-01-22 13:23:52 +01:00
|
|
|
|
for (i = 0; i < _wtoi(token); i++)
|
2008-01-28 20:17:33 +01:00
|
|
|
|
game->addPlayer(new HumanPlayer);
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token = next_token_digit(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
{
|
|
|
|
|
help();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
for (i = 0; i < _wtoi(token); i++)
|
2008-01-28 20:17:33 +01:00
|
|
|
|
game->addPlayer(new AIPercent(1));
|
2005-02-24 09:06:24 +01:00
|
|
|
|
game->start();
|
|
|
|
|
loop_duplicate(*game);
|
|
|
|
|
GameFactory::Instance()->releaseGame(*game);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'l':
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2005-02-24 09:06:24 +01:00
|
|
|
|
// New free game
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token = next_token_digit(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
{
|
|
|
|
|
help();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-24 09:06:24 +01:00
|
|
|
|
FreeGame *game = GameFactory::Instance()->createFreeGame(iDic);
|
2006-01-22 13:23:52 +01:00
|
|
|
|
for (i = 0; i < _wtoi(token); i++)
|
2008-01-28 20:17:33 +01:00
|
|
|
|
game->addPlayer(new HumanPlayer);
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token = next_token_digit(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
{
|
|
|
|
|
help();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
for (i = 0; i < _wtoi(token); i++)
|
2008-01-28 20:17:33 +01:00
|
|
|
|
game->addPlayer(new AIPercent(1));
|
2005-02-24 09:06:24 +01:00
|
|
|
|
game->start();
|
|
|
|
|
loop_freegame(*game);
|
|
|
|
|
GameFactory::Instance()->releaseGame(*game);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'D':
|
2005-02-05 12:14:56 +01:00
|
|
|
|
{
|
2005-02-24 09:06:24 +01:00
|
|
|
|
// New duplicate game
|
|
|
|
|
Duplicate *game = GameFactory::Instance()->createDuplicate(iDic);
|
2008-01-28 20:17:33 +01:00
|
|
|
|
game->addPlayer(new HumanPlayer);
|
|
|
|
|
game->addPlayer(new AIPercent(1));
|
2005-02-24 09:06:24 +01:00
|
|
|
|
game->start();
|
|
|
|
|
loop_duplicate(*game);
|
|
|
|
|
GameFactory::Instance()->releaseGame(*game);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2005-02-05 12:14:56 +01:00
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'L':
|
2005-02-05 12:14:56 +01:00
|
|
|
|
{
|
2005-02-24 09:06:24 +01:00
|
|
|
|
// New free game
|
|
|
|
|
FreeGame *game = GameFactory::Instance()->createFreeGame(iDic);
|
2008-01-28 20:17:33 +01:00
|
|
|
|
game->addPlayer(new HumanPlayer);
|
|
|
|
|
game->addPlayer(new AIPercent(1));
|
2005-02-24 09:06:24 +01:00
|
|
|
|
game->start();
|
|
|
|
|
loop_freegame(*game);
|
|
|
|
|
GameFactory::Instance()->releaseGame(*game);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2005-02-05 12:14:56 +01:00
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'x':
|
|
|
|
|
// Regular expression tests
|
2008-09-13 23:32:45 +02:00
|
|
|
|
eliot_regexp(iDic, delim, &state);
|
2006-01-01 20:32:44 +01:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'q':
|
2004-08-07 20:10:42 +02:00
|
|
|
|
quit = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("commande inconnue\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
int main(int argc, char *argv[])
|
2004-04-08 11:43:06 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
string dicPath;
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
// Let the user choose the locale
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
|
2005-04-10 14:15:40 +02:00
|
|
|
|
if (argc != 2 && argc != 3)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2005-04-10 14:15:40 +02:00
|
|
|
|
fprintf(stdout, "Usage: eliot /chemin/vers/ods4.dawg [random_seed]\n");
|
2004-08-07 20:10:42 +02:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
else
|
2006-08-12 00:06:53 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
dicPath = argv[1];
|
2006-08-12 00:06:53 +02:00
|
|
|
|
}
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
try
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
|
Dictionary dic(dicPath);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2008-11-23 09:33:16 +01:00
|
|
|
|
unsigned int seed;
|
2008-01-08 14:52:32 +01:00
|
|
|
|
if (argc == 3)
|
2008-11-23 09:33:16 +01:00
|
|
|
|
seed = atoi(argv[2]);
|
2008-01-08 14:52:32 +01:00
|
|
|
|
else
|
2008-11-23 09:33:16 +01:00
|
|
|
|
seed = time(NULL);
|
|
|
|
|
srand(seed);
|
|
|
|
|
cerr << "Using seed: " << seed << endl;
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
main_loop(dic);
|
|
|
|
|
GameFactory::Destroy();
|
2005-04-27 19:55:32 +02:00
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
// Free the readline static variable
|
|
|
|
|
if (wline_read)
|
|
|
|
|
delete[] wline_read;
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
cerr << e.what() << endl;
|
|
|
|
|
}
|
2005-04-27 19:55:32 +02:00
|
|
|
|
|
2004-08-07 20:10:42 +02:00
|
|
|
|
return 0;
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
2006-01-01 20:32:44 +01:00
|
|
|
|
|