File indexing completed on 2022-11-29 18:40:56

0001 /*
0002     SPDX-FileCopyrightText: 2013 Denis Kuplyakov <dener.kup@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kreversicomputerplayer.h"
0008 
0009 KReversiComputerPlayer::KReversiComputerPlayer(ChipColor color, const QString &name):
0010     KReversiPlayer(color, name, false, false), m_lowestSkill(100) // setting it big enough
0011 {
0012     m_engine = new Engine(1);
0013 }
0014 
0015 KReversiComputerPlayer::~KReversiComputerPlayer()
0016 {
0017     delete m_engine;
0018 }
0019 
0020 void KReversiComputerPlayer::prepare(KReversiGame *game)
0021 {
0022     m_game = game;
0023     m_state = WAITING;
0024 
0025     Q_EMIT ready();
0026 }
0027 
0028 void KReversiComputerPlayer::takeTurn()
0029 {
0030     m_state = THINKING;
0031     KReversiMove move = m_engine->computeMove(*m_game, true);
0032     move.color = m_color;
0033     m_state = WAITING;
0034     Q_EMIT makeMove(move);
0035 }
0036 
0037 void KReversiComputerPlayer::skipTurn()
0038 {
0039     m_state = WAITING;
0040 }
0041 
0042 void KReversiComputerPlayer::gameOver()
0043 {
0044     m_state = UNKNOWN;
0045 }
0046 
0047 void KReversiComputerPlayer::setSkill(int skill)
0048 {
0049     m_engine->setStrength(skill);
0050     m_lowestSkill = qMin(m_lowestSkill, skill);
0051 }
0052 
0053 int KReversiComputerPlayer::lowestSkill()
0054 {
0055     return m_lowestSkill;
0056 }
0057 
0058