Esempio n. 1
0
void Board::marked(int x, int y) {
  // make sure that the last arrow is correctly undrawn
  undrawArrow();

  if(getField(x, y) == EMPTY)
    return;
  
  if(x == mark_x && y == mark_y) {
    // unmark the piece
    mark_x = -1;
    mark_y = -1;
    updateField(x, y);
    return;
  }

  if(mark_x == -1) {
    mark_x = x;
    mark_y = y;
    updateField(x, y);
    return;
  } else {
    int fld1 = getField(mark_x, mark_y);
    int fld2 = getField(x, y);
    
    // both field same?
    if(fld1 != fld2) {
      emit markError();
      return;
    }
    
    // trace    
    if(findPath(mark_x, mark_y, x, y)) {
      emit madeMove(mark_x, mark_y, x, y);
      drawArrow(mark_x, mark_y, x, y);
      setField(mark_x, mark_y, EMPTY);
      setField(x, y, EMPTY);
      mark_x = -1;
      mark_y = -1;

      int dummyx;
      History dummyh[4];

      // game is over?      
      if(!getHint_I(dummyx,dummyx,dummyx,dummyx,dummyh)) {
	time_for_game = (int)time((time_t)NULL) - starttime;
	emit endOfGame();
      }
      
    } else {
      clearHistory();
      emit markError();
    }
  }
}
Esempio n. 2
0
void Board::marked(int x, int y)
{
	// make sure that the previous connection is correctly undrawn
	undrawConnection();

	if(getField(x, y) == EMPTY)
		return;

	if(x == mark_x && y == mark_y)
	{
		// unmark the piece
		mark_x = -1;
		mark_y = -1;
		updateField(x, y, false);
		return;
	}

	if(mark_x == -1)
	{
		mark_x = x;
		mark_y = y;
		updateField(x, y, false);
		return;
	}

	int fld1 = getField(mark_x, mark_y);
	int fld2 = getField(x, y);

	// both field same?
	if(fld1 != fld2)
		return;

	// trace
	if(findPath(mark_x, mark_y, x, y, connection))
	{
		madeMove(mark_x, mark_y, x, y);
		drawConnection(getDelay());
		setField(mark_x, mark_y, EMPTY);
		setField(x, y, EMPTY);
		grav_col_1 = x;
		grav_col_2 = mark_x;
		mark_x = -1;
		mark_y = -1;

		// game is over?
		// Must delay until after tiles fall to make this test
		// See undrawConnection GP.
	}
	else
	{
		connection.clear();
	}
}
Esempio n. 3
0
bool chessGame::tryMove(const boardMove &bm)
{
    if (bm.isLegal(getBoard().getLegalMoves(bm.getStart()))){
        state.makeMove(bm);

        history.append(state);
        redo.clear();

        emit madeMove(bm);

        cantStep = !getCurrentPlayer()->isHuman();
        if (cantStep){
            getCurrentPlayer()->think(state);
        }
    }
    return false;
}
Esempio n. 4
0
void EngineController::play() {
    qDebug() << "EngineController::play";
    /* make moves in long algebraic notation "d2d4" or "f7f8q" */
    if(engine->getBestmove().size() == 4 || engine->getBestmove().size() == 5) {
        game->move(engine->getBestmove());

        /* Let other widgets know, that we made a move */
        cout << "Made move" << endl;
        emit madeMove();
        ui->playButton->setDisabled(true);

        /* Think on next move if radiobutton play and color checkbox are checked */
        cout << "Think on next move" << endl;
        if(ui->radio_play->isChecked() || ui->radio_think->isChecked()) {
            if(game->getActiveColor() == 'b') selectEngine(1);
            else selectEngine(0);
            if((ui->checkBox_black->isChecked() && game->getActiveColor() == 'b')
                    || (ui->checkBox_white->isChecked() && game->getActiveColor() == 'w')) go();
        }
    }
}