Changeset 172

Show
Ignore:
Timestamp:
12/08/05 22:38:31 (3 years ago)
Author:
ug
Message:

Continue work on algos.cc

Files:

Legend:

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

    r86 r172  
    2020//   The GNU GPL is also currently available at 
    2121//   http://www.gnu.org/copyleft/gpl.html 
     22 
     23#include <iostream> 
     24#include <fstream> 
     25using namespace std; 
    2226 
    2327#include "algos.h" 
     
    8993} 
    9094 
    91 void Algo_finalpos::finalize_process(datap) { 
     95void Algo_finalpos::finalize_process(PyObject* datap) { 
    9296  // FIXME 
    93   file = open(os.path.join(datap[0], 'finalpos'+ datap[1] + '.db'), 'wb'); 
    94   finalpos.tofile(file); 
     97        extract datap0, datap1 from datap 
     98        String fn = datap0 + "/finalpos" + datap1 + ".db"; // FIXME: linux specific!? 
     99        ofstream file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
     100  file.write(finalpos, finalposSize); 
    95101  file.close(); 
    96102} 
    97  
    98  
    99 Algo_finalpos::filelist = ['finalpos']; 
    100  
    101103 
    102104 
     
    134136 
    135137int Algo_finalpos::retrieve_db(datap) { 
    136   try { 
    137     delete []finalpos; 
    138     finalpos = new char[]; 
    139     filelist = [(self.finalpos, 'finalpos')]; 
    140     for(var, filename in filelist) { 
    141       file = open(os.path.join(datap[0], filename+datap[1]+'.db'), 'rb'); 
    142       while (1) { 
    143         try var.fromfile(file, 1000000); 
    144         except EOFError break; 
    145       } 
    146     } 
    147     file.close(); 
     138        String fn = ... "/finalpos" ...; 
     139        ifstream file (fn, ios::in|ios::binary|ios::ate); 
     140        if (file.is_open()) { 
     141                ifstream::pos_type size = file.tellg(); 
     142                delete [] finalpos; 
     143                finalpos = new char[size]; 
     144                file.seekg (0, ios::beg); 
     145                file.read (memblock, size); 
     146                file.close(); 
    148147    return 1; 
    149   } 
    150   except IOError return 0; 
     148        } 
     149  else cout << "Unable to open file"; 
     150  return 0; 
    151151} 
    152152 
     
    329329 
    330330void Algo_movelist::finalize_process(datap) { 
    331          
    332   filelist = [(self.posTable, 'posTable'), (self.mainlistArr, 'lists'), 
    333               (self.finalposC, 'finalposC')]; 
    334   for(var, filename in filelist) { 
    335     file = open(os.path.join(datap[0], filename + datap[1] + '.db'), 'wb'); 
    336     var.tofile(file); 
    337     file.close(); 
    338   } 
    339 
    340  
    341 Algo_movelist::filelist = ['posTable', 'lists', 'finalposC']; 
    342  
    343  
     331  // FIXME 
     332        extract datap0, datap1 from datap 
     333                 
     334        String fn = datap0 + "/posTable" + datap1 + ".db"; // FIXME: linux specific!? 
     335        ofstream file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
     336  file.write(posTable, posTableSize); // FIXME: posTable is vector, posTableSize does not exist 
     337  file.close(); 
     338         
     339        fn = datap0 + "/lists" + datap1 + ".db"; // FIXME: linux specific!? 
     340        file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
     341  file.write(mainlistArr, mainlistArrSize); // FIXME: mainlistArr is vector!, mainlistArrSize does not exist 
     342  file.close(); 
     343         
     344        fn = datap0 + "/finalposC" + datap1 + ".db"; // FIXME: linux specific!? 
     345        file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
     346  file.write(finalposC, finalposCSize); 
     347  file.close(); 
     348
    344349 
    345350void Algo_movelist::retrieve_db(datap) { 
    346351 
    347   // FIXME 
    348  
    349   try { 
    350     posTable = array('L'); 
    351     mainlistArr = array('B'); 
    352     finalposC = array('B'); 
    353     filelist = [(self.mainlistArr, 'lists'), (self.posTable, 'posTable'), 
    354                 (self.finalposC, 'finalposC')]; 
    355     for (var, filename in filelist) { 
    356       file = open(os.path.join(datap[0], filename+datap[1]+'.db'), 'rb'); 
    357       while (1) { 
    358         try var.fromfile(file, 1000000); 
    359         except EOFError break; 
    360       } 
    361     } 
    362     file.close(); 
     352        String fn = ... "/finalposC" ...; // FIXME 
     353        ifstream file (fn, ios::in|ios::binary|ios::ate); 
     354        if (file.is_open()) { 
     355                ifstream::pos_type size = file.tellg(); 
     356                delete [] finalposC; 
     357                finalposC = new char[size]; 
     358                file.seekg (0, ios::beg); 
     359                file.read (memblock, size); 
     360                file.close(); 
     361        } 
     362  else { 
     363                cout << "Unable to open file"; 
     364          return 0; 
     365        } 
     366        String fn = ... "/lists" ...; // FIXME 
     367        ifstream file (fn, ios::in|ios::binary|ios::ate); 
     368        if (file.is_open()) { 
     369                ifstream::pos_type size = file.tellg(); 
     370                delete [] mainlistArr; 
     371                mainlistArr = new char[size]; 
     372                file.seekg (0, ios::beg); 
     373                file.read (memblock, size); 
     374                file.close(); 
     375        } 
     376  else { 
     377                cout << "Unable to open file"; 
     378        return 0; 
     379        } 
     380        String fn = ... "/posTable" ...; // FIXME 
     381        ifstream file (fn, ios::in|ios::binary|ios::ate); 
     382        if (file.is_open()) { 
     383                ifstream::pos_type size = file.tellg(); 
     384                delete [] posTable; 
     385                posTable = new char[size]; // FIXME: not a char array??? 
     386                file.seekg (0, ios::beg); 
     387                file.read (memblock, size); 
     388                file.close(); 
    363389    return 1; 
    364   } 
    365   except IOError return 0; 
     390        } 
     391  else { 
     392                cout << "Unable to open file"; 
     393          return 0; 
     394        } 
     395        return 0; 
    366396} 
    367397 
     
    758788} 
    759789  
    760 void Algo_hash::finalize_process(datap) { 
     790void Algo_hash::finalize_process(PyObject* datap) { 
    761791  hash_global.newCtr(gameCtr); 
    762792  hash_global.sortedOutput(datap); 
    763793} 
    764  
    765 // filelist = ['hash', 'hashT'] 
    766794 
    767795 
     
    791819} 
    792820 
    793 int Algo_hash::retrieve_db(datap) { 
    794   try { 
    795     self.hashT = array('l'); 
    796     self.hash = array('B'); 
    797     filelist = [(self.hash, self.filename), (self.hashT, self.filename + 'T')]; 
    798     for (var, filename in filelist) { 
    799       file = open(os.path.join(datap[0], filename+datap[1]+'.db'), 'rb'); 
    800       while (1) { 
    801         try var.fromfile(file, 1000000); 
    802         except EOFError break; 
    803       } 
    804     } 
    805     file.close(); 
    806     return 1; 
    807   } 
    808   except IOError return 0; 
     821int Algo_hash::retrieve_db(PyObject* datap) { 
     822        String fn = ... filename ...; // FIXME 
     823        ifstream file (fn, ios::in|ios::binary|ios::ate); 
     824        if (file.is_open()) { 
     825                ifstream::pos_type size = file.tellg(); 
     826                delete [] hash; 
     827                hash = new char[size]; // FIXME: not a char array? 
     828                file.seekg (0, ios::beg); 
     829                file.read (memblock, size); 
     830                file.close(); 
     831        } 
     832  else { 
     833                cout << "Unable to open file"; 
     834          return 0; 
     835        } 
     836        String fn = ... filename + "T" ...; // FIXME 
     837        ifstream file (fn, ios::in|ios::binary|ios::ate); 
     838        if (file.is_open()) { 
     839                ifstream::pos_type size = file.tellg(); 
     840                delete [] hashT; 
     841                hashT = new char[size]; 
     842                file.seekg (0, ios::beg); 
     843                file.read (memblock, size); 
     844                file.close(); 
     845        } 
     846  else { 
     847                cout << "Unable to open file"; 
     848          return 0; 
     849        } 
     850  return 0; 
    809851} 
    810852 
     
    920962//                            'hash') 
    921963 
    922 //     filelist = ['hash', 'hashT'] 
    923  
    924964 
    925965// class Algo_hash_sides(Algo_hash): 
     
    930970 
    931971 
    932 //     filelist = ['hashC', 'hashCT'] 
    933  
    934972 
    935973// class Algo_hash_center(Algo_hash): 
     
    939977//         Algo_hash.__init__(poslist, 'hashS') 
    940978 
    941  
    942 //     filelist = ['hashS', 'hashST'] 
    943979 
    944980 
     
    11231159 
    11241160void Algo_intervals::finalize_process(datap) { 
    1125          
    1126   file = open(os.path.join(datap[0], 'movesarr' + datap[1] + '.db'), 'wb'); 
    1127   self.movesArr.tofile(file); 
     1161  // FIXME 
     1162        extract datap0, datap1 from datap 
     1163         
     1164        String fn = datap0 + "/movesarr" + datap1 + ".db"; // FIXME: linux specific!? 
     1165        ofstream file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
     1166  file.write(movesArr, movesArrSize); 
     1167  file.close(); 
     1168         
     1169        fn = datap0 + "/moveints" + datap1 + ".db"; // FIXME: linux specific!? 
     1170        file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
     1171  file.write(moveIntsArr, moveIntsArrSize); 
    11281172  file.close(); 
    11291173         
    1130   file = open(os.path.join(datap[0], 'moveints' + datap[1] + '.db'), 'wb'); 
    1131   self.moveIntsArr.tofile(file); 
    1132   file.close(); 
    1133  
    1134   filelist = ['movesarr', 'moveints']; 
    11351174}         
    11361175 
    11371176 
    11381177int Algo_intervals::retrieve_db(datap) { 
    1139   try { 
    1140     self.movesArr = array('L'); 
    1141     self.moveIntsArr = array('L'); 
    1142     filelist = [(self.movesArr, 'movesarr'), (self.moveIntsArr, 'moveints')]; 
    1143     for(var, filename in filelist) { 
    1144       file = open(os.path.join(datap[0], filename+datap[1]+'.db'), 'rb'); 
    1145       while (1) { 
    1146         try var.fromfile(file, 1000000); 
    1147         except EOFError break; 
    1148       } 
    1149     } 
    1150     file.close() 
    1151       return 1; 
    1152   } 
    1153   except IOError return 0; 
     1178        String fn = ... "/movesarr" ...; // FIXME 
     1179        ifstream file (fn, ios::in|ios::binary|ios::ate); 
     1180        if (file.is_open()) { 
     1181                ifstream::pos_type size = file.tellg(); 
     1182                delete [] movesArr; 
     1183                movesArr = new char[size]; // FIXME: not a char array? 
     1184                file.seekg (0, ios::beg); 
     1185                file.read (memblock, size); 
     1186                file.close(); 
     1187        } 
     1188  else { 
     1189                cout << "Unable to open file"; 
     1190          return 0; 
     1191        } 
     1192        String fn = ... "/moveints" ...; // FIXME 
     1193        ifstream file (fn, ios::in|ios::binary|ios::ate); 
     1194        if (file.is_open()) { 
     1195                ifstream::pos_type size = file.tellg(); 
     1196                delete [] moveIntsArr; 
     1197                moveIntsArr = new char[size]; // FIXME: not a char array? 
     1198                file.seekg (0, ios::beg); 
     1199                file.read (memblock, size); 
     1200                file.close(); 
     1201        } 
     1202  else { 
     1203                cout << "Unable to open file"; 
     1204          return 0; 
     1205        } 
     1206  return 0; 
    11541207} 
    11551208 
  • 06/devel/kombilo.py

    r170 r172  
    6060from board import * 
    6161import v 
    62 from patternPY import * 
     62try: 
     63    from patternPY import * 
     64except ImportError: 
     65    print 'ouch pattern' # FIXME 
     66    from patternPY import * 
    6367from searchPY import * 
    6468from aglPY import *