2005-02-17 21:01:59 +01:00
|
|
|
/*****************************************************************************
|
2008-01-08 14:52:32 +01:00
|
|
|
* Eliot
|
2009-01-24 18:44:56 +01:00
|
|
|
* Copyright (C) 2005-2009 Olivier Teulière
|
2008-01-08 14:52:32 +01:00
|
|
|
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
2005-02-17 21:01:59 +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-17 21:01:59 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "tile.h"
|
|
|
|
#include "rack.h"
|
|
|
|
#include "pldrack.h"
|
|
|
|
#include "round.h"
|
2008-01-08 14:52:32 +01:00
|
|
|
#include "move.h"
|
2005-02-17 21:01:59 +01:00
|
|
|
#include "results.h"
|
|
|
|
#include "board.h"
|
|
|
|
#include "ai_percent.h"
|
|
|
|
|
|
|
|
|
2008-01-28 20:17:33 +01:00
|
|
|
AIPercent::AIPercent(float iPercent)
|
2005-02-17 21:01:59 +01:00
|
|
|
{
|
2009-01-22 19:30:22 +01:00
|
|
|
if (iPercent < 0)
|
|
|
|
iPercent = 0;
|
|
|
|
if (iPercent > 1)
|
|
|
|
iPercent = 1;
|
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
m_percent = iPercent;
|
|
|
|
|
2009-01-22 19:30:22 +01:00
|
|
|
// Use BestResults to be slightly faster when the percentage is 100%
|
|
|
|
if (iPercent == 1)
|
|
|
|
m_results = new BestResults;
|
|
|
|
else
|
|
|
|
m_results = new PercentResults(iPercent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AIPercent::~AIPercent()
|
|
|
|
{
|
|
|
|
delete m_results;
|
2005-02-17 21:01:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-22 15:40:25 +01:00
|
|
|
void AIPercent::compute(const Dictionary &iDic, const Board &iBoard, bool iFirstWord)
|
2005-02-17 21:01:59 +01:00
|
|
|
{
|
2009-01-22 19:30:22 +01:00
|
|
|
m_results->clear();
|
2005-02-17 21:01:59 +01:00
|
|
|
|
|
|
|
Rack rack;
|
|
|
|
getCurrentRack().getRack(rack);
|
2009-01-22 19:30:22 +01:00
|
|
|
m_results->search(iDic, iBoard, rack, iFirstWord);
|
2005-02-17 21:01:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
Move AIPercent::getMove() const
|
2005-02-17 21:01:59 +01:00
|
|
|
{
|
2009-01-22 19:30:22 +01:00
|
|
|
if (m_results->size() == 0)
|
2008-01-08 14:52:32 +01:00
|
|
|
{
|
2008-11-30 22:09:37 +01:00
|
|
|
// If there is no result, pass the turn.
|
2008-01-19 20:33:08 +01:00
|
|
|
// XXX: it is forbidden in duplicate mode (even passing is forbidden),
|
|
|
|
// but well, what else to do?
|
2008-11-30 22:09:37 +01:00
|
|
|
return Move(L"");
|
2008-01-08 14:52:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-22 19:30:22 +01:00
|
|
|
return Move(m_results->get(0));
|
2008-01-08 14:52:32 +01:00
|
|
|
}
|
2005-02-17 21:01:59 +01:00
|
|
|
}
|
|
|
|
|