//private
void ReversiGame::setBoard(QSharedPointer<ReversiBoard> nBoard)
{
    if (nBoard.isNull())
        return;

    ReversiBoard * raw = nBoard.data();
    connect(raw,
            SIGNAL(moveMade(CELL_STATE,CELL_STATE)),
            this,
            SLOT(handleTurnTaken(CELL_STATE,CELL_STATE)));
    connect(raw,
            SIGNAL(moveMade(CELL_STATE,CELL_STATE)),
            this,
            SIGNAL(turnTaken(CELL_STATE,CELL_STATE)));
    connect(raw,
            SIGNAL(gameOver(CELL_STATE)),
            this,
            SLOT(handleGameOver(CELL_STATE)));
    connect(raw,
            SIGNAL(gameOver(CELL_STATE)),
            this,
            SIGNAL(gameOver(CELL_STATE)));
    connect(raw,
            SIGNAL(countChanged(quint16,quint16)),
            this,
            SLOT(handleScoreChanged(quint16,quint16)));
    connect(raw,
            SIGNAL(countChanged(quint16,quint16)),
            this,
            SIGNAL(scoreChanged(quint16,quint16)));

    this->board = nBoard;
}
Beispiel #2
0
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
	srand(time(NULL));
	
	ui->setupUi(this);

	//Wygląd - wyśrodkowanie, tytuł itd.
	this->move(QApplication::desktop()->screen()->rect().center() - this->rect().center());
	this->setWindowTitle(VERSION);

	//TODO: Poprawić buttony i align na oknie nowej gry
	//this->newGameDialog.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
	
	gameHandler = new GameHandler(ui->GraphicsView);
	
	//podpinanie sygnałów
	QObject::connect(ui->ActionZakoncz, SIGNAL(triggered()), this, SLOT(close()));
	QObject::connect(ui->ActionPomoc, SIGNAL(triggered()), this, SLOT(showHelp()));
	QObject::connect(ui->ActionAutor, SIGNAL(triggered()), this, SLOT(showAuthor()));
	QObject::connect(ui->ActionNowa, SIGNAL(triggered()), &newGameDialog, SLOT(exec()));
	QObject::connect(&newGameDialog, SIGNAL(accepted()), this, SLOT(newGame()));
	QObject::connect(this->gameHandler, SIGNAL(moveMade()), this, SLOT(reactToMove()));
	QObject::connect(ui->ActionPokazRozwiazanie, SIGNAL(triggered()), this, SLOT(showSolution()));
	QObject::connect(&this->solutionTimer, SIGNAL(timeout()), gameHandler, SLOT(makeNextSolutionMove()));
	QObject::connect(this->gameHandler->getScene(), SIGNAL(pauseSolution()), this, SLOT(pauseSolution()));
	QObject::connect(this->gameHandler->getScene(), SIGNAL(resumeSolution()), this, SLOT(resumeSolution()));
	
	solutionTimer.setInterval(solutionTimerInterval);
	solutionTimer.setSingleShot(false);
}
Beispiel #3
0
void ChessPlayer::makeBookMove(const Chess::Move& move)
{
	m_timeControl.startTimer();
	makeMove(move);
	m_timeControl.update(false);
	m_eval.setBookEval(true);

	emit moveMade(move);
}
Beispiel #4
0
void PlayGameEngine::sendMoves_()
{
    // thanks, we got what we wanted
    listening_ = false;

    terminateTimer_.stop();

    if (engine_) /* it should be there though */
    {
        if (stopBetweenMoves_)
            engine_->deactivate();
        else
            engine_->stopAnalysis();
    }

    if (!(gotMove_ || gotBestMove_))
        emit engineClueless();
    else
    {
        if (gotBestMove_)
        {
            //qDebug() << "send"<<bestMove_.toNumeric();
            emit moveMade(bestMove_);
        }
        else
        if (!bestMoves_.empty())
        {
            emit moveMade(bestMoves_[0]);

            // multi-ply?
            int stm = bestMoves_[0].sideMoving();
            int i = 1;
            while (i < bestMoves_.size() && bestMoves_[i].sideMoving() == stm)
            {
                emit moveMade(bestMoves_[i]);
                ++i;
            }
        }
        else
            emit engineClueless();
    }

}
Beispiel #5
0
void ChessGame::emitLastMove()
{
	int ply = m_moves.size() - 1;
	if (m_scores.contains(ply))
	{
		int score = m_scores[ply];
		if (score != MoveEvaluation::NULL_SCORE)
			emit scoreChanged(ply, score);
	}

	const auto& md = m_pgn->moves().last();
	emit moveMade(md.move, md.moveString, md.comment);
}
Beispiel #6
0
void ChessPlayer::emitMove(const Chess::Move& move)
{
	if (m_state == Thinking)
		setState(Observing);

	m_timeControl.update();
	m_eval.setTime(m_timeControl.lastMoveTime());

	m_timer->stop();
	if (m_timeControl.expired() && !canPlayAfterTimeout())
	{
		forfeit(Chess::Result::Timeout);
		return;
	}

	emit moveMade(move);
}
Beispiel #7
0
void ChessGame::emitLastMove()
{
	PgnGame::MoveData md(m_pgn->moves().last());
	emit moveMade(md.move, md.moveString, md.comment);
}
Beispiel #8
0
void GameWall::addGame(ChessGame* game)
{
	Q_ASSERT(game != nullptr);

	QWidget* widget = new QWidget(this);

	ChessClock* clock[2] = { new ChessClock(), new ChessClock() };
	QHBoxLayout* clockLayout = new QHBoxLayout();
	for (int i = 0; i < 2; i++)
	{
		clock[i] = new ChessClock();
		clockLayout->addWidget(clock[i]);

		Chess::Side side = Chess::Side::Type(i);
		clock[i]->setPlayerName(side.toString());
	}
	clockLayout->insertSpacing(1, 20);

	BoardScene* scene = new BoardScene();
	BoardView* view = new BoardView(scene);

	QVBoxLayout* mainLayout = new QVBoxLayout();
	mainLayout->addLayout(clockLayout);
	mainLayout->addWidget(view);
	mainLayout->setContentsMargins(0, 0, 0, 0);

	widget->setLayout(mainLayout);
	layout()->addWidget(widget);

	game->lockThread();
	connect(game, SIGNAL(fenChanged(QString)),
		scene, SLOT(setFenString(QString)));
	connect(game, SIGNAL(moveMade(Chess::GenericMove, QString, QString)),
		scene, SLOT(makeMove(Chess::GenericMove)));
	connect(game, SIGNAL(humanEnabled(bool)),
		view, SLOT(setEnabled(bool)));

	for (int i = 0; i < 2; i++)
	{
		ChessPlayer* player(game->player(Chess::Side::Type(i)));

		if (player->isHuman())
			connect(scene, SIGNAL(humanMove(Chess::GenericMove, Chess::Side)),
				player, SLOT(onHumanMove(Chess::GenericMove, Chess::Side)));

		clock[i]->setPlayerName(player->name());
		connect(player, SIGNAL(nameChanged(QString)),
			clock[i], SLOT(setPlayerName(QString)));

		clock[i]->setInfiniteTime(player->timeControl()->isInfinite());

		if (player->state() == ChessPlayer::Thinking)
			clock[i]->start(player->timeControl()->activeTimeLeft());
		else
			clock[i]->setTime(player->timeControl()->timeLeft());

		connect(player, SIGNAL(startedThinking(int)),
			clock[i], SLOT(start(int)));
		connect(player, SIGNAL(stoppedThinking()),
			clock[i], SLOT(stop()));
	}

	scene->setBoard(game->pgn()->createBoard());
	scene->populate();

	foreach (const Chess::Move& move, game->moves())
		scene->makeMove(move);

	game->unlockThread();

	view->setEnabled(!game->isFinished() &&
			 game->playerToMove()->isHuman());
	m_games[game] = widget;

	cleanupWidgets();
}