Commit c79cc6d4 authored by Denis Kuplyakov's avatar Denis Kuplyakov

Formatted source code

GIT_SILENT
parent 64bdb17c
This diff is collapsed.
......@@ -136,30 +136,30 @@ class KReversiGame;
class SquareStackEntry
{
public:
SquareStackEntry();
SquareStackEntry();
void setXY(int x, int y);
void setXY(int x, int y);
public:
int m_x;
int m_y;
int m_x;
int m_y;
};
class SquareStack
{
public:
SquareStack();
SquareStack(int size);
SquareStack();
SquareStack(int size);
void resize(int size);
void init(int size);
SquareStackEntry Pop();
void Push(int x, int y);
void resize(int size);
void init(int size);
SquareStackEntry Pop();
void Push(int x, int y);
private:
QVector<SquareStackEntry> m_squarestack;
int m_top;
QVector<SquareStackEntry> m_squarestack;
int m_top;
};
......@@ -168,15 +168,15 @@ private:
class MoveAndValue
{
public:
MoveAndValue();
MoveAndValue(int x, int y, int value);
MoveAndValue();
MoveAndValue(int x, int y, int value);
void setXYV(int x, int y, int value);
void setXYV(int x, int y, int value);
public:
int m_x;
int m_y;
int m_value;
int m_x;
int m_y;
int m_value;
};
class Score;
......@@ -184,61 +184,72 @@ class Score;
// The real beef of this program: the engine that finds good moves for
// the computer player.
//
class Engine {
class Engine
{
public:
Engine(int st, int sd);
Engine(int st);
Engine();
~Engine();
KReversiMove computeMove(const KReversiGame& game, 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; }
Engine(int st, int sd);
Engine(int st);
Engine();
~Engine();
KReversiMove computeMove(const KReversiGame& game, 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:
KReversiMove ComputeFirstMove(const KReversiGame& game);
int ComputeMove2(int xplay, int yplay, ChipColor color, int level,
int cutoffval,
quint64 colorbits, quint64 opponentbits);
KReversiMove ComputeFirstMove(const KReversiGame& game);
int ComputeMove2(int xplay, int yplay, ChipColor color, int level,
int cutoffval,
quint64 colorbits, quint64 opponentbits);
int TryAllMoves(ChipColor opponent, int level, int cutoffval,
quint64 opponentbits, quint64 colorbits);
int TryAllMoves(ChipColor opponent, int level, int cutoffval,
quint64 opponentbits, quint64 colorbits);
int EvaluatePosition(ChipColor color);
void SetupBcBoard();
void SetupBits();
int CalcBcScore(ChipColor color);
quint64 ComputeOccupiedBits(ChipColor color);
int EvaluatePosition(ChipColor color);
void SetupBcBoard();
void SetupBits();
int CalcBcScore(ChipColor color);
quint64 ComputeOccupiedBits(ChipColor color);
void yield();
void yield();
private:
ChipColor m_board[10][10];
int m_bc_board[9][9];
Score* m_score;
Score* m_bc_score;
SquareStack m_squarestack;
ChipColor m_board[10][10];
int m_bc_board[9][9];
Score* m_score;
Score* m_bc_score;
SquareStack m_squarestack;
int m_depth;
int m_coeff;
int m_nodes_searched;
bool m_exhaustive;
bool m_competitive;
int m_depth;
int m_coeff;
int m_nodes_searched;
bool m_exhaustive;
bool m_competitive;
uint m_strength;
KRandomSequence m_random;
bool m_interrupt;
uint m_strength;
KRandomSequence m_random;
bool m_interrupt;
quint64 m_coord_bit[9][9];
quint64 m_neighbor_bits[9][9];
quint64 m_coord_bit[9][9];
quint64 m_neighbor_bits[9][9];
bool m_computingMove;
bool m_computingMove;
};
#endif
......@@ -26,22 +26,19 @@
// noColor = empty
enum ChipColor {White = 0, Black = 1, NoColor = 2};
struct KReversiPos
{
struct KReversiPos {
KReversiPos(int r = -1, int c = -1)
: row(r), col(c) { }
int row;
int col;
bool isValid() const
{
bool isValid() const {
return (row >= 0 && col >= 0 && row < 8 && col < 8);
}
};
struct KReversiMove: public KReversiPos
{
struct KReversiMove: public KReversiPos {
KReversiMove(ChipColor col = NoColor, int r = -1, int c = -1)
: KReversiPos(r, c), color(col) { }
......@@ -50,8 +47,7 @@ struct KReversiMove: public KReversiPos
ChipColor color;
bool isValid() const
{
bool isValid() const {
return (color != NoColor
&& row >= 0 && col >= 0
&& row < 8 && col < 8);
......
......@@ -24,7 +24,7 @@ namespace KExtHighscore
ExtManager::ExtManager()
: Manager(7)
{
setShowMode( NeverShow );
setShowMode(NeverShow);
setShowStatistics(true);
setShowDrawGamesStatistic(true);
......@@ -44,15 +44,15 @@ ExtManager::ExtManager()
QString ExtManager::gameTypeLabel(uint gameType, LabelType type) const
{
switch (type) {
case Standard:
return QString::number(gameType);
case I18N:
return m_typeLabels.at(gameType);
case Icon:
// FIXME dimsuz: implement
break;
case WW:
break;
case Standard:
return QString::number(gameType);
case I18N:
return m_typeLabels.at(gameType);
case Icon:
// FIXME dimsuz: implement
break;
case WW:
break;
}
return QString();
......
......@@ -67,8 +67,7 @@ KReversiGame::~KReversiGame()
void KReversiGame::makeMove(const KReversiMove &move)
{
if (!move.isValid())
{
if (!move.isValid()) {
kickCurrentPlayer();
return; // Move is invalid!
}
......@@ -76,8 +75,7 @@ void KReversiGame::makeMove(const KReversiMove &move)
if (move.color != m_curPlayer)
return; // It's not your turn now
if (!isMovePossible(move))
{
if (!isMovePossible(move)) {
kickCurrentPlayer();
return; // Unpossible move
}
......@@ -95,16 +93,13 @@ void KReversiGame::startNextTurn()
emit moveFinished(); // previous move has just finished
if (!isGameOver())
{
if (!isGameOver()) {
if (isAnyPlayerMovePossible(m_curPlayer)) {
if (m_curPlayer == White)
emit whitePlayerTurn();
else
emit blackPlayerTurn();
}
else
{
} else {
if (m_curPlayer == White)
emit whitePlayerCantMove();
else
......@@ -113,9 +108,7 @@ void KReversiGame::startNextTurn()
m_lastPlayer = m_curPlayer;
startNextTurn();
}
}
else //Game is over
{
} else { //Game is over
emit gameOver();
}
}
......@@ -130,8 +123,7 @@ int KReversiGame::undo()
int movesUndone = 0;
while( !m_undoStack.isEmpty() )
{
while (!m_undoStack.isEmpty()) {
MoveList lastUndo = m_undoStack.pop();
// One thing that matters here is that we take the
// chip color directly from board, rather than from move.color
......@@ -148,8 +140,7 @@ int KReversiGame::undo()
setChipColor(KReversiMove(NoColor, move.row, move.col));
// and change back the color of the rest chips
foreach( const KReversiMove &pos, lastUndo )
{
foreach(const KReversiMove & pos, lastUndo) {
ChipColor opponentColor = opponentColorFor(m_cells[pos.row][pos.col]);
setChipColor(KReversiMove(opponentColor, pos.row, pos.col));
}
......@@ -157,7 +148,7 @@ int KReversiGame::undo()
lastUndo.clear();
movesUndone++;
if( move.color == m_curPlayer )
if (move.color == m_curPlayer)
break; //we've undone all opponent's + one current player's moves
}
......@@ -179,15 +170,12 @@ void KReversiGame::turnChips(const KReversiMove &move)
setChipColor(move);
m_changedChips.append(move);
// now turn color of all chips that were won
for (int dirNum = 0; dirNum < DIRECTIONS_COUNT; dirNum++)
{
if (hasChunk(dirNum, move))
{
for (int dirNum = 0; dirNum < DIRECTIONS_COUNT; dirNum++) {
if (hasChunk(dirNum, move)) {
for (int r = move.row + DX[dirNum], c = move.col + DY[dirNum];
r >= 0 && c >= 0 && r < 8 && c < 8;
r += DX[dirNum], c += DY[dirNum])
{
if( m_cells[r][c] == move.color )
r >= 0 && c >= 0 && r < 8 && c < 8;
r += DX[dirNum], c += DY[dirNum]) {
if (m_cells[r][c] == move.color)
break;
setChipColor(KReversiMove(move.color, r, c));
m_changedChips.append(KReversiMove(move.color, r, c));
......@@ -203,7 +191,7 @@ void KReversiGame::turnChips(const KReversiMove &move)
bool KReversiGame::isMovePossible(const KReversiMove& move) const
{
// first - the trivial case:
if( m_cells[move.row][move.col] != NoColor || move.color == NoColor )
if (m_cells[move.row][move.col] != NoColor || move.color == NoColor)
return false;
for (int dirNum = 0; dirNum < DIRECTIONS_COUNT; dirNum++)
......@@ -229,20 +217,15 @@ bool KReversiGame::hasChunk(int dirNum, const KReversiMove& move) const
bool foundPlayerColor = false;
for (int r = move.row + DX[dirNum], c = move.col + DY[dirNum];
r >= 0 && c >= 0 && r < 8 && c < 8;
r += DX[dirNum], c += DY[dirNum])
{
r >= 0 && c >= 0 && r < 8 && c < 8;
r += DX[dirNum], c += DY[dirNum]) {
ChipColor color = m_cells[r][c];
if (color == opColor)
{
if (color == opColor) {
opponentChipsNum++;
}
else if (color == move.color)
{
} else if (color == move.color) {
foundPlayerColor = true;
break;
}
else
} else
break;
}
......@@ -255,7 +238,7 @@ bool KReversiGame::hasChunk(int dirNum, const KReversiMove& move) const
bool KReversiGame::isGameOver() const
{
// trivial fast-check
if( m_score[White] + m_score[Black] == 64 )
if (m_score[White] + m_score[Black] == 64)
return true; // the board is full
else
return !(isAnyPlayerMovePossible(White) || isAnyPlayerMovePossible(Black));
......@@ -264,10 +247,8 @@ bool KReversiGame::isGameOver() const
bool KReversiGame::isAnyPlayerMovePossible(ChipColor player) const
{
for (int r = 0; r < 8; ++r)
for (int c = 0; c < 8; ++c)
{
if (m_cells[r][c] == NoColor)
{
for (int c = 0; c < 8; ++c) {
if (m_cells[r][c] == NoColor) {
// let's see if we can put chip here
if (isMovePossible(KReversiMove(player, r, c)))
return true;
......@@ -326,8 +307,7 @@ MoveList KReversiGame::possibleMoves() const
return l;
for (int r = 0; r < 8; ++r)
for (int c = 0; c < 8; ++c)
{
for (int c = 0; c < 8; ++c) {
KReversiMove move(m_curPlayer, r, c);
if (isMovePossible(move))
l.append(move);
......
......@@ -57,7 +57,9 @@ public:
/**
* @return if undo is possible
*/
bool canUndo() const { return !m_undoStack.isEmpty(); }
bool canUndo() const {
return !m_undoStack.isEmpty();
}
/**
* Undoes all the opponent of current player moves and one his move
* (so after calling this function it will be still current player turn)
......@@ -85,7 +87,9 @@ public:
* First of them will be the move itself, and the rest - chips which
* were turned by that move
*/
MoveList changedChips() const { return m_changedChips; }
MoveList changedChips() const {
return m_changedChips;
}
/**
* @return a list of possible moves for current player
*/
......@@ -101,7 +105,9 @@ public:
/**
* @return a color of the current player
*/
ChipColor currentPlayer() const { return m_curPlayer; }
ChipColor currentPlayer() const {
return m_curPlayer;
}
/**
* Sets animation times from players
*/
......@@ -188,10 +194,10 @@ private:
* Color of the current player
*/
ChipColor m_curPlayer;
// 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 :)
// 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
......
......@@ -35,8 +35,8 @@ KReversiView::KReversiView(KReversiGame* game, QWidget *parent) :
m_qml_root = (QObject*) rootObject();
rootContext()->setContextProperty("container", this);
connect(m_qml_root, SIGNAL(cellClicked(int,int)),
this, SLOT(onPlayerMove(int,int)));
connect(m_qml_root, SIGNAL(cellClicked(int, int)),
this, SLOT(onPlayerMove(int, int)));
setGame(game);
}
......
......@@ -35,12 +35,12 @@ static const char description[] = I18N_NOOP("KDE Reversi Board Game");
int main(int argc, char **argv)
{
KAboutData aboutData( "kreversi", 0, ki18n("KReversi"),
"2.0", ki18n(description), KAboutData::License_GPL,
ki18n("(c) 1997-2000, Mario Weilguni\n(c) 2004-2006, Inge Wallin\n(c) 2006, Dmitry Suzdalev"),
KLocalizedString(), "http://games.kde.org/kreversi" );
aboutData.addAuthor(ki18n("Mario Weilguni"),ki18n("Original author"), "mweilguni@sime.com");
aboutData.addAuthor(ki18n("Inge Wallin"),ki18n("Original author"), "inge@lysator.liu.se");
KAboutData aboutData("kreversi", 0, ki18n("KReversi"),
"2.0", ki18n(description), KAboutData::License_GPL,
ki18n("(c) 1997-2000, Mario Weilguni\n(c) 2004-2006, Inge Wallin\n(c) 2006, Dmitry Suzdalev"),
KLocalizedString(), "http://games.kde.org/kreversi");
aboutData.addAuthor(ki18n("Mario Weilguni"), ki18n("Original author"), "mweilguni@sime.com");
aboutData.addAuthor(ki18n("Inge Wallin"), ki18n("Original author"), "inge@lysator.liu.se");
aboutData.addAuthor(ki18n("Dmitry Suzdalev"), ki18n("Game rewrite for KDE4. Current maintainer."), "dimsuz@gmail.com");
aboutData.addCredit(ki18n("Simon Hürlimann"), ki18n("Action refactoring"));
aboutData.addCredit(ki18n("Mats Luthman"), ki18n("Game engine, ported from his JAVA applet."));
......@@ -49,23 +49,20 @@ int main(int argc, char **argv)
aboutData.addCredit(ki18n("Brian Croom"), ki18n("Port rendering code to KGameRenderer"), "brian.s.croom@gmail.com");
aboutData.addCredit(ki18n("Denis Kuplyakov"), ki18n("Port rendering code to QML"), "dener.kup@gmail.com");
KCmdLineArgs::init( argc, argv, &aboutData );
KCmdLineArgs::init(argc, argv, &aboutData);
KCmdLineOptions options;
options.add("demo", ki18n( "Start with demo game playing" ));
KCmdLineArgs::addCmdLineOptions( options );
options.add("demo", ki18n("Start with demo game playing"));
KCmdLineArgs::addCmdLineOptions(options);
KApplication application;
KGlobal::locale()->insertCatalog( QLatin1String( "libkdegames" ));
KGlobal::locale()->insertCatalog(QLatin1String("libkdegames"));
if( application.isSessionRestored() )
{
if (application.isSessionRestored()) {
RESTORE(KReversiMainWindow)
}
else
{
} else {
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
KReversiMainWindow *mainWin = new KReversiMainWindow( 0, args->isSet( "demo" ) );
KReversiMainWindow *mainWin = new KReversiMainWindow(0, args->isSet("demo"));
args->clear();
mainWin->show();
}
......
......@@ -172,8 +172,8 @@ void KReversiMainWindow::slotAnimSpeedChanged(int speed)
void KReversiMainWindow::slotUseColoredChips(bool toggled)
{
KReversiView::ChipsPrefix chipsPrefix = m_coloredChipsAct->isChecked() ?
KReversiView::Colored :
KReversiView::BlackWhite;
KReversiView::Colored :
KReversiView::BlackWhite;
m_view->setChipsPrefix(chipsPrefix);
Preferences::setUseColoredChips(toggled);
Preferences::self()->writeConfig();
......
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