diff options
author | Jason Katz-Brown <jason@airbnb.com> | 2013-08-25 02:17:13 -0700 |
---|---|---|
committer | Jason Katz-Brown <jason@airbnb.com> | 2013-08-25 02:17:13 -0700 |
commit | 9306cb60c32082c5403931de0823a9fd5daa196c (patch) | |
tree | ca1b6eb695fdf3f0c2294e92416b272164bae642 /computerplayer.cpp | |
parent | 8fb2c681cecc01b46b0f4ba02d5cc177c4747b1c (diff) |
Initial git commit.
Diffstat (limited to 'computerplayer.cpp')
-rw-r--r-- | computerplayer.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/computerplayer.cpp b/computerplayer.cpp new file mode 100644 index 0000000..c19877a --- /dev/null +++ b/computerplayer.cpp @@ -0,0 +1,112 @@ +/* + * Quackle -- Crossword game artificial intelligence and analysis tool + * Copyright (C) 2005-2006 Jason Katz-Brown and John O'Laughlin. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "computerplayer.h" +#include "endgameplayer.h" + +using namespace Quackle; + +ComputerPlayer::ComputerPlayer() + : m_name(MARK_UV("Computer Player")), m_id(0), m_dispatch(0) +{ + m_parameters.secondsPerTurn = 10; + m_parameters.inferring = false; +} + +ComputerPlayer::~ComputerPlayer() +{ +} + +void ComputerPlayer::setDispatch(ComputerDispatch *dispatch) +{ + m_dispatch = dispatch; + m_simulator.setDispatch(dispatch); +} + +void ComputerPlayer::setPosition(const GamePosition &position) +{ + m_simulator.setPosition(position); +} + +bool ComputerPlayer::shouldAbort() +{ + return m_dispatch && m_dispatch->shouldAbort(); +} + +void ComputerPlayer::signalFractionDone(double fractionDone) +{ + if (m_dispatch) + m_dispatch->signalFractionDone(fractionDone); +} + +void ComputerPlayer::considerMove(const Move &move) +{ + m_simulator.addConsideredMove(move); +} + +void ComputerPlayer::setConsideredMoves(const MoveList &moves) +{ + m_simulator.setConsideredMoves(moves); +} + +MoveList ComputerPlayer::moves(int /* nmoves */) +{ + MoveList ret; + ret.push_back(move()); + return ret; +} + +/////// + +StaticPlayer::StaticPlayer() +{ + m_name = MARK_UV("Static Player"); + m_id = 1; +} + +StaticPlayer::~StaticPlayer() +{ +} + +Move StaticPlayer::move() +{ + return m_simulator.currentPosition().staticBestMove(); +} + +MoveList StaticPlayer::moves(int nmoves) +{ + m_simulator.currentPosition().kibitz(nmoves); + return m_simulator.currentPosition().moves(); +} + +ScalingDispatch::ScalingDispatch(ComputerDispatch *shadow, double scale, double addition) + : m_shadow(shadow), m_scale(scale), m_addition(addition) +{ +} + +bool ScalingDispatch::shouldAbort() +{ + return m_shadow->shouldAbort(); +} + +void ScalingDispatch::signalFractionDone(double fractionDone) +{ + m_shadow->signalFractionDone(fractionDone * m_scale + m_addition); +} |