Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED]can someone help me fix this?  (Read 584 times)
0 Members and 1 Guest are viewing this topic.
Offline trvcic

Senior Newbie





« Posted 2012-12-18 22:24:40 »

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?
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
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

while(true) { be awesome; }
Offline davedes
« Reply #1 - Posted 2012-12-19 00:04:34 »

How can we help you if we don't know what you're trying to achieve? Wink

Offline trvcic

Senior Newbie





« Reply #2 - Posted 2012-12-19 01:21:43 »

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

while(true) { be awesome; }
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trvcic

Senior Newbie





« Reply #3 - Posted 2012-12-19 01:55:59 »

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 Wink)

while(true) { be awesome; }
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (38 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (61 views)
2014-09-21 02:42:18

BurntPizza (31 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (53 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!