2005-02-05 12:14:56 +01:00
|
|
|
|
/*****************************************************************************
|
2008-01-08 14:52:32 +01:00
|
|
|
|
* Eliot
|
2012-10-07 16:25:41 +02:00
|
|
|
|
* Copyright (C) 1999-2012 Antoine Fraboulet & Olivier Teuli<EFBFBD>re
|
2008-01-08 14:52:32 +01:00
|
|
|
|
* Authors: Antoine Fraboulet <antoine.fraboulet @@ free.fr>
|
|
|
|
|
* Olivier Teuli<EFBFBD>re <ipkiss @@ gmail.com>
|
2005-02-05 12:14:56 +01:00
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-23 16:53:42 +02:00
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-02-05 12:14:56 +01:00
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
#include <wctype.h>
|
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
|
#include <dic.h>
|
|
|
|
|
#include "tile.h"
|
|
|
|
|
#include "board.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
|
static void Board_checkout_tile(const Dictionary &iDic,
|
|
|
|
|
vector<Tile>& iTiles,
|
|
|
|
|
vector<bool> & iJoker,
|
|
|
|
|
Cross &oCross,
|
|
|
|
|
int& oPoints,
|
|
|
|
|
int index)
|
|
|
|
|
{
|
|
|
|
|
oPoints = 0;
|
|
|
|
|
|
|
|
|
|
/* Points on the left part */
|
2012-02-18 21:19:42 +01:00
|
|
|
|
int left = index;
|
2006-11-05 14:30:06 +01:00
|
|
|
|
while (!iTiles[left - 1].isEmpty())
|
2005-02-05 12:14:56 +01:00
|
|
|
|
{
|
2006-11-05 14:30:06 +01:00
|
|
|
|
left--;
|
|
|
|
|
if (!iJoker[left])
|
|
|
|
|
oPoints += iTiles[left].getPoints();
|
2005-02-05 12:14:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-05 14:30:06 +01:00
|
|
|
|
// FIXME: create temporary strings until the dictionary uses Tile objects
|
2012-06-18 21:21:40 +02:00
|
|
|
|
wstring leftTiles;
|
|
|
|
|
wstring rightTiles;
|
2006-11-05 14:30:06 +01:00
|
|
|
|
|
2012-02-18 21:19:42 +01:00
|
|
|
|
for (int i = left; i < index; i++)
|
2012-06-18 21:21:40 +02:00
|
|
|
|
leftTiles.push_back(towupper(iTiles[i].toChar()));
|
2006-11-05 14:30:06 +01:00
|
|
|
|
|
2012-06-18 21:21:40 +02:00
|
|
|
|
for (int i = index + 1; !iTiles[i].isEmpty(); i++)
|
|
|
|
|
rightTiles.push_back(towupper(iTiles[i].toChar()));
|
2006-11-05 14:30:06 +01:00
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
|
/* Tiles that can be played */
|
2012-02-18 21:19:42 +01:00
|
|
|
|
unsigned int node, succ;
|
2012-06-18 21:21:40 +02:00
|
|
|
|
node = iDic.charLookup(iDic.getRoot(), leftTiles.c_str());
|
2006-12-23 14:50:43 +01:00
|
|
|
|
if (node == 0)
|
2005-02-05 12:14:56 +01:00
|
|
|
|
{
|
2006-11-05 14:30:06 +01:00
|
|
|
|
oCross.setNone();
|
2005-02-05 12:14:56 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
for (succ = iDic.getSucc(node); succ; succ = iDic.getNext(succ))
|
2005-02-05 12:14:56 +01:00
|
|
|
|
{
|
2012-06-18 21:21:40 +02:00
|
|
|
|
if (iDic.isEndOfWord(iDic.charLookup(succ, rightTiles.c_str())))
|
2008-01-08 14:52:32 +01:00
|
|
|
|
oCross.insert(Tile(iDic.getChar(succ)));
|
|
|
|
|
if (iDic.isLast(succ))
|
2005-02-05 12:14:56 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-01 20:37:26 +01:00
|
|
|
|
/* Points on the right part */
|
2008-01-08 14:52:32 +01:00
|
|
|
|
/* yes, it is REALLY [index + 1] */
|
|
|
|
|
while (!iTiles[index + 1].isEmpty())
|
2006-01-01 20:37:26 +01:00
|
|
|
|
{
|
2006-12-23 14:50:43 +01:00
|
|
|
|
index++;
|
|
|
|
|
if (!iJoker[index])
|
|
|
|
|
oPoints += iTiles[index].getPoints();
|
2006-01-01 20:37:26 +01:00
|
|
|
|
}
|
2005-02-05 12:14:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void Board_check(const Dictionary &iDic,
|
|
|
|
|
Matrix<Tile> &iTilesMx,
|
|
|
|
|
Matrix<bool> &iJokerMx,
|
|
|
|
|
Matrix<Cross> &iCrossMx,
|
|
|
|
|
Matrix<int> &iPointMx)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 1; i <= BOARD_DIM; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 1; j <= BOARD_DIM; j++)
|
|
|
|
|
{
|
|
|
|
|
iPointMx[j][i] = -1;
|
2005-02-17 21:01:59 +01:00
|
|
|
|
if (!iTilesMx[i][j].isEmpty())
|
2006-01-01 20:37:26 +01:00
|
|
|
|
{
|
2006-11-05 14:30:06 +01:00
|
|
|
|
iCrossMx[j][i].setNone();
|
2008-01-08 14:52:32 +01:00
|
|
|
|
}
|
2005-02-17 21:01:59 +01:00
|
|
|
|
else if (!iTilesMx[i][j - 1].isEmpty() ||
|
|
|
|
|
!iTilesMx[i][j + 1].isEmpty())
|
2005-02-05 12:14:56 +01:00
|
|
|
|
{
|
2006-11-05 14:30:06 +01:00
|
|
|
|
iCrossMx[j][i].setNone();
|
2005-02-05 12:14:56 +01:00
|
|
|
|
Board_checkout_tile(iDic,
|
|
|
|
|
iTilesMx[i],
|
|
|
|
|
iJokerMx[i],
|
|
|
|
|
iCrossMx[j][i],
|
|
|
|
|
iPointMx[j][i],
|
|
|
|
|
j);
|
|
|
|
|
}
|
|
|
|
|
else
|
2006-01-01 20:37:26 +01:00
|
|
|
|
{
|
2005-02-05 12:14:56 +01:00
|
|
|
|
iCrossMx[j][i].setAny();
|
2008-01-08 14:52:32 +01:00
|
|
|
|
}
|
2005-02-05 12:14:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Board::buildCross(const Dictionary &iDic)
|
|
|
|
|
{
|
|
|
|
|
Board_check(iDic, m_tilesRow, m_jokerRow, m_crossCol, m_pointCol);
|
|
|
|
|
Board_check(iDic, m_tilesCol, m_jokerCol, m_crossRow, m_pointRow);
|
|
|
|
|
}
|
2006-01-01 20:37:26 +01:00
|
|
|
|
|