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
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <string.h>
|
2006-01-22 13:23:52 +01:00
|
|
|
|
#include <locale.h>
|
|
|
|
|
#include <wctype.h>
|
|
|
|
|
#include <wchar.h>
|
2005-02-05 12:14:56 +01:00
|
|
|
|
#include <fstream>
|
2005-04-27 19:55:32 +02:00
|
|
|
|
#include <readline/readline.h>
|
|
|
|
|
#include <readline/history.h>
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
|
|
|
|
#include "dic.h"
|
|
|
|
|
#include "dic_search.h"
|
2006-01-01 20:32:44 +01:00
|
|
|
|
#include "regexp.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"
|
2006-01-22 13:23:52 +01:00
|
|
|
|
#include "encoding.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. */
|
|
|
|
|
static char *line_read = NULL;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
/* Wide version of the line */
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
// If the buffer has already been allocated, return the memory to the free
|
|
|
|
|
// pool
|
|
|
|
|
if (line_read)
|
|
|
|
|
{
|
|
|
|
|
free(line_read);
|
|
|
|
|
line_read = NULL;
|
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
if (wline_read)
|
|
|
|
|
{
|
|
|
|
|
free(wline_read);
|
|
|
|
|
wline_read = NULL;
|
|
|
|
|
}
|
2005-04-27 19:55:32 +02:00
|
|
|
|
|
|
|
|
|
// Get a line from the user
|
|
|
|
|
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];
|
|
|
|
|
len = mbstowcs(wline_read, line_read, len + 1);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2006-01-22 13:23:52 +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
|
|
|
|
{
|
2006-01-22 13:23:52 +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
|
|
|
|
{
|
2006-01-22 13:23:52 +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
|
|
|
|
{
|
2006-01-22 13:23:52 +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
|
|
|
|
{
|
2006-01-22 13:23:52 +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
|
|
|
|
{
|
2006-01-22 13:23:52 +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
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
void eliottxt_get_cross(const Dictionary &iDic, wchar_t *cros)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t wordlist[RES_CROS_MAX][DIC_WORD_MAX];
|
2005-02-05 12:14:56 +01:00
|
|
|
|
Dic_search_Cros(iDic, cros, wordlist);
|
2006-01-22 13:23:52 +01:00
|
|
|
|
for (int i = 0; i < RES_CROS_MAX && wordlist[i][0]; i++)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
printf(" %s\n", convertToMb(wordlist[i]).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");
|
|
|
|
|
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(" 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");
|
|
|
|
|
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");
|
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");
|
|
|
|
|
printf(" c [] : charger la partie du fichier []\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");
|
|
|
|
|
printf(" c [] : charger la partie du fichier []\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");
|
|
|
|
|
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
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
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-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-01-01 20:32:44 +01:00
|
|
|
|
iGame.save(cout,Game::FILE_FORMAT_ADVANCED);
|
|
|
|
|
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
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *token;
|
|
|
|
|
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();
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token = wcstok(commande, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token)
|
|
|
|
|
{
|
|
|
|
|
switch (token[0])
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'?':
|
2004-08-07 20:10:42 +02:00
|
|
|
|
help_training();
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'a':
|
|
|
|
|
display_data(iGame, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'd':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_training();
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (Dic_search_word(iGame.getDic(), token))
|
2006-01-22 13:23:52 +01:00
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- existe\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
2004-08-07 20:10:42 +02:00
|
|
|
|
else
|
2006-01-22 13:23:52 +01:00
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- n'existe pas\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'j':
|
|
|
|
|
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
|
|
|
|
help_training();
|
2004-08-07 20:10:42 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int res;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *coord = next_token_alphanum(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (coord == NULL)
|
|
|
|
|
{
|
|
|
|
|
help_training();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if ((res = iGame.play(coord, token)) != 0)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Mot incorrect ou mal plac<61> (%i)\n",
|
|
|
|
|
res);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'n':
|
|
|
|
|
token = next_token_digit(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_training();
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
int n = _wtoi(token);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (n <= 0)
|
2005-02-05 12:14:56 +01:00
|
|
|
|
iGame.back(n == 0 ? 1 : -n);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (iGame.playResult(--n))
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf("mauvais argument\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'r':
|
2005-02-05 12:14:56 +01:00
|
|
|
|
iGame.search();
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L't':
|
|
|
|
|
token = next_token_alphaplusjoker(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_training();
|
|
|
|
|
else
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (iGame.setRackManual(0, token))
|
2004-08-07 20:10:42 +02:00
|
|
|
|
printf("le sac ne contient pas assez de lettres\n");
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'x':
|
|
|
|
|
token = next_token_cross(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_training();
|
|
|
|
|
else
|
2005-02-05 12:14:56 +01:00
|
|
|
|
eliottxt_get_cross(iGame.getDic(), token);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'*':
|
2006-01-01 20:32:44 +01:00
|
|
|
|
iGame.setRackRandom(false, Game::RACK_ALL);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'+':
|
2006-01-01 20:32:44 +01:00
|
|
|
|
iGame.setRackRandom(false, Game::RACK_NEW);
|
2005-02-05 12:14:56 +01:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L's':
|
|
|
|
|
token = next_token_filename(NULL, delim, &state);
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (token != NULL)
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
string filename = convertToMb(token);
|
|
|
|
|
ofstream fout(filename.c_str());
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (fout.rdstate() == ios::failbit)
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
printf("impossible d'ouvrir %s\n",
|
|
|
|
|
filename.c_str());
|
2005-02-05 12:14:56 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
iGame.save(fout);
|
|
|
|
|
fout.close();
|
|
|
|
|
}
|
2004-08-07 20:10:42 +02: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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *token;
|
|
|
|
|
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();
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token = wcstok(commande, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token)
|
|
|
|
|
{
|
|
|
|
|
switch (token[0])
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'?':
|
2004-08-07 20:10:42 +02:00
|
|
|
|
help_freegame();
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'a':
|
|
|
|
|
display_data(iGame, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'd':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
if (token == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
help_freegame();
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (Dic_search_word(iGame.getDic(), token))
|
2006-01-22 13:23:52 +01:00
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- existe\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
2004-08-07 20:10:42 +02:00
|
|
|
|
else
|
2006-01-22 13:23:52 +01:00
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- n'existe pas\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'j':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_freegame();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int res;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *coord = next_token_alphanum(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (coord == NULL)
|
|
|
|
|
{
|
|
|
|
|
help_freegame();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if ((res = iGame.play(coord, token)) != 0)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Mot incorrect ou mal plac<61> (%i)\n",
|
|
|
|
|
res);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'p':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
/* You can pass your turn without changing any letter */
|
|
|
|
|
if (token == NULL)
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token = L"";
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (iGame.pass(token, iGame.currPlayer()) != 0)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L's':
|
|
|
|
|
token = next_token_filename(NULL, delim, &state);
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (token != NULL)
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
string filename = convertToMb(token);
|
|
|
|
|
ofstream fout(filename.c_str());
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (fout.rdstate() == ios::failbit)
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
printf("impossible d'ouvrir %s\n",
|
|
|
|
|
filename.c_str());
|
2005-02-05 12:14:56 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
iGame.save(fout);
|
|
|
|
|
fout.close();
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *token;
|
|
|
|
|
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();
|
2006-01-22 13:23:52 +01:00
|
|
|
|
token = wcstok(commande, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token)
|
|
|
|
|
{
|
|
|
|
|
switch (token[0])
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'?':
|
2004-08-07 20:10:42 +02:00
|
|
|
|
help_duplicate();
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'a':
|
|
|
|
|
display_data(iGame, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'd':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_duplicate();
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (Dic_search_word(iGame.getDic(), token))
|
2006-01-22 13:23:52 +01:00
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- existe\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
2004-08-07 20:10:42 +02:00
|
|
|
|
else
|
2006-01-22 13:23:52 +01:00
|
|
|
|
{
|
|
|
|
|
printf("le mot -%s- n'existe pas\n",
|
|
|
|
|
convertToMb(token).c_str());
|
|
|
|
|
}
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'j':
|
|
|
|
|
token = next_token_alpha(NULL, delim, &state);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
if (token == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
help_duplicate();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int res;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *coord = next_token_alphanum(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (coord == NULL)
|
|
|
|
|
{
|
|
|
|
|
help_duplicate();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if ((res = iGame.play(coord, token)) != 0)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Mot incorrect ou mal plac<61> (%i)\n",
|
|
|
|
|
res);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'n':
|
|
|
|
|
token = next_token_digit(NULL, delim, &state);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (token == NULL)
|
|
|
|
|
help_duplicate();
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
int res = iGame.setPlayer(_wtoi(token));
|
2004-08-07 20:10:42 +02:00
|
|
|
|
if (res == 1)
|
|
|
|
|
fprintf(stderr, "Num<EFBFBD>ro de joueur invalide\n");
|
|
|
|
|
else if (res == 2)
|
|
|
|
|
fprintf(stderr, "Impossible de choisir un joueur non humain\n");
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L's':
|
|
|
|
|
token = next_token_filename(NULL, delim, &state);
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (token != NULL)
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
string filename = convertToMb(token);
|
|
|
|
|
ofstream fout(filename.c_str());
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (fout.rdstate() == ios::failbit)
|
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
printf("impossible d'ouvrir %s\n",
|
|
|
|
|
filename.c_str());
|
2005-02-05 12:14:56 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
iGame.save(fout);
|
|
|
|
|
fout.close();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
case L'q':
|
2004-08-07 20:10:42 +02:00
|
|
|
|
quit = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2004-04-08 11:43:06 +02:00
|
|
|
|
printf("commande inconnue\n");
|
|
|
|
|
break;
|
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
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
void eliot_regexp_build_default_llist(struct search_RegE_list_t &llist)
|
2006-01-01 20:32:44 +01:00
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
memset(&llist, 0, sizeof(llist));
|
2006-01-01 20:32:44 +01:00
|
|
|
|
|
|
|
|
|
llist.minlength = 1;
|
|
|
|
|
llist.maxlength = 15;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
|
2006-01-01 20:32:44 +01:00
|
|
|
|
llist.symbl[0] = RE_ALL_MATCH;
|
|
|
|
|
llist.symbl[1] = RE_VOWL_MATCH;
|
|
|
|
|
llist.symbl[2] = RE_CONS_MATCH;
|
|
|
|
|
llist.symbl[3] = RE_USR1_MATCH;
|
|
|
|
|
llist.symbl[5] = RE_USR2_MATCH;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
|
2006-01-01 20:32:44 +01:00
|
|
|
|
llist.valid[0] = 1; // all letters
|
|
|
|
|
llist.valid[1] = 1; // vowels
|
|
|
|
|
llist.valid[2] = 1; // consonants
|
|
|
|
|
llist.valid[3] = 0; // user defined list 1
|
|
|
|
|
llist.valid[4] = 0; // user defined list 2
|
2006-01-22 13:23:52 +01:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < DIC_SEARCH_REGE_LIST; i++)
|
|
|
|
|
{
|
|
|
|
|
memset(llist.letters[i], 0, sizeof(llist.letters[i]));
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-01 20:32:44 +01:00
|
|
|
|
const list<Tile>& allTiles = Tile::getAllTiles();
|
|
|
|
|
list<Tile>::const_iterator it;
|
|
|
|
|
for (it = allTiles.begin(); it != allTiles.end(); it++)
|
2006-01-22 13:23:52 +01:00
|
|
|
|
{
|
|
|
|
|
if (! it->isJoker() && ! it->isEmpty())
|
2006-01-01 20:32:44 +01:00
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
// all tiles
|
|
|
|
|
llist.letters[0][it->toCode()] = 1;
|
|
|
|
|
// vowels
|
|
|
|
|
if (it->isVowel())
|
|
|
|
|
{
|
|
|
|
|
llist.letters[1][it->toCode()] = 1;
|
|
|
|
|
}
|
|
|
|
|
// consonants
|
|
|
|
|
if (it->isConsonant())
|
|
|
|
|
{
|
|
|
|
|
llist.letters[2][it->toCode()] = 1;
|
|
|
|
|
}
|
2006-01-01 20:32:44 +01:00
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
}
|
2006-01-01 20:32:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
void eliot_regexp(const Dictionary& iDic, wchar_t *cmd,
|
|
|
|
|
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");
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define DIC_RE_MAX (3*DIC_WORD_MAX) // yes, it's 3
|
|
|
|
|
|
|
|
|
|
struct search_RegE_list_t llist;
|
|
|
|
|
eliot_regexp_build_default_llist(llist);
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *exp, *cnres, *clmin, *clmax;
|
|
|
|
|
|
|
|
|
|
exp = wcstok(NULL, delim, state);
|
|
|
|
|
cnres = wcstok(NULL, delim, state);
|
|
|
|
|
clmin = wcstok(NULL, delim, state);
|
|
|
|
|
clmax = wcstok(NULL, delim, state);
|
2006-01-01 20:32:44 +01:00
|
|
|
|
|
|
|
|
|
if (exp == NULL)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
int nres = cnres ? _wtoi(cnres) : 50;
|
|
|
|
|
int lmin = clmin ? _wtoi(clmin) : 1;
|
|
|
|
|
int lmax = clmax ? _wtoi(clmax) : DIC_WORD_MAX - 1;
|
2006-01-01 20:32:44 +01:00
|
|
|
|
|
|
|
|
|
if (lmax <= (DIC_WORD_MAX - 1) && lmin >= 1 && lmin <= lmax)
|
|
|
|
|
{
|
|
|
|
|
llist.minlength = lmin;
|
|
|
|
|
llist.maxlength = lmax;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t re[DIC_RE_MAX];
|
|
|
|
|
wcsncpy(re, exp, DIC_RE_MAX);
|
|
|
|
|
wchar_t buff[RES_REGE_MAX][DIC_WORD_MAX];
|
|
|
|
|
|
|
|
|
|
printf("search for %s (%d,%d,%d)\n", convertToMb(exp).c_str(),
|
|
|
|
|
nres, lmin, lmax);
|
|
|
|
|
Dic_search_RegE(iDic, re, buff, &llist);
|
|
|
|
|
|
2006-01-01 20:32:44 +01:00
|
|
|
|
int nresult = 0;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
for (int i = 0; i < RES_REGE_MAX && i < nres && buff[i][0]; i++)
|
2006-01-01 20:32:44 +01:00
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
printf("%s\n", convertToMb(buff[i]).c_str());
|
2006-01-01 20:32:44 +01:00
|
|
|
|
nresult++;
|
|
|
|
|
}
|
2006-01-22 13:23:52 +01:00
|
|
|
|
printf("%d printed results\n", nresult);
|
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
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
wchar_t *token;
|
|
|
|
|
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();
|
2006-01-22 13:23:52 +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);
|
2004-08-07 20:10:42 +02:00
|
|
|
|
FILE* fin;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
if ((fin = fopen(filename.c_str(), "r")) == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
|
printf("impossible d'ouvrir %s\n",
|
|
|
|
|
filename.c_str());
|
2004-08-07 20:10:42 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-05 12:14:56 +01:00
|
|
|
|
Game *game = Game::load(fin, iDic);
|
|
|
|
|
fclose(fin);
|
|
|
|
|
if (game == NULL)
|
2004-08-07 20:10:42 +02:00
|
|
|
|
{
|
2006-01-01 20:32:44 +01:00
|
|
|
|
printf("erreur pendant le chargement\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
|
|
|
|
{
|
2005-02-05 12:14:56 +01:00
|
|
|
|
if (game->getMode() == Game::kTRAINING)
|
|
|
|
|
loop_training((Training&)*game);
|
|
|
|
|
else if (game->getMode() == Game::kFREEGAME)
|
|
|
|
|
loop_freegame((FreeGame&)*game);
|
|
|
|
|
else
|
|
|
|
|
loop_duplicate((Duplicate&)*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++)
|
2005-02-24 09:06:24 +01:00
|
|
|
|
game->addHumanPlayer();
|
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++)
|
2005-02-24 09:06:24 +01:00
|
|
|
|
game->addAIPlayer();
|
|
|
|
|
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++)
|
2005-02-24 09:06:24 +01:00
|
|
|
|
game->addHumanPlayer();
|
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++)
|
2005-02-24 09:06:24 +01:00
|
|
|
|
game->addAIPlayer();
|
|
|
|
|
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);
|
|
|
|
|
game->addHumanPlayer();
|
|
|
|
|
game->addAIPlayer();
|
|
|
|
|
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);
|
|
|
|
|
game->addHumanPlayer();
|
|
|
|
|
game->addAIPlayer();
|
|
|
|
|
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
|
|
|
|
|
eliot_regexp(iDic, NULL, 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
|
|
|
|
{
|
2004-08-07 20:10:42 +02:00
|
|
|
|
char dic_path[100];
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
// Let the user choose the locale
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
|
2004-08-07 20:10:42 +02:00
|
|
|
|
Dictionary dic = NULL;
|
|
|
|
|
|
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
|
|
|
|
|
strcpy(dic_path, argv[1]);
|
|
|
|
|
|
|
|
|
|
switch (Dic_load(&dic, dic_path))
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
/* Normal case */
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
printf("chargement: probl<62>me d'ouverture de %s\n", argv[1]);
|
|
|
|
|
exit(1);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
printf("chargement: mauvais en-tete de dictionnaire\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
printf("chargement: probl<62>me 3 d'allocation m<>moire\n");
|
|
|
|
|
exit(3);
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
printf("chargement: probl<62>me 4 d'alocation m<>moire\n");
|
|
|
|
|
exit(4);
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
printf("chargement: probl<62>me de lecture des arcs du dictionnaire\n");
|
|
|
|
|
exit(5);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("chargement: probl<62>me non-repertori<72>\n");
|
|
|
|
|
exit(6);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-10 14:15:40 +02:00
|
|
|
|
if (argc == 3)
|
|
|
|
|
srand(atoi(argv[2]));
|
|
|
|
|
else
|
|
|
|
|
srand(time(NULL));
|
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
|
main_loop(dic);
|
2005-02-24 09:06:24 +01:00
|
|
|
|
GameFactory::Destroy();
|
2004-08-07 20:10:42 +02:00
|
|
|
|
|
|
|
|
|
Dic_destroy(dic);
|
2005-04-27 19:55:32 +02:00
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
// Free the readline static variable and its wide equivalent
|
2005-04-27 19:55:32 +02:00
|
|
|
|
if (line_read)
|
|
|
|
|
free(line_read);
|
2006-01-22 13:23:52 +01:00
|
|
|
|
if (wline_read)
|
|
|
|
|
free(wline_read);
|
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
|
|
|
|
|
|
|
|
|
/// Local Variables:
|
|
|
|
|
/// mode: c++
|
|
|
|
|
/// mode: hs-minor
|
|
|
|
|
/// c-basic-offset: 4
|
|
|
|
|
/// indent-tabs-mode: nil
|
|
|
|
|
/// End:
|