Commit f032a101 authored by Inge Wallin's avatar Inge Wallin

Revert "Establish coding standards step II."

This reverts commit 8cd91fed.
parent f8ec6394
......@@ -115,18 +115,11 @@
// or nearly equal value after the search is completed.
// Own
#include "Engine.h"
// Qt
#include "kreversigame.h"
#include <QApplication>
// KDE
#include <KDebug>
// Kreversi
#include "kreversigame.h"
// ================================================================
// Classes SquareStackEntry and SquareStack
......@@ -173,6 +166,7 @@ void SquareStack::resize(int size)
// (Re)initialize the stack so that is empty, and at the same time
// resize it to 'size'.
//
void SquareStack::init(int size)
{
resize(size);
......@@ -215,7 +209,7 @@ inline void MoveAndValue::setXYV(int x, int y, int value)
MoveAndValue::MoveAndValue()
{
setXYV(0, 0, 0);
setXYV(0,0,0);
}
......@@ -227,7 +221,6 @@ MoveAndValue::MoveAndValue(int x, int y, int value)
// ================================================================
// class Score
/* This class keeps track of the score for both colors. Such a score
* could be either the number of pieces, the score from the evaluation
* function or anything similar.
......@@ -276,7 +269,7 @@ Engine::Engine(int st, int sd)/* : SuperEngine(st, sd) */
}
Engine::Engine(int st)
Engine::Engine(int st) //: SuperEngine(st)
: m_strength(st)
, m_computingMove(false)
{
......@@ -420,13 +413,13 @@ KReversiPos Engine::computeMove(const KReversiGame& game, bool competitive)
// The main search loop. Step through all possible moves and keep
// track of the most valuable one. This move is stored in
// (max_x, max_y) and the value is stored in maxval.
m_nodesSearched = 0;
m_nodes_searched = 0;
for (int x = 1; x < 9; x++) {
for (int y = 1; y < 9; y++) {
// Don't bother with non-empty squares and squares that aren't
// neighbors to opponent pieces.
if (m_board[x][y] != NoColor
|| (m_neighborBits[x][y] & opponentbits) == null_bits)
|| (m_neighbor_bits[x][y] & opponentbits) == null_bits)
continue;
int val = ComputeMove2(x, y, color, 1, maxval, colorbits, opponentbits);
......@@ -530,11 +523,11 @@ int Engine::ComputeMove2(int xplay, int yplay, ChipColor color, int level,
SquareStackEntry mse;
ChipColor opponent = opponentColorFor(color);
m_nodesSearched++;
m_nodes_searched++;
// Put the piece on the board and incrementally update scores and bitmaps.
m_board[xplay][yplay] = color;
colorbits |= m_coordBit[xplay][yplay];
colorbits |= m_coord_bit[xplay][yplay];
m_score->inc(color);
m_bc_score->add(color, m_bc_board[xplay][yplay]);
......@@ -558,8 +551,8 @@ int Engine::ComputeMove2(int xplay, int yplay, ChipColor color, int level,
for (x -= xinc, y -= yinc; x != xplay || y != yplay;
x -= xinc, y -= yinc) {
m_board[x][y] = color;
colorbits |= m_coordBit[x][y];
opponentbits &= ~m_coordBit[x][y];
colorbits |= m_coord_bit[x][y];
opponentbits &= ~m_coord_bit[x][y];
m_squarestack.Push(x, y);
......@@ -660,7 +653,7 @@ int Engine::TryAllMoves(ChipColor opponent, int level, int cutoffval,
for (int x = 1; x < 9; x++) {
for (int y = 1; y < 9; y++) {
if (m_board[x][y] == NoColor
&& (m_neighborBits[x][y] & colorbits) != null_bits) {
&& (m_neighbor_bits[x][y] & colorbits) != null_bits) {
int val = ComputeMove2(x, y, opponent, level+1, maxval, opponentbits, colorbits);
if (val != ILLEGAL_VALUE && val > maxval) {
......@@ -716,8 +709,8 @@ int Engine::EvaluatePosition(ChipColor color)
void Engine::SetupBits()
{
//m_coordBit = new long[9][9];
//m_neighborBits = new long[9][9];
//m_coord_bit = new long[9][9];
//m_neighbor_bits = new long[9][9];
quint64 bits = 1;
......@@ -725,20 +718,20 @@ void Engine::SetupBits()
// each square.
for (int i=1; i < 9; i++)
for (int j=1; j < 9; j++) {
m_coordBit[i][j] = bits;
m_coord_bit[i][j] = bits;
bits *= 2;
}
// Store a bitmap consisting of all neighbors for each square.
for (int i=1; i < 9; i++)
for (int j=1; j < 9; j++) {
m_neighborBits[i][j] = 0;
m_neighbor_bits[i][j] = 0;
for (int xinc=-1; xinc<=1; xinc++)
for (int yinc=-1; yinc<=1; yinc++) {
if (xinc != 0 || yinc != 0)
if (i + xinc > 0 && i + xinc < 9 && j + yinc > 0 && j + yinc < 9)
m_neighborBits[i][j] |= m_coordBit[i + xinc][j + yinc];
m_neighbor_bits[i][j] |= m_coord_bit[i + xinc][j + yinc];
}
}
}
......@@ -804,7 +797,7 @@ quint64 Engine::ComputeOccupiedBits(ChipColor color)
for (int i=1; i < 9; i++)
for (int j=1; j < 9; j++)
if (m_board[i][j] == color) retval |= m_coordBit[i][j];
if (m_board[i][j] == color) retval |= m_coord_bit[i][j];
return retval;
}
......
......@@ -119,18 +119,18 @@
#ifndef KREVERSI_ENGINE_H
#define KREVERSI_ENGINE_H
// Qt
#include <QVector>
//#include "SuperEngine.h"
//#include "Position.h"
//#include "Game.h"
//#include "Move.h"
//#include "Score.h"
// KDE
#include <QVector>
#include <krandomsequence.h>
// KReversi
#include "commondefs.h"
class KReversiGame;
static ChipColor opponentColorFor(ChipColor color)
{
if (color == NoColor)
......@@ -169,7 +169,7 @@ class SquareStack
private:
QVector<SquareStackEntry> m_squarestack;
int m_top;
int m_top;
};
......@@ -212,10 +212,10 @@ class Engine
void setStrength(uint strength) { m_strength = strength; }
uint strength() const { return m_strength; }
private:
KReversiPos ComputeFirstMove(const KReversiGame& game);
KReversiPos ComputeFirstMove(const KReversiGame& game);
int ComputeMove2(int xplay, int yplay, ChipColor color, int level,
int utoffval,
quint64 colorbits, quint64 opponentbits);
int cutoffval,
quint64 colorbits, quint64 opponentbits);
int TryAllMoves(ChipColor opponent, int level, int cutoffval,
quint64 opponentbits, quint64 colorbits);
......@@ -230,15 +230,15 @@ class Engine
private:
ChipColor m_board[10][10];
ChipColor m_board[10][10];
int m_bc_board[9][9];
Score* m_score;
Score* m_bc_score;
Score* m_score;
Score* m_bc_score;
SquareStack m_squarestack;
int m_depth;
int m_coeff;
int m_nodesSearched;
int m_nodes_searched;
bool m_exhaustive;
bool m_competitive;
......@@ -246,8 +246,8 @@ class Engine
KRandomSequence m_random;
bool m_interrupt;
quint64 m_coordBit[9][9];
quint64 m_neighborBits[9][9];
quint64 m_coord_bit[9][9];
quint64 m_neighbor_bits[9][9];
bool m_computingMove;
};
......
......@@ -15,16 +15,14 @@ Legend
----------------------------------------------------------------
Fix important bugs
* All crashes DONE
* All crashes ----
*
Cleanup
* Establish coding standards ----
+ Create a HACKING file that describes this (copy Krita's) ----
+ Enforce unified indentation, braces, parenthesis, etc Done
+ Enforce unified variable naming (fooBar instead of foo_bar) Done
+ Fix comments (real sentences, add missing comments) ----
+ Name files consistently ----
+ Enforce unified variable naming (fooBar instead of foo_bar) ----
General enhancements
* Make it possible to play white -----
......@@ -38,8 +36,6 @@ 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
+ Remove all mentions of "Player" and "Computer" from KReversiGame ----
This should be strictly about the game, using only Black/White
Documentation
* Rewrite DESIGN totally. DONE
......
......@@ -18,13 +18,9 @@
#ifndef COLORSCHEME_H
#define COLORSCHEME_H
// Qt
#include <QDeclarativeItem>
#include <QColor>
// KDE
#include <KColorScheme>
#include <QColor>
class ColorScheme : public QDeclarativeItem
{
......
......@@ -20,7 +20,6 @@
* Boston, MA 02110-1301, USA.
*
********************************************************************/
#ifndef COMMONDEFS_H
#define COMMONDEFS_H
......
......@@ -17,16 +17,12 @@
*/
// Own
#include "highscores.h"
// Qt
#include <QVector>
#include <QDateTime>
// KDE
#include <klocale.h>
#include <kconfig.h>
#include <QVector>
#include <QDateTime>
#include <kglobal.h>
#include <kconfiggroup.h>
......
......@@ -20,12 +20,9 @@
#ifndef HIGHSCORES_H
#define HIGHSCORES_H
// Qt
#include <QStringList>
// KDE
#include <kexthighscore.h>
#include <kdemacros.h>
#include <QStringList>
namespace KExtHighscore
{
......
......@@ -21,16 +21,12 @@
*
********************************************************************/
// Own
#include "kreversigame.h"
// KDE
#include <kdebug.h>
// KReversi
#include "Engine.h"
KReversiGame::KReversiGame()
: m_curPlayer(Black)
, m_playerColor(Black)
......@@ -54,7 +50,6 @@ KReversiGame::~KReversiGame()
delete m_engine;
}
void KReversiGame::makePlayerMove(int row, int col, bool demoMode)
{
m_curPlayer = m_playerColor;
......
......@@ -20,15 +20,12 @@
* Boston, MA 02110-1301, USA.
*
********************************************************************/
#ifndef KREVERSI_GAME_H
#define KREVERSI_GAME_H
// Qt
#include <QObject>
#include <QStack>
// KReversi
#include "commondefs.h"
class Engine;
......@@ -150,14 +147,12 @@ public:
* @return a list of possible moves for current player
*/
PosList possibleMoves() const;
signals:
void gameOver();
void boardChanged();
void moveFinished();
void computerCantMove();
void playerCantMove();
private:
enum Direction { Up, Down, Right, Left, UpLeft, UpRight, DownLeft, DownRight };
/**
......@@ -204,12 +199,14 @@ private:
* The color of the computer played chips
*/
ChipColor m_computerColor;
/**
* Our AI
*/
Engine *m_engine;
// Well I'm not brief at all :). That's because I think that my
// English is not well shaped sometimes, so I try to describe things
// so that me and others can understand. Even simple things.
// Specially when I think that my description sucks :)
/**
* This list holds chips that were changed/added during last move
* First of them will be the chip added to the board by the player
......@@ -217,7 +214,6 @@ private:
* move.
*/
PosList m_changedChips;
/**
* This is an undo stack.
* It contains a lists of chips changed with each turn.
......@@ -225,5 +221,4 @@ private:
*/
QStack<PosList> m_undoStack;
};
#endif
......@@ -38,13 +38,14 @@ KReversiView::KReversiView(KReversiGame* game, QWidget *parent)
m_provider->discoverThemes("appdata", QLatin1String("pics"));
m_provider->setDeclarativeEngine("themeProvider", engine());
QString path = KStandardDirs::locate("appdata", QLatin1String("qml/Table.qml"));
QString path =
KStandardDirs::locate("appdata", QLatin1String("qml/Table.qml"));
setSource(QUrl::fromLocalFile(path));
m_qmlRoot = (QObject*) rootObject();
m_qml_root = (QObject*) rootObject();
rootContext()->setContextProperty("container", this);
connect(m_qmlRoot, SIGNAL(cellClicked(int,int)),
connect(m_qml_root, SIGNAL(cellClicked(int,int)),
this, SLOT(onPlayerMove(int,int)));
setGame(game);
}
......@@ -80,7 +81,7 @@ void KReversiView::setGame(KReversiGame *game)
void KReversiView::setChipsPrefix(const QString &chipsPrefix)
{
m_qmlRoot->setProperty("chipsImagePrefix", chipsPrefix);
m_qml_root->setProperty("chipsImagePrefix", chipsPrefix);
}
void KReversiView::setShowBoardLabels(bool show)
......@@ -107,7 +108,7 @@ void KReversiView::setAnimationSpeed(int speed)
m_delay = value;
m_qmlRoot->setProperty("chipsAnimationTime", value);
m_qml_root->setProperty("chipsAnimationTime", value);
}
KReversiView::~KReversiView()
......@@ -119,7 +120,7 @@ void KReversiView::updateBoard()
{
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++) {
QMetaObject::invokeMethod(m_qmlRoot, "setPreAnimationTicks",
QMetaObject::invokeMethod(m_qml_root, "setPreAnimationTicks",
Q_ARG(QVariant, i),
Q_ARG(QVariant, j),
Q_ARG(QVariant, 0));
......@@ -129,7 +130,7 @@ void KReversiView::updateBoard()
if (m_game) {
PosList changed_chips = m_game->changedChips();
for (int i = 1; i < changed_chips.size(); i++) { //i == 0 is new chip it don't need animation time
QMetaObject::invokeMethod(m_qmlRoot, "setPreAnimationTicks",
QMetaObject::invokeMethod(m_qml_root, "setPreAnimationTicks",
Q_ARG(QVariant, changed_chips[i].row),
Q_ARG(QVariant, changed_chips[i].col),
Q_ARG(QVariant, i - 1));
......@@ -153,21 +154,21 @@ void KReversiView::updateBoard()
break;
}
QMetaObject::invokeMethod(m_qmlRoot, "setChipState",
QMetaObject::invokeMethod(m_qml_root, "setChipState",
Q_ARG(QVariant, i),
Q_ARG(QVariant, j),
Q_ARG(QVariant, new_state));
// clearing legal markers, hints and lastmove
QMetaObject::invokeMethod(m_qmlRoot, "setLegal",
QMetaObject::invokeMethod(m_qml_root, "setLegal",
Q_ARG(QVariant, i),
Q_ARG(QVariant, j),
Q_ARG(QVariant, false));
QMetaObject::invokeMethod(m_qmlRoot, "setHint",
QMetaObject::invokeMethod(m_qml_root, "setHint",
Q_ARG(QVariant, i),
Q_ARG(QVariant, j),
Q_ARG(QVariant, false));
QMetaObject::invokeMethod(m_qmlRoot, "setLastMove",
QMetaObject::invokeMethod(m_qml_root, "setLastMove",
Q_ARG(QVariant, i),
Q_ARG(QVariant, j),
Q_ARG(QVariant, false));
......@@ -177,21 +178,21 @@ void KReversiView::updateBoard()
if (m_game && m_showLegalMoves) {
PosList possible_moves = m_game->possibleMoves();
for (int i = 0; i < possible_moves.size(); i++) {
QMetaObject::invokeMethod(m_qmlRoot, "setLegal",
QMetaObject::invokeMethod(m_qml_root, "setLegal",
Q_ARG(QVariant, possible_moves.at(i).row),
Q_ARG(QVariant, possible_moves.at(i).col),
Q_ARG(QVariant, true));
}
}
m_qmlRoot->setProperty("isBoardShowingLabels", m_showLabels);
m_qml_root->setProperty("isBoardShowingLabels", m_showLabels);
if (m_hint.isValid()) {
QMetaObject::invokeMethod(m_qmlRoot, "setChipState",
QMetaObject::invokeMethod(m_qml_root, "setChipState",
Q_ARG(QVariant, m_hint.row),
Q_ARG(QVariant, m_hint.col),
Q_ARG(QVariant, "Black"));
QMetaObject::invokeMethod(m_qmlRoot, "setHint",
QMetaObject::invokeMethod(m_qml_root, "setHint",
Q_ARG(QVariant, m_hint.row),
Q_ARG(QVariant, m_hint.col),
Q_ARG(QVariant, true));
......@@ -200,7 +201,7 @@ void KReversiView::updateBoard()
if (m_game && m_showLastMove) {
KReversiPos lastmove = m_game->getLastMove();
if (lastmove.isValid())
QMetaObject::invokeMethod(m_qmlRoot, "setLastMove",
QMetaObject::invokeMethod(m_qml_root, "setLastMove",
Q_ARG(QVariant, lastmove.row),
Q_ARG(QVariant, lastmove.col),
Q_ARG(QVariant, true));
......@@ -281,7 +282,7 @@ void KReversiView::slotGameOver()
void KReversiView::slotComputerCantMove()
{
QMetaObject::invokeMethod(m_qmlRoot, "showPopup",
QMetaObject::invokeMethod(m_qml_root, "showPopup",
Q_ARG(QVariant,
i18n("Computer can not move. It is your turn again.")));
updateBoard();
......@@ -289,7 +290,7 @@ void KReversiView::slotComputerCantMove()
void KReversiView::slotPlayerCantMove()
{
QMetaObject::invokeMethod(m_qmlRoot, "showPopup",
QMetaObject::invokeMethod(m_qml_root, "showPopup",
Q_ARG(QVariant,
i18n("You can not perform any move. Computer takes next turn now.")));
updateBoard();
......
......@@ -174,7 +174,7 @@ private:
/**
* Used to provide access to QML-implemented board
*/
QObject *m_qmlRoot;
QObject *m_qml_root;
/**
* Used to access theme engine from QML
......@@ -222,7 +222,7 @@ private:
bool m_showLegalMoves;
/**
* If true, board labels will be rendered
* If true board labels will be rendered
*/
bool m_showLabels;
......
......@@ -23,17 +23,11 @@
*
********************************************************************/
// Own
#include "mainwindow.h"
#include "kreversigame.h"
#include "kreversiview.h"
#include "preferences.h"
// Qt
#include <QApplication>
#include <QListWidget>
#include <QDockWidget>
#include <QLabel>
#include <QDesktopWidget>
// KDE
#include <kaction.h>
#include <kactioncollection.h>
#include <ktoggleaction.h>
......@@ -48,15 +42,13 @@
#include <kstandardgameaction.h>
#include <kselectaction.h>
#include <ktoolinvocation.h>
// libkdegames
#include <KgDifficulty>
// KReversi
#include "kreversigame.h"
#include "kreversiview.h"
#include "preferences.h"
#include <QApplication>
#include <QListWidget>
#include <QDockWidget>
#include <QLabel>
#include <QDesktopWidget>
static const int PLAYER_STATUSBAR_ID = 1;
static const int COMP_STATUSBAR_ID = 2;
......
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