Changeset 86 for 06/devel/agl.cc

Show
Ignore:
Timestamp:
03/12/04 23:10:50 (4 years ago)
Author:
ug
Message:

Further C++ transcoding (algos, agl)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/devel/agl.cc

    r14 r86  
    132132    sgf = f.read(); 
    133133    f.close(); 
    134     node = Cursor(sgf, 1).getRootNode(q.second); 
     134    Node node = Cursor(sgf, 1).getRootNode(q.second); // FIXME: node should be the node itself, not the data dict 
    135135  } 
    136136  catch(...) return ""; 
    137137 
    138         t = '' 
    139          
    140         if node.has_key('PW'): t = t + node['PW'][0] 
    141         else: t = t + ' ?' 
    142         if node.has_key('WR'): t = t + ', ' + node['WR'][0] 
    143  
    144         t = t + ' - ' 
    145  
    146         if node.has_key('PB'): t = t + node['PB'][0] 
    147         else: t = t + ' ?' 
    148         if node.has_key('BR'): t = t + ', ' + node['BR'][0] 
    149  
    150         if node.has_key('RE'): t = t + ', ' + node['RE'][0] 
    151         if node.has_key('KM'): t = t + ' (Komi ' + node['KM'][0] + ')' 
    152         if node.has_key('HA'): t = t + ' (Hcp ' + node['HA'][0] + ')' 
    153  
    154         t = t + '\n' 
    155  
    156         if node.has_key('EV'): t = t + node['EV'][0] + ', ' 
    157         if node.has_key('RO'): t = t + node['RO'][0] + ', ' 
    158         if node.has_key('DT'): t = t + node['DT'][0] + '\n' 
    159  
    160         if node.has_key('GC'): 
    161             gc = node['GC'][0] 
    162             gc = replace(gc, '\n\r', ' ') 
    163             gc = replace(gc, '\r\n', ' ') 
    164             gc = replace(gc, '\r', ' ') 
    165             gc = replace(gc, '\n', ' ') 
    166              
    167             t = t + gc 
    168  
    169         try: 
    170             t2 = 'Commentary in ' +\ 
    171                  self.references[self.DBlist[`self.boardsize`][DBindex].namelist[self.DBlist[`self.boardsize`][DBindex].current[indexWithinCurrent]][4]] 
    172         except: t2 = '' 
    173  
    174         return t, t2 
     138  char* t = new char[]; 
     139         
     140  if (node.has_key("PW")) strcat(t, node.getstr("PW", 0)); 
     141  else strcat(t, " ?"); 
     142  if (node.has_key("WR")) strcat(t, node.getstr("WR", 0)); 
     143   
     144  strcat(t, " - "); 
     145 
     146  if (node.has_key("PB")) strcat(t, node.getstr("PB", 0)); 
     147  else strcat(t, " ?"); 
     148  if (node.has_key("BR")) strcat(t, node.getstr("BR", 0)); 
     149 
     150  if (node.has_key("RE")) strcat(t, node.getstr("RE", 0)); 
     151  if (node.has_key('KM')) { 
     152    strcat(t, " (Komi "); 
     153    strcat(t, node.getstr("KM", 0)); 
     154    strcat(t, ")"); 
     155  } 
     156  if (node.has_key("HA")) { 
     157    strcat(t, " (Hcp "); 
     158    strcat(t, node.getstr("HA", 0)); 
     159    strcat(t, ")"); 
     160  } 
     161 
     162  strcat(t, "\n"); 
     163 
     164  if (node.has_key("EV")) { 
     165    strcat(t, node.getstr("EV", 0)); 
     166    strcat(t, ", "); 
     167  } 
     168  if (node.has_key("RO")) { 
     169    strcat(t, node.getstr("RO", 0)); 
     170    strcat(t, ", "); 
     171  } 
     172  if (node.has_key("DT")) { 
     173    strcat(t, node.getstr("DT", 0)); 
     174    strcat(t, "\n"); 
     175  } 
     176 
     177  if (node.has_key("GC")) { 
     178    char* s = node.getstr("GC", 0); 
     179    char* gc = new char[strlen(s)+1]; 
     180    int gcIndex = 0 
     181      for(int i=0; i<strlen(s); i++)  
     182        if (s[i] != '\n' && s[i] != '\r') gc[gcIndex++] = s[i]; 
     183        else gc[gcIndex++] = ' '; 
     184    gc[gcIndex] = 0; 
     185    strcat(t, gc); 
     186    delete [] gc; 
     187  } 
     188 
     189  char* t2 = new char[]; 
     190  try { 
     191    t2 = 'Commentary in ' +\ 
     192      self.references[self.DBlist[`self.boardsize`][DBindex].namelist[self.DBlist[`self.boardsize`][DBindex].current[indexWithinCurrent]][4]]; 
     193  } 
     194  catch() else t2 = ''; 
     195 
     196  strcpy ...; 
     197  delete [] t; 
     198  delete [] t2; 
     199  return t, t2; 
    175200} 
    176201 
     
    182207  if (boardsize==9) bsize = 2; 
    183208   
    184   Bwins = Wwins = Owins = 0 ; 
     209  Bwins 0; 
     210  Wwins = 0; 
     211  Owins = 0; 
     212 
    185213  references = {}; 
    186214  gameIndex.clear(); 
    187215   
    188   for db in self.DBlist[`self.boardsize`]
     216  for(db in self.DBlist[`self.boardsize`])
    189217    success = db.loadDB(); 
    190218    if (success != 1) ...; 
     
    194222         
    195223  for bs in [9, 13, 19] { 
    196     if bs != self.boardsize: 
    197                 for db in self.DBlist[`bs`]: 
    198                     db.clear() 
     224    if (bs != self.boardsize) 
     225      for(db in self.DBlist[`bs`]) 
     226        db.clear(); 
    199227  } 
    200228}