bool BoardController::moveFigure(int from, int to) { if(!m_logic_controller.isMoveAllowed(from, to) || from == to) return false; auto victim = figureAt(to); auto victim_type = victim->type(); auto victim_color = victim->side(); Transition t(from, to, victim_color, victim_type); _moveFigure(from, to); emit figureMoved(t); return true; }
bool ChessBoard::turn(int row, int column) { if( !m_selected_piece ) return false; // get possible turns QScopedPointer< const QList<QSize> > trns(m_selected_piece->getPossibleTurns( column, row )); // current coords QSize cur_coords = m_selected_piece->getCoords(); QList<QSize>::const_iterator it; for(it = trns->begin(); it != trns->end(); it++) { QSize coords_sum = b_black_bottom ^ m_selected_piece->m_bWhite ? cur_coords - (*it) : cur_coords + (*it); if( coords_sum == turn_coords ) { emit figureMoved(cur_coords, turn_coords); PiecePtr &turned = pieceAt(column, row); m_selected_piece->setCoords(turn_coords); turned.swap(m_selected_piece); return true; } } return false; }