Changeset 185

Show
Ignore:
Timestamp:
09/26/06 20:38:39 (2 years ago)
Author:
ug
Message:

Minor fixes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/libkombilo/search.cc

    r184 r185  
    839839 
    840840void Algo_signature::branchpoint_process() { 
     841 
    841842} 
    842843 
     
    29572958int GameList::process(const char* sgf, const char* path, const char* fn) throw(SGFError,DBError) { 
    29582959 
    2959         Cursor c = Cursor(sgf, 1); // parse sgf sloppily 
    2960         // FIXME catch SGFError 
    2961  
    2962         Node* root = c.root->next; 
     2960        Cursor* c = 0; 
     2961        try { 
     2962                c = new Cursor(sgf, 1); // parse sgf sloppily 
     2963        } catch (SGFError) { 
     2964                return 1; 
     2965        } 
     2966 
     2967        Node* root = c->root->next; 
    29632968 
    29642969        int pos = 0; 
     
    30833088                // NodeStack branchpoints(); 
    30843089 
    3085                 while (current) { 
    3086                         counter++; 
    3087  
    3088                         // parse current node, watch out for B, W, AB, AW, AE properties 
    3089  
    3090                         const char* s = current->SGFstring.c_str(); 
    3091                         int lSGFstring = strlen(s); 
    3092                         int i = 0; 
    3093                         while (i < lSGFstring && s[i] != ';' && (s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t'))  
    3094                                 i++; 
    3095  
    3096                         if (i>=lSGFstring) { 
    3097                                 throw SGFError(); 
    3098                         } 
    3099                         if (s[i] != ';') { 
    3100                                 throw SGFError(); 
    3101                         } 
    3102                         i++; 
    3103  
    3104                         while (i < lSGFstring) { // while parsing 
    3105  
    3106                                 while (i < lSGFstring && (s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t'))  
     3090                try { 
     3091                        while (current) { 
     3092                                counter++; 
     3093 
     3094                                // parse current node, watch out for B, W, AB, AW, AE properties 
     3095 
     3096                                const char* s = current->SGFstring.c_str(); 
     3097                                int lSGFstring = strlen(s); 
     3098                                int i = 0; 
     3099                                while (i < lSGFstring && s[i] != ';' && (s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t'))  
    31073100                                        i++; 
    3108                                 if (i >= lSGFstring) break; 
    3109  
    3110                                 char ID[30]; 
    3111                                 int IDindex = 0; 
    3112  
    3113                                 while (i < lSGFstring && s[i] != '[' && IDindex < 30) { 
    3114                                         if (65 <= s[i] && s[i] <= 90) 
    3115                                                 ID[IDindex++] = s[i]; 
    3116                                         else if (!(97 <= s[i] && s[i] <= 122) && !(s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t')) { 
    3117                                                 throw SGFError(); 
    3118                                         } 
    3119                                         i++; 
    3120                                 } 
    3121  
    3122                                 i++; 
    3123  
    3124                                 if (i >= lSGFstring || IDindex >= 30 || !IDindex) { 
     3101 
     3102                                if (i>=lSGFstring) { 
    31253103                                        throw SGFError(); 
    31263104                                } 
    3127                                 ID[IDindex] = 0; // found next property ID 
    3128                                 bool IDrelevant= (!strcmp(ID,"B") || !strcmp(ID,"W") || !strcmp(ID,"AB") || !strcmp(ID,"AW") || !strcmp(ID,"AE")); 
    3129                                 char* propValue = new char[lSGFstring+1]; 
    3130                                 int propValueIndex = 0
    3131                                 int oldPropValueIndex = 0; 
    3132  
    3133                                 while (i < lSGFstring) { // while looking for property values of the current property 
    3134                                         while (s[i] != ']' && i < lSGFstring) { 
    3135                                                 if (s[i] == '\\') i++; 
    3136                                                if (!IDrelevant || s[i] == '\t' || s[i] == ' ' || s[i] == '\r' || s[i] == '\n') { 
    3137                                                         i++; 
    3138                                                        continue
    3139                                                } 
    3140                                                 if (97 <= s[i] && s[i] <= 96+boardsize) { // valid board coordinate? 
    3141                                                        propValue[propValueIndex++] = s[i]; 
    3142                                                 } else if (s[i] == 't') { ; // allow passes, but do not record them (we handle them a little sloppily here
    3143                                                 } else { 
    3144                                                        printf("Error 1\n"); 
     3105                                if (s[i] != ';') { 
     3106                                       throw SGFError(); 
     3107                                } 
     3108                                i++
     3109 
     3110                                while (i < lSGFstring) { // while parsing 
     3111 
     3112                                        while (i < lSGFstring && (s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t'))  
     3113                                                i++; 
     3114                                        if (i >= lSGFstring) break; 
     3115 
     3116                                        char ID[30]
     3117                                        int IDindex = 0; 
     3118 
     3119                                        while (i < lSGFstring && s[i] != '[' && IDindex < 30) { 
     3120                                                if (65 <= s[i] && s[i] <= 90
     3121                                                       ID[IDindex++] = s[i]; 
     3122                                                else if (!(97 <= s[i] && s[i] <= 122) && !(s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t')) { 
    31453123                                                        throw SGFError(); 
    31463124                                                } 
    31473125                                                i++; 
    31483126                                        } 
    3149                                         if (i >= lSGFstring) throw SGFError(); 
    3150                                         if (propValueIndex - oldPropValueIndex != 0 && propValueIndex - oldPropValueIndex != 2) { 
    3151                                                 printf("Error %d %d\n", propValueIndex, oldPropValueIndex); 
     3127 
     3128                                        i++; 
     3129 
     3130                                        if (i >= lSGFstring || IDindex >= 30 || !IDindex) { 
    31523131                                                throw SGFError(); 
    31533132                                        } 
    3154                                         oldPropValueIndex = propValueIndex; 
    3155  
    3156                                         i++; 
    3157  
    3158                                         while (i < lSGFstring && (s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t'))  
     3133                                        ID[IDindex] = 0; // found next property ID 
     3134                                        bool IDrelevant= (!strcmp(ID,"B") || !strcmp(ID,"W") || !strcmp(ID,"AB") || !strcmp(ID,"AW") || !strcmp(ID,"AE")); 
     3135                                        char* propValue = new char[lSGFstring+1]; 
     3136                                        int propValueIndex = 0; 
     3137                                        int oldPropValueIndex = 0; 
     3138 
     3139                                        while (i < lSGFstring) { // while looking for property values of the current property 
     3140                                                while (s[i] != ']' && i < lSGFstring) { 
     3141                                                        if (s[i] == '\\') i++; 
     3142                                                        if (!IDrelevant || s[i] == '\t' || s[i] == ' ' || s[i] == '\r' || s[i] == '\n') { 
     3143                                                                i++; 
     3144                                                                continue; 
     3145                                                        } 
     3146                                                        if (97 <= s[i] && s[i] <= 96+boardsize) { // valid board coordinate? 
     3147                                                                propValue[propValueIndex++] = s[i]; 
     3148                                                        } else if (s[i] == 't') { ; // allow passes, but do not record them (we handle them a little sloppily here) 
     3149                                                        } else { 
     3150                                                                printf("Error 1\n"); 
     3151                                                                throw SGFError(); 
     3152                                                        } 
     3153                                                        i++; 
     3154                                                } 
     3155                                                if (i >= lSGFstring) throw SGFError(); 
     3156                                                if (propValueIndex - oldPropValueIndex != 0 && propValueIndex - oldPropValueIndex != 2) { 
     3157                                                        printf("Error %d %d\n", propValueIndex, oldPropValueIndex); 
     3158                                                        throw SGFError(); 
     3159                                                } 
     3160                                                oldPropValueIndex = propValueIndex; 
     3161 
    31593162                                                i++; 
    31603163 
    3161                                         if (i >= lSGFstring || s[i] != '[') break; // end of node, or found next property 
    3162                                         else { // s[i] == '[', so another property value follows.  
    3163                                                 i++; 
     3164                                                while (i < lSGFstring && (s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t'))  
     3165                                                        i++; 
     3166 
     3167                                                if (i >= lSGFstring || s[i] != '[') break; // end of node, or found next property 
     3168                                                else { // s[i] == '[', so another property value follows.  
     3169                                                        i++; 
     3170                                                } 
    31643171                                        } 
    3165                                 } 
    3166                                 int p_len = propValueIndex/2; 
    3167  
    3168                                 if (!propValueIndex) { // in particular, this happens if !IDrelevant 
     3172                                        int p_len = propValueIndex/2; 
     3173 
     3174                                        if (!propValueIndex) { // in particular, this happens if !IDrelevant 
     3175                                                if (!strcmp(ID, "B") || !strcmp(ID, "W")) { 
     3176                                                        for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->pass_process(); 
     3177                                                } 
     3178                                                delete [] propValue; 
     3179                                                continue; 
     3180                                        } 
     3181 
    31693182                                        if (!strcmp(ID, "B") || !strcmp(ID, "W")) { 
    3170                                                 for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->pass_process(); 
    3171                                         } 
    3172                                         delete [] propValue; 
    3173                                         continue; 
    3174                                 } 
    3175  
    3176                                 if (!strcmp(ID, "B") || !strcmp(ID, "W")) { 
    3177                                         char x = propValue[0]-97; // 97 == ord('a'), (0,0) <= (x,y) <= (bs-1, bs-1) 
    3178                                         char y = propValue[1]-97; 
    3179  
    3180                                         if (!b.play(x, y, ID)) { 
    3181                                                 throw SGFError(); // FIXME: have to catch this! 
    3182                                         } 
    3183                                         Move m = b.undostack.top(); 
    3184  
    3185                                         for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->move_process(m); 
    3186                                 } else 
    3187                                         if (!strcmp(ID, "AB")) { 
    3188                                                 for(int pp=0; pp < p_len; pp++) { 
    3189                                                         char x = propValue[2*pp]-97; 
    3190                                                         char y = propValue[2*pp+1]-97; 
    3191                                                         if (!b.play(x, y, "B")) throw SGFError(); // FIXME: have to catch this! 
    3192                                                         for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->AB_process(x, y); 
     3183                                                char x = propValue[0]-97; // 97 == ord('a'), (0,0) <= (x,y) <= (bs-1, bs-1) 
     3184                                                char y = propValue[1]-97; 
     3185 
     3186                                                if (!b.play(x, y, ID)) { 
     3187                                                        throw SGFError(); 
    31933188                                                } 
     3189                                                Move m = b.undostack.top(); 
     3190 
     3191                                                for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->move_process(m); 
    31943192                                        } else 
    3195                                                 if (!strcmp(ID, "AW")) { 
     3193                                                if (!strcmp(ID, "AB")) { 
    31963194                                                        for(int pp=0; pp < p_len; pp++) { 
    31973195                                                                char x = propValue[2*pp]-97; 
    31983196                                                                char y = propValue[2*pp+1]-97; 
    3199                                                                 if (!b.play(x, y, "W")) throw SGFError(); // FIXME: have to catch this! 
    3200                                                                 for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->AW_process(x, y); 
     3197                                                                if (!b.play(x, y, "B")) throw SGFError(); 
     3198                                                                for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->AB_process(x, y); 
    32013199                                                        } 
    32023200                                                } else 
    3203                                                         if (!strcmp(ID, "AE")) { 
     3201                                                        if (!strcmp(ID, "AW")) { 
    32043202                                                                for(int pp=0; pp < p_len; pp++) { 
    32053203                                                                        char x = propValue[2*pp]-97; 
    32063204                                                                        char y = propValue[2*pp+1]-97; 
    3207                                                                         char removed = b.getStatus(x,y); 
    3208                                                                         if (removed==' ') throw SGFError(); 
    3209                                                                         b.remove(x, y); 
    3210                                                                         for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->AE_process(x, y, removed); 
     3205                                                                        if (!b.play(x, y, "W")) throw SGFError(); 
     3206                                                                        for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->AW_process(x, y); 
     3207                                                                } 
     3208                                                        } else { 
     3209                                                                if (!strcmp(ID, "AE")) { 
     3210                                                                        for(int pp=0; pp < p_len; pp++) { 
     3211                                                                                char x = propValue[2*pp]-97; 
     3212                                                                                char y = propValue[2*pp+1]-97; 
     3213                                                                                char removed = b.getStatus(x,y); 
     3214                                                                                if (removed==' ') throw SGFError(); 
     3215                                                                                b.remove(x, y); 
     3216                                                                                for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->AE_process(x, y, removed); 
     3217                                                                        } 
    32113218                                                                } 
    32123219                                                        } 
    3213                                                 delete [] propValue; 
    3214                         }  
    3215  
    3216                         for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->endOfNode_process(); 
    3217  
    3218                         // if (processVariations || cursor.noChildren() > 1) { // several variations start from this node; 
    3219                         //   for algo in algolist: algo.branchpoint_process(); 
    3220                         //   self.branchpoints.append((cursor.currentN, b.copy(), 0)); 
    3221                         //   print 'branchpoint' ; 
    3222                         // } 
    3223  
    3224                         current = current->next; 
    3225  
    3226                         // if (!current && self.branchpoints) { 
    3227                         //   // for algo in algolist: algo.endOfVariation_process() 
    3228                         //  
    3229                         //   cursor.currentN, b, whichVar = self.branchpoints.pop(); 
    3230                         //   if (whichVar+2 < cursor.noChildren()) { 
    3231                         //     for algo in algolist: algo.branchpoint_process(); 
    3232                         //     self.branchpoints.append((cursor.currentN, b.copy(), whichVar+1)); 
    3233                         //   } 
    3234                         //   cursor.next(whichVar+1) 
    3235                         // }  
    3236                 } // while 
     3220                                                        delete [] propValue; 
     3221                                }  
     3222 
     3223                                for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->endOfNode_process(); 
     3224 
     3225                                // if (processVariations || cursor.noChildren() > 1) { // several variations start from this node; 
     3226                                //   for algo in algolist: algo.branchpoint_process(); 
     3227                                //   self.branchpoints.append((cursor.currentN, b.copy(), 0)); 
     3228                                //   print 'branchpoint' ; 
     3229                                // } 
     3230 
     3231                                current = current->next; 
     3232 
     3233                                // if (!current && self.branchpoints) { 
     3234                                //   // for algo in algolist: algo.endOfVariation_process() 
     3235                                //  
     3236                                //   cursor.currentN, b, whichVar = self.branchpoints.pop(); 
     3237                                //   if (whichVar+2 < cursor.noChildren()) { 
     3238                                //     for algo in algolist: algo.branchpoint_process(); 
     3239                                //     self.branchpoints.append((cursor.currentN, b.copy(), whichVar+1)); 
     3240                                //   } 
     3241                                //   cursor.next(whichVar+1) 
     3242                                // }  
     3243                        } // while 
     3244                } 
     3245                catch (SGFError) { 
     3246                        // FIXME do we want to do anything here? 
     3247                } 
    32373248 
    32383249                for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->endgame_process();