Exemplo n.º 1
0
//------------------------------------------------------------------------------------------------
vector<Position> Rook::GetValidMoves(Board* board) {

	vector<Position> vec;
	Position* curPos = this->GetPosition();
	int row = curPos->GetRow();
	int col = curPos->GetCol();

	// Up
	while (row > 0) {
		if (board->GetPieceAt(--row, col) == NULL) {
			Position pos(row, col);
			vec.push_back(pos);
		}
	
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) {
			
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else 
			break;
	}

	// Down
	row = curPos->GetRow();
	col = curPos->GetCol();
	while (row < 7) {
		if (board->GetPieceAt(++row, col) == NULL) { // Blank square
			Position pos(row, col);
			vec.push_back(pos);
		}
	
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) { //enemy
			
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else // My piece
			break;
	}

	// Left
	row = curPos->GetRow();
	col = curPos->GetCol();
	while (col > 0) {
		if (board->GetPieceAt(row, --col) == NULL) {
			Position pos(row, col);
			vec.push_back(pos);
		}
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) {
			
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else 
			break;
	}

	// Right
	row = curPos->GetRow();
	col = curPos->GetCol();
	while (col < 7) {
		if (board->GetPieceAt(row, ++col) == NULL) {
			Position pos(row, col);
			vec.push_back(pos);
		}
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) {
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else 
			break;
	}

	return vec;
}
Exemplo n.º 2
0
Position::Position(const Position& other)
    : m_row(other.GetRow())
    , m_column(other.GetColumn())
{}
Exemplo n.º 3
0
bool Position::operator<(const Position& other) const
{
    return GetRow() < other.GetRow() || (GetRow() == other.GetRow() && GetColumn() < other.GetColumn());
}
Exemplo n.º 4
0
bool Position::operator!=(const Position& other) const
{
    return GetRow() != other.GetRow() || GetColumn() != other.GetColumn();
}
Exemplo n.º 5
0
bool Position::operator==(const Position& other) const
{
    return GetRow() == other.GetRow() && GetColumn() == other.GetColumn();
}
Exemplo n.º 6
0
//------------------------------------------------------------------------------------------------
vector<Position> Queen::GetValidMoves(Board* board) {

	vector<Position> vec;
	Position* curPos = this->GetPosition();
	int row = curPos->GetRow();
	int col = curPos->GetCol();

	// Up and Left
	while (row > 0 && col > 0) {
		if (board->GetPieceAt(--row, --col) == NULL) {
			Position pos(row, col);
			vec.push_back(pos);
		}
	
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) {
			
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else 
			break;
	}

	// Up and Right
	row = curPos->GetRow();
	col = curPos->GetCol();
	while (row > 0 && col < 7) {
		if (board->GetPieceAt(--row, ++col) == NULL) {
			Position pos(row, col);
			vec.push_back(pos);
		}
	
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) {
			
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else 
			break;
	}

	// Down and Left
	row = curPos->GetRow();
	col = curPos->GetCol();
	while (row < 7 && col > 0) {
		if (board->GetPieceAt(++row, --col) == NULL) {
			Position pos(row, col);
			vec.push_back(pos);
		}
	
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) {
			
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else 
			break;
	}

	// Down and Right
	row = curPos->GetRow();
	col = curPos->GetCol();
	while (row < 7 && col < 7) {
		if (board->GetPieceAt(++row, ++col) == NULL) {
			Position pos(row, col);
			vec.push_back(pos);
		}
	
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) {
			
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else 
			break;
	}

	// Up
	row = curPos->GetRow();
	col = curPos->GetCol();
	while (row > 0) {
		if (board->GetPieceAt(--row, col) == NULL) {
			Position pos(row, col);
			vec.push_back(pos);
		}
	
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) {
			
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else 
			break;
	}


	// Down
	row = curPos->GetRow();
	col = curPos->GetCol();
	while (row < 7) {
		if (board->GetPieceAt(++row, col) == NULL) {
			Position pos(row, col);
			vec.push_back(pos);
		}
	
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) {
			
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else 
			break;
	}

	// Left
	row = curPos->GetRow();
	col = curPos->GetCol();
	while (col > 0) {
		if (board->GetPieceAt(row, --col) == NULL) {
			Position pos(row, col);
			vec.push_back(pos);
		}
	
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) {
			
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else 
			break;
	}

	// Right
	row = curPos->GetRow();
	col = curPos->GetCol();
	while (col < 7) {
		if (board->GetPieceAt(row, ++col) == NULL) {
			Position pos(row, col);
			vec.push_back(pos);
		}
	
		else if ((board->GetPieceAt(row, col))->GetColor() != this->GetColor()) {
			
			Position pos(row, col);
			vec.push_back(pos);
			break;
		}
		else 
			break;
	}

	return vec;
}