コード例 #1
0
// just gets the first jump it finds for now
Checkers::Move MoveMaker::getJump()
{
	Checkers::Move move = {Checkers::SW, 22};
	vector<Checker*> myCheckers = m_board.getComputerCheckers();
	vector<Checker*>::iterator it;
	for (it = myCheckers.begin(); it != myCheckers.end(); ++it)
	{
		Checker* checker = *it;
		Square* sq = (*it)->getSquare();

		Square* neighbor = sq->getSW();
		if (neighbor != nullptr && neighbor->getChecker() != nullptr)
		{
			Checker* neighborChecker = neighbor->getChecker();
			if (neighborChecker->getColor() == Checkers::RED)
			{
				Square* jumpSquare = neighbor->getSW();
				if (jumpSquare != nullptr && jumpSquare->getChecker() == nullptr)
				{
					move.index = checker->getIndex();
					move.dir = Checkers::SW;
					break;
				}
			}
		}
		neighbor =sq->getSE();
		if (neighbor != nullptr && neighbor->getChecker() != nullptr)
		{
			Checker* neighborChecker = neighbor->getChecker();
			if (neighborChecker->getColor() == Checkers::RED)
			{
				Square* jumpSquare = neighbor->getSE();
				if (jumpSquare != nullptr && jumpSquare->getChecker() == nullptr)
				{
					move.index = checker->getIndex();
					move.dir = Checkers::SE;
					break;
				}
			}
		}
	}
	return move;
}
コード例 #2
0
bool Checker::hasJump(Checkers::DirectionType dir)
{
	Square* neighbor = Checkers::getNeighborSquare(m_square, dir);
	if (neighbor != nullptr)
	{
		Checker* checker = neighbor->getChecker();
		if (checker != nullptr && checker->getColor() != m_myColor)
		{
			Square* jumpSquare = Checkers::getNeighborSquare(neighbor, dir);
			if (jumpSquare != nullptr && jumpSquare->getChecker() == nullptr)
			{
				return true;
			}
		}
	}
	return false;
}