Commit 94ee18b9 authored by Inge Wallin's avatar Inge Wallin
Browse files

Revert "Better separation between KReversiGame and the Engine."

This reverts commit 6a31d037.
parent 6a31d037
......@@ -264,11 +264,11 @@ static const int ILLEGAL_VALUE = 8888888;
static const int BC_WEIGHT = 3;
Engine::Engine(int strength, int seed)/* : SuperEngine(st, sd) */
: m_strength(strength)
Engine::Engine(int st, int sd)/* : SuperEngine(st, sd) */
: m_strength(st)
, m_computingMove(false)
{
m_random.setSeed(seed);
m_random.setSeed(sd);
m_score = new Score;
m_bc_score = new Score;
SetupBcBoard();
......@@ -276,8 +276,8 @@ Engine::Engine(int strength, int seed)/* : SuperEngine(st, sd) */
}
Engine::Engine(int strength)
: m_strength(strength)
Engine::Engine(int st)
: m_strength(st)
, m_computingMove(false)
{
m_random.setSeed(0);
......@@ -288,7 +288,7 @@ Engine::Engine(int strength)
}
Engine::Engine()
Engine::Engine()// : SuperEngine(1)
: m_strength(1)
, m_computingMove(false)
{
......@@ -314,7 +314,7 @@ void Engine::yield()
// Calculate the best move from the current position, and return it.
Move Engine::computeMove(const Position &position, Color color, bool competitive)
Move Engine::computeMove(const KReversiGame& game, Color color, bool competitive)
{
if (m_computingMove) {
kDebug() << "I'm already computing move! Yours KReversi Engine.";
......@@ -341,14 +341,14 @@ Move Engine::computeMove(const Position &position, Color color, bool competitive
}
// Figure out the current score
m_score->set(White, position.playerScore(White));
m_score->set(Black, position.playerScore(Black));
m_score->set(White, game.playerScore(White));
m_score->set(Black, game.playerScore(Black));
// Treat the first move as a special case (we can basically just
// pick a move at random).
if (m_score->score(White) + m_score->score(Black) == 4) {
m_computingMove = false;
return ComputeFirstMove(color);
return ComputeFirstMove(game);
}
// Let there be room for 3000 changes during the recursive search.
......@@ -385,7 +385,7 @@ Move Engine::computeMove(const Position &position, Color color, bool competitive
for (uint y = 0; y < 10; y++) {
if (1 <= x && x <= 8
&& 1 <= y && y <= 8)
m_board[x][y] = position.colorAt(y-1, x-1);
m_board[x][y] = game.chipColorAt(y-1, x-1);
else
m_board[x][y] = NoColor;
}
......@@ -491,9 +491,12 @@ Move Engine::computeMove(const Position &position, Color color, bool competitive
// Get the first move. We can pick any move at random.
//
Move Engine::ComputeFirstMove(Color color)
Move Engine::ComputeFirstMove(const KReversiGame& game)
{
int r = m_random.getLong(4) + 1;
int r;
Color color = game.currentPlayer();
r = m_random.getLong(4) + 1;
if (color == White) {
if (r == 1) return Move(color, 4, 2);
......
......@@ -195,7 +195,7 @@ class Engine
~Engine();
Move computeMove(const Position& position, Color color, bool competitive);
Move computeMove(const KReversiGame& game, Color color, bool competitive);
bool isThinking() const { return m_computingMove; }
void setInterrupt(bool intr) { m_interrupt = intr; }
......@@ -206,7 +206,7 @@ class Engine
private:
// These are all helper functions.
Move ComputeFirstMove(Color color);
Move ComputeFirstMove(const KReversiGame& game);
int ComputeMove2(int xplay, int yplay, Color color, int level,
int utoffval,
quint64 colorbits, quint64 opponentbits);
......
......@@ -44,7 +44,7 @@ Structural enhancements
+ Integrate the separated reversi logic into view ----
+ Remove all mentions of "Player" and "Computer" from KReversiGame ----
This should be strictly about the game, using only Black/White
+ Remove all mentions of "Player" and "Computer" from the engine Done
+ Remove all mentions of "Player" and "Computer" from the engine ----
This should go to KReversiView (or perhaps introduce a new
class for that)
......
......@@ -66,7 +66,7 @@ void KReversiGame::makePlayerMove(int row, int col, bool demoMode)
if (!demoMode)
move = KReversiPos(m_playerColor, row, col);
else {
move2 = m_engine->computeMove(m_position, m_playerColor, true);
move2 = m_engine->computeMove(*this, m_playerColor, true);
move = KReversiPos(move2.color, move2.row, move2.col);
if (!move.isValid())
return;
......@@ -123,7 +123,7 @@ void KReversiGame::makeComputerMove()
m_curPlayer = m_computerColor;
// FIXME dimsuz: m_competitive. Read from config.
// (also there's computeMove in getHint)
Move move2 = m_engine->computeMove(m_position, m_computerColor, true);
Move move2 = m_engine->computeMove(*this, m_computerColor, true);
KReversiPos move = KReversiPos(move2.color, move2.row, move2.col);
if (!move.isValid())
return;
......@@ -525,7 +525,7 @@ void KReversiGame::setComputerSkill(int skill)
KReversiPos KReversiGame::getHint() const
{
// FIXME dimsuz: don't use true, use m_competitive
Move move = m_engine->computeMove(m_position, m_playerColor, true);
Move move = m_engine->computeMove(*this, m_playerColor, true);
return KReversiPos(move.color, move.row, move.col);
}
......
......@@ -189,8 +189,6 @@ private:
* Sets the type of chip at (row,col)
*/
void setColor(Color type, int row, int col);
// The actual game (this is the part that will be switched to the new code).
/**
* The board itself
*/
......@@ -203,8 +201,6 @@ private:
* Color of the current player
*/
Color m_curPlayer;
// Values from the UI
/**
* The color of the human played chips
*/
......@@ -230,7 +226,7 @@ private:
// New code
/**
* The current position of the game.
* The current position.
*/
Position m_position;
......
......@@ -208,6 +208,10 @@ public:
bool undoMove(Move &move, bool checkFirst = true);
private:
enum Direction {
Up, Down, Right, Left, UpLeft, UpRight, DownLeft, DownRight,
LastDirection // Sentinel to be used for loop counters only
};
/**
* Searches for a "chunk" of opponent pieces in direction dir.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment