示例#1
0
int WordController::SolidTest(Field board[15][15], vector <Letter*>* existLetters, Word * word)
{
	Word * tempWord = new Word();
	int totalPoints = 0;
	bool good = false;
	for (int i = 0; i < word->letters.size(); i++)
	{
		int pos_x = word->letters[i]->getPositionX();
		int pos_y = word->letters[i]->getPositionY();

		Letter * temp = GetLetterOnBoard(board, existLetters, GetField(board, existLetters, pos_x + 40, pos_y));
		Letter * temp2 = GetLetterOnBoard(board, existLetters, GetField(board, existLetters, pos_x - 40, pos_y));
		Letter * temp3 = GetLetterOnBoard(board, existLetters, GetField(board, existLetters, pos_x, pos_y + 40));
		Letter * temp4 = GetLetterOnBoard(board, existLetters, GetField(board, existLetters, pos_x, pos_y - 40));
		
		// Sprawdzamy czy litera ma jakis sasiadow
		if (temp == nullptr && temp2 == nullptr && temp3 == nullptr && temp4 == nullptr)
		{
			std::string excep = "Alone Letter";
			throw excep;
		}

		// Jezeli jednak cos wystepuje kolo tej litery i nie jest to litera z tego slowa
		if ((temp != nullptr && !CheckIfLetterExist(word, temp)) || (temp2 != nullptr && !CheckIfLetterExist(word, temp2)) ||
			(temp3 != nullptr && !CheckIfLetterExist(word, temp3)) || (temp4 != nullptr && !CheckIfLetterExist(word, temp4)))
		{
			good = true;
		}
		
	}
	if (!good)
	{
		std::string excep = "Slowo nie laczy sie z juz istniejacym";
		throw excep;
	}

	if (horizontal)
	{
		for (int i = 0; i < word->letters.size(); i++)
		{
			int pos_x = word->letters[i]->getPositionX();
			int pos_y = word->letters[i]->getPositionY();
			Field * begin = GetField(board, existLetters, pos_x, pos_y);

			tempWord = CheckVertical(board, existLetters, GetLetterOnBoard(board, existLetters, begin));

			if (tempWord != nullptr)
			{
				wordForCheck.push_back(tempWord);
			}
			if(tempWord != nullptr)
				if (tempWord->letters.size() > 1)
				{
					cout << "\n PUNKTY: " << CountPoints(board, existLetters, tempWord);
					totalPoints += CountPoints(board, existLetters, tempWord);
				}
		}

		int pos_x = word->letters[0]->getPositionX();
		int pos_y = word->letters[0]->getPositionY();
		Field * begin = GetField(board, existLetters, pos_x, pos_y);
		tempWord = CheckHorizontal(board, existLetters, GetLetterOnBoard(board, existLetters, begin));
		if (tempWord != nullptr)
		{
			wordForCheck.push_back(tempWord);
		}
		if (tempWord != nullptr)
			if (tempWord->letters.size() > 1)
			{
				cout << "\n PUNKTY: " << CountPoints(board, existLetters, tempWord);
				totalPoints += CountPoints(board, existLetters, tempWord);
			}
	}
	else if (vertical)
	{
		for (int i = 0; i < word->letters.size(); i++)
		{
			int pos_x = word->letters[i]->getPositionX();
			int pos_y = word->letters[i]->getPositionY();
			Field * begin = GetField(board, existLetters, pos_x, pos_y);

			tempWord = CheckHorizontal(board, existLetters, GetLetterOnBoard(board, existLetters, begin));
			if (tempWord != nullptr)
			{
				wordForCheck.push_back(tempWord);
			}
			if (tempWord != nullptr)
				if (tempWord->letters.size() > 1)
				{
					cout << "\n PUNKTY: " << CountPoints(board, existLetters, tempWord);
					totalPoints += CountPoints(board, existLetters, tempWord);
				}

		}

		int pos_x = word->letters[0]->getPositionX();
		int pos_y = word->letters[0]->getPositionY();
		Field * begin = GetField(board, existLetters, pos_x, pos_y);
		tempWord = CheckVertical(board, existLetters, GetLetterOnBoard(board, existLetters, begin));
		if (tempWord != nullptr)
		{
			wordForCheck.push_back(tempWord);
		}
		if (tempWord != nullptr)
			if (tempWord->letters.size() > 1)
			{
				cout << "\n PUNKTY: " << CountPoints(board, existLetters, tempWord);
				totalPoints += CountPoints(board, existLetters, tempWord);
			}

		
	}
	else //Czyli w przypadku gdy dostawiamy pojednycza literke
	{
		int pos_x = word->letters[0]->getPositionX();
		int pos_y = word->letters[0]->getPositionY();
		Field * begin = GetField(board, existLetters, pos_x, pos_y);
		tempWord = CheckVertical(board, existLetters, GetLetterOnBoard(board, existLetters, begin));
		if (tempWord != nullptr)
		{
			wordForCheck.push_back(tempWord);
		}
		if (tempWord != nullptr)
			if (tempWord->letters.size() > 1)
			{
				cout << "\n PUNKTY: " << CountPoints(board, existLetters, tempWord);
				totalPoints += CountPoints(board, existLetters, tempWord);
			}
		tempWord =  CheckHorizontal(board, existLetters, GetLetterOnBoard(board, existLetters, begin));
		if (tempWord != nullptr)
		{
			wordForCheck.push_back(tempWord);
		}
		if (tempWord != nullptr)
			if (tempWord->letters.size() > 1)
			{
				cout << "\n PUNKTY: " << CountPoints(board, existLetters, tempWord);
				totalPoints += CountPoints(board, existLetters, tempWord);
			}
	}

	//delete tempWord;
	return totalPoints;
}
示例#2
0
bool WordController::QuickCheck(Field board[15][15], vector <Letter*>* existLetters, Word * word)
{
	//TO DO sprawdzenie sensu pierwszego worda
	horizontal = false;
	vertical = false;
	bool good = false;

	sort(word->letters.begin(), word->letters.end(), Word::compareTwoLeters);
	
	//Jezeli dostawiamy tylko jedna literke sprawdzamy czy sasiaduje ona z czyms
	if (word->letters.size() == 1)
	{
		int pos_x = word->letters[0]->getPositionX();
		int pos_y = word->letters[0]->getPositionY();
		Field * begin = GetField(board, existLetters, pos_x, pos_y);
		if (CheckVertical(board, existLetters, GetLetterOnBoard(board, existLetters, begin)) ||
			CheckHorizontal(board, existLetters, GetLetterOnBoard(board, existLetters, begin)))
			return true;
	}
	//Tutaj sprawdzamy czy podane slowo jest w jednej linii
	for (int i = 0; i < word->letters.size() - 1; i++)
	{
		if (word->letters.at(i)->getPositionX() == word->letters.at(i + 1)->getPositionX())
		{
			vertical = true;
		}
		else
		{
			if (vertical)
			{
				std::string excep = "Not at one line";
				throw excep;
			}
			vertical = false;
		}
		if (word->letters.at(i)->getPositionY() == word->letters.at(i + 1)->getPositionY())
		{
			horizontal = true;
		}
		else
		{
			if (horizontal)
			{
				std::string excep = "Not at one line";
				throw excep;
			}
			horizontal = false;
		}

	}

	if (!vertical && !horizontal)
	{
		std::string excep = "Not at one line or something";
		throw excep;
		return false;
	}
	else
	{
		return true;
	}

}
示例#3
0
/**
 * Checks if a move is valid.
 *
 * @param x
 *   x-pos
 * @param y
 *   x-pos
 * @param e
 *   number we want to add
 * @return
 *  Valid or invalid (already there)
 * @warning
 *  Method assumes that the board is valid before the move
 */
bool Board::IsValidMove(int x, int y, int e) const {
    if (CheckHorizontal(x, y, e) && CheckVertical(x, y, e) && CheckBlock(x, y, e)) // Lazy evaluation guarantees efficient handling
        return true;
    else
        return false;
}