1/*******************************************************************
2 *
3 * Copyright 2013 Denis Kuplyakov <dener.kup@gmail.com>
4 *
5 * This file is part of the KDE project "KReversi"
6 *
7 * KReversi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * KReversi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with KReversi; see the file COPYING. If not, write to
19 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 ********************************************************************/
23
24#include <kreversicomputerplayer.h>
25
26KReversiComputerPlayer::KReversiComputerPlayer(ChipColor color, QString name):
27 KReversiPlayer(color, name, false, false), m_lowestSkill(100) // setting it big enough
28{
29 m_engine = new Engine(1);
30}
31
32KReversiComputerPlayer::~KReversiComputerPlayer()
33{
34 delete m_engine;
35}
36
37void KReversiComputerPlayer::prepare(KReversiGame *game)
38{
39 m_game = game;
40 m_state = WAITING;
41
42 emit ready();
43}
44
45void KReversiComputerPlayer::takeTurn()
46{
47 m_state = THINKING;
48 KReversiMove move = m_engine->computeMove(*m_game, true);
49 move.color = m_color;
50 m_state = WAITING;
51 emit makeMove(move);
52}
53
54void KReversiComputerPlayer::skipTurn()
55{
56 m_state = WAITING;
57}
58
59void KReversiComputerPlayer::gameOver()
60{
61 m_state = UNKNOWN;
62}
63
64void KReversiComputerPlayer::setSkill(int skill)
65{
66 m_engine->setStrength(skill);
67 m_lowestSkill = qMin(m_lowestSkill, skill);
68}
69
70int KReversiComputerPlayer::lowestSkill()
71{
72 return m_lowestSkill;
73}
74
75
76