示例#1
0
void Reversi::changeShowHint(){
	showHints = !showHints;
	refreshField();
	if(showHints){
		checkForLegalTurns();
	}
}
示例#2
0
void Reversi::newGame(){
	map = new Map(FIELD_SIZE);

	gameOver = false;
	gameStatus = WHITE_PLAYER_TURN; // Turn zero
	refreshField();
	changePlayer(0); // Change player to turn one
}
示例#3
0
void Reversi::cellClicked(int x, int y) {
	Lines lines(gameStatus, Point(x, y), map->fieldStatus, FIELD_SIZE);
	if (map->fieldStatus[x][y] == 0) {
		QList<Point> modifiedCells = lines.getActiveTiles();
		if ((modifiedCells.size() > 0)) {
			for (unint i = 0; i < modifiedCells.size(); i++) {
				map->fieldStatus[modifiedCells.at(i).x][modifiedCells.at(i).y] =
						gameStatus;
			}
			refreshField();
			changePlayer(0);
		}
	}
}
示例#4
0
void settingOtherPlayGround(WINDOW* thisWindow){
	//wborder(thisWindow, 'I', 'I', '-', '-', '*', '*', '*', '*');
	for (int i = 1; i < 23; i = i++){
		for (int j = 1; j < 24; j = j + 2){
			if (i == 0 || i == 23)
				mvwprintw(thisWindow, i, j, "□");
			else
				mvwprintw(thisWindow, i, j, "□");
		}
	}

	initField();
	refreshField(thisWindow, 5, 5, 5);

	wrefresh(thisWindow);
}
double temperature_iterate(TemperatureField *field)
{
	++iter_cnt;
	refreshField(field, 0, 0, field->x, field->y, field->x, field->y);
	int i, j, d;
	double ret = 0;
#pragma omp parallel for schedule(static) private(j) private(d) reduction(+:ret)
	for (i=0; i<field->x; ++i){
		for (j=0; j<field->y; ++j)
		{
			tempField->t[i][j] = 0;
			for (d=0; d<4; ++d)
				if ( legal(i+dx[d], field->x) && legal(j+dy[d], field->y) )
					tempField->t[i][j] += field->t[i+dx[d]][j+dy[d]];
				else
					tempField->t[i][j] += ROOM_TEMP;
			tempField->t[i][j] /= 4;
			if (NOT_FIRE_PLACE)
				ret += fabs(tempField->t[i][j] - field->t[i][j]);
		}
	}
	return ret;
}
示例#6
0
void Reversi::changePlayer(int skippedTurns) {
	// Change player turn
	switch (gameStatus *= -1) {
	case WHITE_PLAYER_TURN:
	{
		QString result1 = QString("White player\'s turn");
		result1.append(gameScore);
		main->setStatusBar(&result1);
		break;
	}
	case BLACK_PLAYER_TURN:
	{
		QString result2 = QString("Black player\'s turn");
		result2.append(gameScore);
		main->setStatusBar(&result2);
		break;
	}
	}
	if (checkForLegalTurns() && skippedTurns < 1) {
		changePlayer(1);
	} else if (checkForLegalTurns() && skippedTurns > 0) {
		QString result3 = QString("Game over");
		result3.append(gameScore);
		main->setStatusBar(&result3);
		skippedTurns++;
	}
	// Counts the amount of time this function was called
	switch (skippedTurns) {
	case 1:{
		QMessageBox msgBox1;
			switch(gameStatus*(-1)){
				case WHITE_PLAYER_TURN:
					msgBox1.setText("White player skips a turn");
					break;
				case BLACK_PLAYER_TURN:
					msgBox1.setText("Black player skips a turn");
					break;
			}
		    msgBox1.exec();
		return;
	}
	case 2:{
			QMessageBox msgBox2;
				msgBox2.setText("White player wins");
			if((map->blackChipCount-map->whiteChipCount)< 0){
			}
			else if((map->blackChipCount-map->whiteChipCount)>0){
				msgBox2.setText("Black player wins");
			}
			else {
				msgBox2.setText("Its a draw");
			}

		    msgBox2.setInformativeText(*gameScore);
		    msgBox2.exec();
		    gameOver = true;
		    return;
		}
	}

	if(playWithAi && gameStatus==WHITE_PLAYER_TURN && !gameOver){
		AI *bot = new AI(gameStatus);
		bot->makeTurn(map);
		refreshField();
		changePlayer(0);
	}
}
void OptionalFieldWidget::refreshImpl()
{
    refreshInternal();
    refreshField();
}