Commit 4539bd30 by Inge Wallin

### Integrate the new reversi logic into the Engine.

```Basically this more or less means that it now returns a Reversi::Move instead
of a KReversiPos.```
parent d1ec9049
 ... ... @@ -314,11 +314,11 @@ void Engine::yield() // Calculate the best move from the current position, and return it. KReversiPos Engine::computeMove(const KReversiGame& game, 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."; return KReversiPos(); kDebug() << "I'm already computing move! Yours KReversi Engine."; return Move(); } m_computingMove = true; ... ... @@ -337,7 +337,7 @@ KReversiPos Engine::computeMove(const KReversiGame& game, Color color, bool comp // Check the color to get the move for. if (color == NoColor) { m_computingMove = false; return KReversiPos(); return Move(); } // Figure out the current score ... ... @@ -480,18 +480,18 @@ KReversiPos Engine::computeMove(const KReversiGame& game, Color color, bool comp m_computingMove = false; // Return a suitable move. if (interrupted()) return KReversiPos(NoColor, -1, -1); return Move(NoColor, -1, -1); else if (maxval != -LARGEINT) return KReversiPos(color, max_y-1, max_x-1); return Move(color, max_y-1, max_x-1); else return KReversiPos(NoColor, -1, -1); return Move(NoColor, -1, -1); } // Get the first move. We can pick any move at random. // KReversiPos Engine::ComputeFirstMove(const KReversiGame& game) Move Engine::ComputeFirstMove(const KReversiGame& game) { int r; Color color = game.currentPlayer(); ... ... @@ -499,16 +499,16 @@ KReversiPos Engine::ComputeFirstMove(const KReversiGame& game) r = m_random.getLong(4) + 1; if (color == White) { if (r == 1) return KReversiPos(color, 4, 2); else if (r == 2) return KReversiPos(color, 5, 3); else if (r == 3) return KReversiPos(color, 2, 4); else return KReversiPos(color, 3, 5); if (r == 1) return Move(color, 4, 2); else if (r == 2) return Move(color, 5, 3); else if (r == 3) return Move(color, 2, 4); else return Move(color, 3, 5); } else { if (r == 1) return KReversiPos(color, 3, 2); else if (r == 2) return KReversiPos(color, 5, 4); else if (r == 3) return KReversiPos(color, 2, 3); else return KReversiPos(color, 4, 5); if (r == 1) return Move(color, 3, 2); else if (r == 2) return Move(color, 5, 4); else if (r == 3) return Move(color, 2, 3); else return Move(color, 4, 5); } } ... ... @@ -525,7 +525,7 @@ int Engine::ComputeMove2(int xplay, int yplay, Color color, int level, { int number_of_turned = 0; SquareStackEntry mse; Color opponent = opponentColorFor(color); Color opponent = opponentColorFor(color); m_nodesSearched++; ... ...
 ... ... @@ -195,16 +195,18 @@ class Engine ~Engine(); KReversiPos computeMove(const KReversiGame& game, Color color, bool competitive); bool isThinking() const { return m_computingMove; } Move computeMove(const KReversiGame& game, Color color, bool competitive); bool isThinking() const { return m_computingMove; } void setInterrupt(bool intr) { m_interrupt = intr; } bool interrupted() const { return m_interrupt; } void setStrength(uint strength) { m_strength = strength; } uint strength() const { return m_strength; } private: KReversiPos ComputeFirstMove(const KReversiGame& game); // These are all helper functions. Move ComputeFirstMove(const KReversiGame& game); int ComputeMove2(int xplay, int yplay, Color color, int level, int utoffval, quint64 colorbits, quint64 opponentbits); ... ...
 ... ... @@ -38,6 +38,10 @@ Enhancements to the view Structural enhancements * Improve separation of engine + game logic from the UI ---- This will let us create a QML based UI for Plasma Active + Collect all reversi logic into its own file Done + Integrate the separated reversi logic into engine Done + Integrate the separated reversi logic into game ---- + 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 ---- ... ...
 ... ... @@ -61,11 +61,13 @@ void KReversiGame::makePlayerMove(int row, int col, bool demoMode) m_curPlayer = m_playerColor; KReversiPos move; Move move2; if (!demoMode) move = KReversiPos(m_playerColor, row, col); else { move = m_engine->computeMove(*this, m_playerColor, true); move2 = m_engine->computeMove(*this, m_playerColor, true); move = KReversiPos(move2.color, move2.row, move2.col); if (!move.isValid()) return; } ... ... @@ -121,7 +123,8 @@ void KReversiGame::makeComputerMove() m_curPlayer = m_computerColor; // FIXME dimsuz: m_competitive. Read from config. // (also there's computeMove in getHint) KReversiPos move = m_engine->computeMove(*this, 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; ... ... @@ -522,7 +525,8 @@ void KReversiGame::setComputerSkill(int skill) KReversiPos KReversiGame::getHint() const { // FIXME dimsuz: don't use true, use m_competitive return m_engine->computeMove(*this, m_playerColor, true); Move move = m_engine->computeMove(*this, m_playerColor, true); return KReversiPos(move.color, move.row, move.col); } KReversiPos KReversiGame::getLastMove() const ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!