| 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')) |
|---|
| 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')) { |
|---|
| 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 | |
|---|
| 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(); |
|---|
| 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 | } |
|---|
| 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 | } |
|---|