Ejemplo n.º 1
0
void Gui::selectBlackPlayer() {
	Gtk::MessageDialog dialog("Choose black player", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE);
	dialog.set_secondary_text("Please choose whether black is an AI or human player");
	dialog.add_button("Human", HUMAN);
	dialog.add_button("AI", AI);
	int result = dialog.run();
	players[Piece::BLACK] = (Player)result;
	std::cout << "Black player set to: " << result << std::endl;
	updateTurn();
}
Ejemplo n.º 2
0
void MainWindow::undo(){
    pair<int,int> play = gameOrganizer->undo();
    if(play.first != -1 && play.second != -1){
        helper->drawBlock(play.first, play.second, QBrush(QColor(Qt::white)));
        ui->btnRedo->setProperty("enabled", true);
        ui->btnUndo->setProperty("enabled", false);
    }

   updateTurn();

}
Ejemplo n.º 3
0
void Gui::newGame() {
	board->init();
	info->init();
	hintMove = Move();
	movingFrom = -1;
	finished = false;
	moveList.clear();
	draw();
	updateTurn();
	std::cout << "New Game" << std::endl;
}
Ejemplo n.º 4
0
void Gui::doAiMove() {
	if (finished) return;
	Move move;
	static const int depth = 3;
	static const int quiescenceDepth = 8;
	// AI searches game tree at specified depths to decide next move.
	int eval = Minimax::AlphaBeta(board, info, move, depth, quiescenceDepth);
	std::cout << "Executed move " << move.toAlgebraic() << " with evaluation " << eval << std::endl;
	board->executeMove(move);
	info->executeMove(move);
	draw();
	updateTurn();
}
Ejemplo n.º 5
0
void MainWindow::redo(){
    char color = gameOrganizer->turnToPlay()->getcolour();
    pair<int,int> play = gameOrganizer->redo();
    if(play.first != -1 && play.second != -1) {
        if(color == 'r')
            helper->drawBlock(play.first, play.second, QBrush(QColor(Qt::red)));
        else if(color == 'b')
            helper->drawBlock(play.first, play.second, QBrush(QColor(Qt::blue)));
        ui->btnUndo->setProperty("enabled", true);
        ui->btnRedo->setProperty("enabled", false);
    }
    updateTurn();
}
Ejemplo n.º 6
0
void MainWindow::columnClicked(int column) {
    Player* turn = gameOrganizer->turnToPlay();
    int row = gameOrganizer->play(column);
    char color = turn->getcolour();

    if(color == 'r')
        helper->drawBlock(column, row, QBrush(QColor(Qt::red)));
    else if(color == 'b')
        helper->drawBlock(column, row, QBrush(QColor(Qt::blue)));
    ui->btnUndo->setProperty("enabled", true);
    ui->btnRedo->setProperty("enabled", false);
    updateTurn();
    if (gameOrganizer->isFinished()) finished(gameOrganizer->turnToPlay());
}
Ejemplo n.º 7
0
bool Gui::handleEvent(GdkEvent *event) {
	if (event->type == Gdk::EXPOSE) draw();
	if (finished) return true;
	if (event->type == Gdk::BUTTON_PRESS) {
		if (players[info->turn] == AI) {
			doAiMove();
			return true;
		}
		// Ascertain the position of the click.
		position pos = Position::ToInt((int)event->button.x / TileSize, NUM_RANKS - 1 - ((int)event->button.y / TileSize));
		std::cout << "Click at " << Position::ToAlgebraic(pos) << std::endl;
		// If choosing a piece to move..
		if (movingFrom < 0) {
			std::cout << "Moving from..." << std::endl;
			if (moveList.generateForHuman(pos, board, info)) {
				std::cout << "Legal piece to move!" << std::endl;
				moveList.prune((Piece::Color)!info->turn, board);
				movingFrom = pos;
				// Draw highlighted moves.
				draw();
			} else std::cout << "Cannot move this piece!" << std::endl;
		// If choosing a destination..
		} else {
			std::cout << "Moving to..." << std::endl;
			MoveList::const_iterator moveItr = moveList.getMove(movingFrom, pos);
			if (moveItr == moveList.end()) {
				// Invalid move.
				std::cout << "Invalid move!" << std::endl;
			} else {
				// Execute move.
				std::cout << "Executing move" << std::endl;
				Move move = *moveItr;
				if (move.type >= Move::PROMOTION) {
					move.type = (Move::Type)(Move::PROMOTION + handlePromotion());
				}
				board->executeMove(move);
				info->executeMove(move);
				updateTurn();
				// Reset hint.
				hintMove = Move();
			}
			movingFrom = -1;
			moveList.clear();
			// Redraw
			draw();
		}
	}
	return true;
}
Ejemplo n.º 8
0
bool Gui::init(Window *window) {
	this->window = window;
	// Add mouse click handling.
	add_events(Gdk::BUTTON_PRESS_MASK);
	signal_event().connect(sigc::mem_fun(*this, &Gui::handleEvent));
	// Load sprite sheet form file.
	try {
		spritesheet = Gdk::Pixbuf::create_from_file(SpritesheetFilename);
	} catch (const Glib::FileError &e) {
		std::cerr << "Error loading image: " << e.what() << std::endl;
		return false;
	} catch (const Gdk::PixbufError &e) {
		std::cerr << "Error loading image: " << e.what() << std::endl;
		return false;
	}
	updateTurn();
	return true;
}
Ejemplo n.º 9
0
void MainWindow::startGame() {
    helper->drawGrid();
    gameOrganizer->init();
    updateTurn();
}
Ejemplo n.º 10
0
void CarModel::update(float* controlState)
{
	updateFriction();
	updateDrive(controlState);
	updateTurn(controlState);
}