[SOLVED]can someone help me fix this?

I’m making the game boggle, and it works 95% of the time. but when it checks if a word is valid, occasionally it will ‘forget’ where one of the letters were. I can’t figure out how or when it decides to mess up. could someone take a look at it?

private boolean checkIfBuildable(String wordToCheck){
		Point[] lettersUsed = new Point[wordToCheck.length()];
		int letterToCheck = 0;
		
		while(true){
			boolean letterFound = false;
			
			if(letterToCheck == 0){
				
				//first letter, first time
				if(lettersUsed[letterToCheck] == null){
					for(int row = 0; row < letters.length; row++){
						for(int col = 0; col < letters[row].length; col++){
							
							if(!letterFound){//we have to keep looking
								if(wordToCheck.charAt(letterToCheck) == letters[row][col]){
									
									//it's found
									lettersUsed[letterToCheck] = new Point(row, col);
									letterFound = true;
								}
							} else {
								break;//if letter is found, move to the next
							}
						}
					}
					
				//first letter, any time
				} else {
					for(int row = (int)lettersUsed[letterToCheck].getX(); row < letters.length; row++){
						for(int col = (int)lettersUsed[letterToCheck].getY(); col < letters[row].length; col++){

							if(!letterFound){
								if(wordToCheck.charAt(letterToCheck) == letters[row][col]){
									if(row > lettersUsed[letterToCheck].getX() || 
											(row == lettersUsed[letterToCheck].getX() && col > lettersUsed[letterToCheck].getY())){
										
										//it's found
										lettersUsed[letterToCheck] = new Point(row, col);
										letterFound = true;
									}
								}
							} else {
								break;//if letter is found, move to the next
							}
						}
					}
				}

			} else {
				
				//any letter, first time
				if (lettersUsed[letterToCheck] == null){
					for(int row = 0; row < letters.length; row++){
						for(int col = 0; col < letters[row].length; col++){

							if(!letterFound){
								if(wordToCheck.charAt(letterToCheck) == letters[row][col]){
									if(row > lettersUsed[letterToCheck - 1].getX() - 2 && row < lettersUsed[letterToCheck - 1].getX() + 2
											&& col > lettersUsed[letterToCheck - 1].getY() - 2 && col < lettersUsed[letterToCheck - 1].getY() + 2){
										
										//check if repeated
										boolean isRepeated = false;
										for(int check = 0; check < letterToCheck; check++){
											if(lettersUsed[check].equals(new Point(row, col))){
												isRepeated = true;
											}
										}
										
										if(!isRepeated){
											
											//it's found
											lettersUsed[letterToCheck] = new Point(row, col);
											letterFound = true;
										}
									}
								}
							} else {
								break;//if letter is found, move to the next
							}
						}
					}
					
				//any letter, any time
				} else {
					for(int row = (int)lettersUsed[letterToCheck].getX(); row < letters.length; row++){
						for(int col = (int)lettersUsed[letterToCheck].getY(); col < letters[row].length; col++){
							
							if(!letterFound){
								if(wordToCheck.charAt(letterToCheck) == letters[row][col]){

									if(row > lettersUsed[letterToCheck - 1].getX() - 2 && row < lettersUsed[letterToCheck - 1].getX() + 2 
											&& col > lettersUsed[letterToCheck - 1].getY() - 2 && col < lettersUsed[letterToCheck - 1].getY() + 2){

										if(row > lettersUsed[letterToCheck].getX() || 
												(row == lettersUsed[letterToCheck].getX() && col > lettersUsed[letterToCheck].getY())){
											
											//check if repeated
											boolean isRepeated = false;
											for(int check = 0; check < letterToCheck; check++){
												if(lettersUsed[check].equals(new Point(row, col))){
													isRepeated = true;
												}
											}
											if(!isRepeated){
												
												//it's found
												lettersUsed[letterToCheck] = new Point(row, col);
												letterFound = true;
											}
										}
									}
								}
							} else {
								break;//if letter is found, move to the next
							}
						}
					}
				}
			}
			
			
			
			//if we found the letter, we move on to the next one
			if(letterFound){
				if(letterToCheck > 0  && wordToCheck.charAt(letterToCheck - 1) == 'Q'){//if it's q
					lettersUsed[letterToCheck] = lettersUsed[letterToCheck - 1];//q and u have the same spot from qu
					letterToCheck++;
				}
				
				letterToCheck++;
							
			} else {//we need to look for a different spelling
				lettersUsed[letterToCheck] = null;
				
				//if the letter is the u from qu, skip back to the q
				if(letterToCheck > 0 && wordToCheck.charAt(letterToCheck - 1) == 'Q'){
					letterToCheck--;
				}

				letterToCheck--;
			}

			//it's done
			if(letterToCheck >= wordToCheck.length()){
				return true;
			}

			//if we can't find the first letter, or can't find a valid combination
			if(letterToCheck <= -1){
				return false;
			}
		}
	}

ps. i hope this looks alright, i’m pretty new to this site

How can we help you if we don’t know what you’re trying to achieve? :wink:

there is an error I can get rid of or explain. It would be cool if someone could like at it and possibly tell me if I did something wrong. (this was pretty much a last resort, I have no idea what could be causing my error)

the problem is that occasionally words that use a certain letter and are valid will return false, but I can’t find an pattern to it
(if you know how to play boggle)like any word that uses the e in the upper right corner is returns false

ps this was pretty much just a hail mary pass, I think something is wrong, but not with my code

sorry everyone, but I ended up rewriting the code, and it just worked. No idea why or where the error came from, but it’s gone now(hopefully ;))