home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 72 / IOPROG_72.ISO / soft / Codice / CRobots / Software / CRUTILS.ZIP / crutils.pp < prev    next >
Encoding:
Text File  |  1999-09-12  |  28.4 KB  |  1,183 lines

  1. {
  2.     CRUtils - CROBOTS (TM) Linux Utilities ver.2.04d - 12-set-1999
  3.         Copyright (C) 1999 Maurizio Camangi
  4.         CRUtils comes with ABSOLUTELY NO WARRANTY; for details read COPYING file.
  5.         This is free software, and you are welcome to redistribute it
  6.         under certain conditions; read COPYING file for details.
  7.  
  8.     Maurizio "Joshua" Camangi <joshua@ascu.unian.it>
  9. }
  10. program crutils;
  11.  
  12. uses crt,dos;
  13.  
  14. const
  15.     RELEASE    = 'ver.2.04d, 12-set-1999';
  16.     ABOUT1    = 'Copyright (C) 1999 Maurizio "Joshua" Camangi <joshua@ascu.unian.it>';
  17.         ABOUT2  = 'CRUtils comes with ABSOLUTELY NO WARRANTY; for details read COPYING file.';
  18.         ABOUT3  = 'This is free software, and you are welcome to redistribute it';
  19.         ABOUT4  = 'under certain conditions; read COPYING file for details.';
  20.     F    = '-> ';
  21.     EXTR    = '.r';
  22.     EXTC    = '.csv';
  23.     EXTH    = '.html';
  24.     EXTL    = '.log';
  25.     NUM_CHAR = ['0'..'9'];
  26.     UP2LOW : array['A'..'Z'] of char = ('a','b','c','d','e','f',
  27.     'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
  28.     'w','x','y','z');
  29.     PATHCHAR = [' ','/','\',':','.'];
  30.     CHARSET  = ['A'..'Z'];
  31.     INI    = 'crobots.ini';
  32.     NOHTML    = 'nohtml';
  33.     AVERAGE    = 100000;
  34.  
  35. type
  36.     QUARK    = array[1..4] of byte;
  37. var
  38.     choice    : byte;
  39.     title    : string[80];
  40.     rpath,
  41.     path    : pathstr;
  42.         SGNips  : longint;
  43.     batch    : boolean;
  44.     inifile : text;
  45.  
  46. procedure crob;
  47.  
  48. const
  49.      max      = 100;
  50.      log_path = 'crobots';
  51.  
  52. var
  53.    p          :array[1..MAX] of pathstr;
  54.    outpath,
  55.    crob_path  : pathstr;
  56.    outrand: array[1..10626] of QUARK;
  57.    g,
  58.    cy         :string[6];
  59.    save,
  60.    torneo,
  61.    video      :boolean;
  62.    np,
  63.    nm,
  64.    k,
  65.    i,
  66.    j,
  67.    x          :integer;
  68.    i1,i2,
  69.    i3,i4      :byte;
  70.    cc         :char;
  71.    t          :text;
  72.    file_r     :searchrec;
  73.    tot,match,
  74.    index,
  75.    cycles     :longint;
  76.  
  77.    procedure enter;
  78.    var
  79.      tmp:pathstr;
  80.      pth:boolean;
  81.      i,j:integer;
  82.    begin
  83.      write('Elenco robots ad inserimento <M>anuale o <A>utomatico ? ');
  84.      cc:=upcase(readkey);
  85.      if cc='M' then
  86.      begin
  87.      writeln(cc);
  88.      writeln;
  89.      writeln('Elenco robots ( non includere l''estensione <',EXTR,'> )');
  90.      writeln;
  91.      for i:=1 to np do
  92.      begin
  93.        write('Crobot  n^ ',i,' ',f,' ');
  94.        readln(p[i]);
  95.        p[i]:=p[i] + EXTR;
  96.      end;
  97.      end else
  98.      begin
  99.        writeln('Auto');
  100.        write('Path per la ricerca dei file con estensione ',EXTR,'    ',f,' ');
  101.        readln(tmp);
  102.        write('Vuoi includere il path nei nomi dei robots (s/N) ?  ',f,' ');
  103.        cc:=upcase(readkey);
  104.        if cc = 'S' then
  105.          pth:=true
  106.        else begin
  107.          cc:='N';
  108.          pth:=false;
  109.        end;
  110.        writeln(cc);
  111.        rpath:=concat(tmp,'*'+EXTR);
  112.        k:=0; writeln;
  113.        findfirst(rpath,archive,file_r);
  114.        while (doserror = 0) and (k <= np) do
  115.        begin
  116.          inc(k);
  117.          p[k]:=file_r.name;
  118.          for j:=1 to length(p[k]) do
  119.          if p[k][j] in CHARSET then p[k][j]:=UP2LOW[p[k][j]];
  120.          if pth then p[k]:=concat(tmp,p[k]);
  121.          writeln(p[k]);
  122.          findnext(file_r);
  123.        end;
  124.        if k=0 then
  125.        begin
  126.          writeln('Nessun robot trovato!');
  127.          halt(1);
  128.        end else if k < np then
  129.             begin
  130.               writeln('Numero dei robots trovati : ',k);
  131.               write('Vuoi continuare (s/N) ? ');
  132.               cc:=upcase(readkey);
  133.               if cc='S' then
  134.               begin
  135.               writeln(cc);
  136.               np:=k;
  137.               end else
  138.               begin
  139.                 writeln('N');
  140.                 halt(1);
  141.               end;
  142.             end;
  143.      end;
  144.        writeln;
  145.      end;
  146.  
  147.    procedure time_match;
  148.    const lnc = - 4.30103;
  149.          disksp1 = 0.35;
  150.          disksp2 = 0.082;
  151.    var
  152.      ecc : byte;
  153.      tsec,avec: longint;
  154.  
  155.    function log(x:longint):real;
  156.    begin
  157.      log:=ln(x)/ln(10);
  158.    end;
  159.  
  160. begin
  161.     if SGNips < 1000 then ecc:=5
  162.     else if SGNips < 3000 then ecc:=4
  163.       else if SGNips < 10000 then ecc:=3
  164.     else if SGNips < 20000 then ecc:=2
  165.        else ecc:=1;
  166.   if nm = 3 then
  167.     SGNips:=SGNips + (SGNips div 4)
  168.   else if nm = 2 then
  169.     SGNips:=SGNips + (SGNips div 3);
  170.   if cycles = 200000 then avec:=AVERAGE
  171.   else avec:=round( 1000*(log(cycles) + lnc) ) * 100;
  172.   tsec:=((tot*match*avec) div SGNips) + (ecc*tot);
  173.   write('Tempo stimato : ');
  174.   if tsec < 0 then begin
  175.     writeln('Non computabile.');
  176.     exit;
  177.   end;
  178.   if (tsec > 3600) then begin
  179.     write(tsec div 3600,'h');
  180.     tsec:=tsec mod 3600;
  181.     if (tsec > 60) then write(' ',tsec div 60,'min');
  182.   end else if (tsec > 60) then write(tsec div 60,'min')
  183.        else write(tsec,'sec');
  184.   writeln('.');
  185.   writeln('Spazio su disco necessario per il file batch  : ',tot*disksp2:0:0,'kB circa');
  186.   writeln('Spazio su disco necessario per il file di log : ',tot*match*disksp1:0:0,'kB circa')
  187. end;
  188.  
  189. begin
  190.   writeln;
  191.   if SGNips = 0 then begin
  192.     write('Quanti SGNips calcola il tuo PC ? ');
  193.     readln(SGNips);
  194.     if SGNips < 0 then begin
  195.       writeln('Ops!');
  196.       exit;
  197.     end;
  198.     writeln;
  199.   end;
  200.   repeat
  201.     write('Numero Crobots (min. 2 - max. ',MAX,') ',f,' ');
  202.     readln(np)
  203.   until (np > 1) and (np < max + 1);
  204.   writeln;
  205.   writeln('Vuoi generare un file batch con le specifiche di Torneo ?');
  206.   writeln('a) 4 crobots in simultanea; massimo 24 crobots totali.');
  207.   writeln('b) 200000 cicli per incontro.');
  208.   writeln('c) Almeno 1000 incontri tra ciascuna coppia di crobots.');
  209.   writeln('d) Sequenza di incontri (semi)casuale.');
  210.   write('(S/n) ',f,' ');
  211.   cc:=upcase(readkey);
  212.   if cc = 'N' then begin
  213.     writeln('N'); torneo:=FALSE;
  214.     repeat
  215.       writeln;
  216.       write('Numero crobots in simultanea: 2, 3 o 4 ?         ',f,' ');
  217.       readln(nm)
  218.     until (nm > 1) and (nm < 5);
  219.     write('Numero di ripetizioni per incontro (default=100) ',f,' ');
  220.     readln(g);
  221.     val(g,match,i);
  222.     if (g='') or (i <> 0) then begin
  223.       g:='100';
  224.       match:=100;
  225.     end else if (i=0) and (match < 1) then begin
  226.            g:='100';
  227.          match:=100;
  228.          end else writeln;
  229.     if np < 25 then torneo:=TRUE;
  230.     write('Numero cicli per incontro (default=200000)       ',f,' ');
  231.     readln(cy);
  232.     val(cy,cycles,i);
  233.     if (cy='') or (i <> 0) then begin
  234.       cy:='200000';
  235.       cycles:=200000;
  236.     end else if (i=0) and (cycles < 1) then begin
  237.            cy:='200000';
  238.          cycles:=200000;
  239.         end else writeln;
  240.   end else begin
  241.     writeln('S');
  242.     torneo:=TRUE;
  243.     nm:=4;
  244.     if (np < nm) then begin
  245.       writeln('Robots insufficienti !');
  246.       halt;
  247.     end else if (np > 24) then begin
  248.       writeln('Numero troppo elevato di robots !');
  249.       halt;
  250.     end;
  251.     cy:='200000'; cycles:=200000;
  252.     match:=2000 div ((np - 2) * (np - 3));
  253.     if (2000 mod ((np - 2) * (np - 3))) > 0 then inc(match);
  254.     str(match,g);
  255.   end;
  256.   tot:=0;
  257.   case nm of { Il metodo diretto di calcolo non funziona, bug del BP ? }
  258.   2 : for j:=1 to np-1 do
  259.     for k:=j+1 to np do
  260.         inc(tot);
  261.   3 : for j:=1 to np-2 do
  262.     for k:=j+1 to np-1 do
  263.       for x:=k+1 to np do
  264.                 inc(tot);
  265.   4 : for j:=1 to np-3 do
  266.     for k:=j+1 to np-2 do
  267.       for x:=k+1 to np-1 do
  268.         for i:=x+1 to np do begin
  269.         inc(tot);
  270.         if torneo then begin
  271.             outrand[tot][1]:=j;
  272.             outrand[tot][2]:=k;
  273.             outrand[tot][3]:=x;
  274.             outrand[tot][4]:=i;
  275.         end;
  276.            end;
  277.   end;
  278.   write('Ridirezione su ',log_path + EXTL,' (s/N) ? ');
  279.   cc:=upcase(readkey);
  280.   if cc='S' then begin
  281.            outpath:=log_path;
  282.            writeln(cc);
  283.          end
  284.     else begin
  285.        writeln('N');
  286.        write('Nuovo path e file di ridirezione (senza estensione ',EXTL,') ',f,' ');
  287.        readln(outpath);
  288.      end;
  289.   writeln;
  290.   enter;
  291.   writeln('Verranno generate ',tot,' combinazioni per un totale di ',tot*match,' incontri.');
  292.   time_match;
  293.   video:=false; save:=false;
  294.   writeln;
  295.   write('Vuoi salvare i dati su file "start"  (s/N) ? ');
  296.   cc:=upcase(readkey);
  297.   if cc='S' then
  298.   begin
  299.     writeln(cc);
  300.     crob_path:='start';
  301.     save:=true;
  302.   end
  303.     else begin
  304.        writeln('N');
  305.        write('Vuoi specificare un nuovo path  (s/N) ? ');
  306.        cc:=upcase(readkey);
  307.        if cc='S' then
  308.        begin
  309.           writeln(cc);
  310.           write('Nuovo path per il file batch "start" ',f,' ');
  311.           readln(crob_path);
  312.           crob_path:=concat(crob_path,'start');
  313.           save:=true;
  314.        end
  315.        else writeln('N');
  316.      end;
  317.   if save then
  318.     begin
  319.      {$I-}
  320.       assign(t,crob_path);
  321.       rewrite(t);
  322.      {$I+}
  323.       if IOresult <> 0 then begin
  324.                   writeln('Errore nella creazione del file ...');
  325.                   halt(1);
  326.                 end;
  327.     end else
  328.     begin
  329.       write('Vuoi vedere l''elenco su video   (s/N) ? ');
  330.       cc:=upcase(readkey);
  331.       if cc='S' then
  332.     begin
  333.       writeln(cc);
  334.      {$I-}
  335.       assigncrt(t);
  336.       rewrite(t);
  337.      {$I+}
  338.       video:=true;
  339.       if IOresult <> 0 then begin
  340.                   writeln('Errore nella creazione del file ...');
  341.                   halt(1);
  342.                 end;
  343.     end else begin
  344.            writeln('N');
  345.            exit;
  346.          end;
  347.     end;
  348.   writeln;
  349.   write('Attendi ... ');
  350.   if video then clrscr;
  351.   if torneo then randomize;
  352.   case nm of
  353.   2 : for j:=1 to np-1 do
  354.     for k:=j+1 to np do
  355.     writeln(t,concat('crobots -m',g,' -l',cy,' ',
  356.       p[j],' ',p[k],' <cr >>',outpath,EXTL));
  357.   3 : for j:=1 to np-2 do
  358.     for k:=j+1 to np-1 do
  359.       for x:=k+1 to np do
  360.         writeln(t,concat('crobots -m',g,' -l',cy,' ',
  361.         p[j],' ',p[k],' ',p[x],' <cr >>',outpath,EXTL));
  362.   4 : for j:=1 to np-3 do
  363.     for k:=j+1 to np-2 do
  364.       for x:=k+1 to np-1 do
  365.         for i:=x+1 to np do begin
  366.             if torneo then begin
  367.                 index:=random(tot) + 1;
  368.                 i1:=outrand[index][1];
  369.                 i2:=outrand[index][2];
  370.                 i3:=outrand[index][3];
  371.                 i4:=outrand[index][4];
  372.                 for cycles:=index to pred(tot) do outrand[cycles]:=outrand[succ(cycles)];
  373.                 dec(tot);
  374.             end else begin
  375.                 i1:=j; i2:=k; i3:=x; i4:=i;
  376.             end;
  377.         writeln(t,concat('crobots -m',g,' -l',cy,' ',
  378.           p[i1],' ',p[i2],' ',p[i3],' ',p[i4],' <cr >>',outpath,EXTL));
  379.    end;
  380.   end;
  381.   close(t);
  382.   writeln('OK!');
  383. end;
  384.  
  385. procedure parser;
  386.  
  387. const
  388.      WINS     = 'wins=';
  389.      M        = 6;
  390.      MAX      = 100;
  391.      MATCH    = 'Match';
  392.  
  393. type
  394.     robstr = string[10];
  395.     robot  = record
  396.            name  : robstr;
  397.            win,
  398.            tie,
  399.            play,
  400.            lose,
  401.            point : word;
  402.            eff   : real;
  403.          end;
  404.     robots = array[1..MAX] of robot;
  405.  
  406. var
  407.    rob            : robots;
  408.    strn,
  409.    description    : string[80];
  410.    index,
  411.    max_rob        : word;
  412.    mem_wins,
  413.    mem_ties       : array[1..MAX] of word;
  414.    work,
  415.    resultfile     : text;
  416.    ch             : char;
  417.    resultfilename : pathstr;
  418.  
  419.  
  420.    (* Bubble Sort per creare la classifica aggiornata *)
  421.  
  422.    procedure bsort(var vects : robots;n : word);
  423.    var
  424.        i,
  425.        j       : word;
  426.        flag    : boolean;
  427.        swapper : robot;
  428.    begin
  429.      i:=1;
  430.      repeat
  431.        inc(i);
  432.        flag:=true;
  433.        for j:=n downto i do
  434.      if (vects[j].point > vects[pred(j)].point) then
  435.      begin
  436.        swapper:=vects[j];
  437.        vects[j]:=vects[pred(j)];
  438.        vects[pred(j)]:=swapper;
  439.        flag:=false;
  440.      end
  441.      until flag or (n = i);
  442.    end;
  443.  
  444.  
  445.    (* Parsing della singola riga *)
  446.  
  447.    procedure pars;
  448.    var
  449.       code     : integer;
  450.       total    : word;
  451.       x        : string[M];
  452.       position,
  453.       cnt,
  454.       found    : byte;
  455.  
  456.    begin
  457.      index:=0;
  458.      found:=0;
  459.      while (index < max_rob) and (found < 2) do
  460.      begin
  461.        inc(index);
  462.        position:=pos(rob[index].name,strn);
  463.        if position > 0 then
  464.        if strn[pred(position)] in PATHCHAR then
  465.        begin
  466.      cnt:=position;
  467.      position:=pos(WINS,strn);
  468.      if position > 0 then
  469.      begin
  470.        inc(found);
  471.        inc(rob[index].play);
  472.        while strn[cnt] <> '=' do inc(cnt);
  473.        inc(cnt);
  474.        while strn[cnt] in NUM_CHAR do inc(cnt);
  475.        dec(cnt);
  476.        total:=0;
  477.        x:='      ';
  478.        position:=0;
  479.        while strn[cnt] in NUM_CHAR do
  480.        begin
  481.          x[M - position]:=strn[cnt];
  482.          dec(cnt);
  483.          inc(position);
  484.        end;
  485.        val(x,total,code);
  486.        if code = 0 then mem_wins[index]:=total;
  487.        inc(cnt);
  488.        while strn[cnt] <> '=' do inc(cnt);
  489.        inc(cnt);
  490.        while strn[cnt] in NUM_CHAR do inc(cnt);
  491.        dec(cnt);
  492.        total:=0;
  493.        x:='      ';
  494.        position:=0;
  495.        while strn[cnt] in NUM_CHAR do
  496.        begin
  497.          x[M - position]:=strn[cnt];
  498.          dec(cnt);
  499.          inc(position);
  500.        end;
  501.        val(x,total,code);
  502.        if code = 0 then mem_ties[index]:=total;
  503.      end;
  504.        end;
  505.      end;
  506.    end;
  507.  
  508.  
  509.    (* Inserimento manuale dei robots *)
  510.  
  511.    procedure man_rob;
  512.    var
  513.       loc_rob : string[8];
  514. {      l       : byte; }
  515.       count   : word;
  516.  
  517.    begin
  518.      count:=0;
  519.      while (count < 1) or (count > MAX) do
  520.      begin
  521.        writeln;
  522.        write('Inserisci il numero di ROBOTS ',F);
  523.        readln(count);
  524.      end;
  525.      writeln;
  526.      writeln('Inserisci i robots SENZA l''estensione ',EXTR,' e SENZA PATH');
  527.      writeln;
  528.      index:=0;
  529.      while (index < count) do
  530.      begin
  531.        inc(index);
  532.        write('Robot n^ ',index,' ',F);
  533.        readln(loc_rob);
  534.        if loc_rob <> '' then
  535.        begin
  536.      rob[index].name:=loc_rob + EXTR;
  537.      with rob[index] do
  538.      begin
  539.        play:=0;
  540.        win:=0;
  541.        tie:=0;
  542.        lose:=0;
  543.        point:=0;
  544.        eff:=0.0;
  545.      end;
  546.        end else dec(index);
  547.      end;
  548.      writeln;
  549.      max_rob:=index;
  550.      writeln('Robots totali         ',F,max_rob);
  551.    end;
  552.  
  553.  
  554.    (* Inserimento automatico dei robots *)
  555.  
  556.    procedure auto_rob;
  557.    var dirinfo   : searchrec;
  558.        old_path  : pathstr;
  559.        n         : word;
  560.        search    : robstr;
  561.        found,
  562.        not_exit  : boolean;
  563.        i         : byte;
  564.  
  565.    begin
  566.      if batch then begin (* Lettura dei nomi robots *)
  567.     index:=0;
  568.     while (not(eof(inifile)) and (index < MAX)) do begin
  569.         inc(index);
  570.         readln(inifile,rob[index].name);
  571.         for i:=1 to length(rob[index].name) do
  572.             if rob[index].name[i] in CHARSET then
  573.                 rob[index].name[i]:=UP2LOW[rob[index].name[i]];
  574.         rob[index].name:=rob[index].name+EXTR;
  575.     end;
  576.     max_rob:=index;
  577.     for i:=1 to max_rob do
  578.                with rob[i] do
  579.                begin
  580.                  play:=0;
  581.                  win:=0;
  582.                  tie:=0;
  583.                  lose:=0;
  584.                  point:=0;
  585.                  eff:=0.0;
  586.                end;
  587.      end else begin
  588. (* Interactive On *)
  589.      not_exit:=true;
  590.      while (max_rob = 0) or not_exit do
  591.      begin
  592.        writeln;
  593.        index:=0;
  594.        write('Inserisci il path completo dei Crobots ',F);
  595.        old_path:=rpath;
  596.        readln(rpath);
  597.        if (max_rob > 0) and (old_path = rpath) then
  598.        begin
  599.      writeln('Non posso cercare nella stessa subdirectory !');
  600.      writeln('I crobots devono essere tutti diversi !');
  601.        end else
  602.      begin
  603.        findfirst(rpath+'*'+EXTR,anyfile,dirinfo);
  604.        while doserror = 0 do
  605.        begin
  606.          inc(index);
  607.          if (index+max_rob) > MAX then
  608.          begin
  609.            write('Impossibile caricare altri crobots,');
  610.            writeln(' risorse esaurite !');
  611.            write('Continuo ? [s/N] : ',F);
  612.            ch:=upcase(readkey);
  613.            if (ch = 'S') then
  614.            begin
  615.          writeln(ch);
  616.          exit;
  617.            end else
  618.          begin
  619.            writeln('N');
  620.            halt(1);
  621.          end;
  622.          end;
  623.          found:=false;
  624.          rob[index+max_rob].name:=dirinfo.name;
  625.          for i:=1 to length(rob[index+max_rob].name) do
  626.          if rob[index+max_rob].name[i] in CHARSET then
  627.         rob[index+max_rob].name[i]:=UP2LOW[rob[index+max_rob].name[i]];
  628.          search:=rob[index+max_rob].name;
  629.          write('CRobot n^ ',index,' ',F,rob[index+max_rob].name,' ...');
  630.          n:=1;
  631.          while (n < (max_rob + index)) and not(found) do
  632.          begin
  633.            if (search = rob[n].name) then
  634.            begin
  635.          found:=true;
  636.          dec(index);
  637.            end;
  638.            inc(n);
  639.          end;
  640.          if not(found) then
  641.          begin
  642.            with rob[index+max_rob] do
  643.            begin
  644.          play:=0;
  645.          win:=0;
  646.          tie:=0;
  647.          lose:=0;
  648.          point:=0;
  649.          eff:=0.0;
  650.            end;
  651.            writeln(' OK!');
  652.          end else writeln(' gia'' trovato, NON valido !');
  653.          findnext(dirinfo);
  654.        end;
  655.      end;
  656.      max_rob:=max_rob+index;
  657.      writeln('CRobots trovati          ',F,index);
  658.      writeln('CRobots totali           ',F,max_rob);
  659.      if index = 0 then
  660.      begin
  661.        writeln('Nessun Crobot trovato !!');
  662.        if max_rob = 0 then
  663.        begin
  664.          writeln;
  665.          write('Vuoi uscire ? [s/N] ',F);
  666.          ch:=upcase(readkey);
  667.          if ch = 'S' then
  668.          begin
  669.            writeln(ch); halt(1);
  670.          end else writeln('N');
  671.       end;
  672.      end;
  673.      if max_rob > 0 then
  674.      begin
  675.        write('Altri Crobots ? [S/n] ',F);
  676.        ch:=upcase(readkey);
  677.        if (ch = 'N') then
  678.        begin
  679.          writeln(ch);
  680.          not_exit:=false;
  681.        end else writeln('S');
  682.      end;
  683.       end;
  684. (* Interactive Off *)
  685.       end;
  686.    end;
  687.  
  688.  
  689.    (* Apertura del file di LOG *)
  690.  
  691.    procedure init_log;
  692.  
  693.    begin
  694.      if batch then begin
  695.         readln(inifile,title); (* Lettura del titolo della pagin web *)
  696.     readln(inifile,path);  (* Lettura del nome file di log *)
  697.     {$I-}
  698.     assign(work,path + EXTL);
  699.      reset(work);
  700.     {$I+}
  701.     if IOresult <> 0 then begin
  702.          halt(1);
  703.     end;
  704.      end else begin
  705. (* Interactive On *)
  706.      writeln;
  707.      writeln('Inserisci il path completo e il nome del file LOG :');
  708.      write('Non includere l''estensione <',EXTL,'> ',F,' ');
  709.      readln(path);
  710.    {$I-}
  711.      assign(work,path + EXTL);
  712.      reset(work);
  713.    {$I+}
  714.      if IOresult <> 0 then
  715.      begin
  716.        writeln('Errore nell''apertura del file ',path + EXTL);
  717.        halt(1);
  718.      end;
  719.      end;
  720. (* Interactive Off *)
  721.    end;
  722.  
  723.    (* Parsing del file di LOG *)
  724.  
  725.    procedure parsing;
  726.    var
  727.        code      : integer;
  728.        index,
  729.        tmp       : word;
  730.        cnt,
  731.        position  : byte;
  732.        n_m       : string[M];
  733.  
  734.    begin
  735.      write('Parsing file ',F,path+EXTL,'...');
  736.      for index:=1 to max_rob do begin
  737.        mem_wins[index]:=0;
  738.        mem_ties[index]:=0;
  739.      end;
  740.      while not(eof(work)) do
  741.      begin
  742.        readln(work,strn);
  743.        cnt:=pos(MATCH,strn);
  744.        if cnt > 0 then
  745.        begin
  746.      while strn[cnt] <> ':' do inc(cnt);
  747.      dec(cnt);
  748.      n_m:='      ';
  749.      position:=0;
  750.      while strn[cnt] in NUM_CHAR do
  751.      begin
  752.        n_m[M - position]:=strn[cnt];
  753.        dec(cnt);
  754.        inc(position);
  755.      end;
  756.      val(n_m,tmp,code);
  757.      if tmp = 1 then
  758.        for index:=1 to max_rob do
  759.        begin
  760.          rob[index].win:=mem_wins[index] + rob[index].win;
  761.          rob[index].tie:=mem_ties[index] + rob[index].tie;
  762.          mem_wins[index]:=0;
  763.          mem_ties[index]:=0;
  764.        end;
  765.        end;
  766.        pars;
  767.      end;
  768.      for index:=1 to max_rob do
  769.      begin
  770.       rob[index].win:=mem_wins[index] + rob[index].win;
  771.       rob[index].tie:=mem_ties[index] + rob[index].tie;
  772.      end;
  773.      close(work);
  774.      writeln('OK!');
  775.    end;
  776.  
  777.    procedure result;
  778.    var
  779.       step               : byte;
  780.       winchar,
  781.       losechar,tiechar,
  782.       playchar,effchar,
  783.       pointchar          : string;
  784.       index             : word;
  785.  
  786.    begin
  787.      for index:=1 to max_rob do
  788.      begin
  789.        rob[index].point:=rob[index].win*3 + rob[index].tie;
  790.        rob[index].lose:=rob[index].play - rob[index].win - rob[index].tie;
  791.        if rob[index].play > 0 then
  792.      rob[index].eff:=(rob[index].point / (rob[index].play * 3)) * 100;
  793.      end;
  794.      bsort(rob,max_rob);
  795.      if not(batch) then begin
  796.         writeln;
  797.     write('Premi un tasto qualsiasi ...');
  798.          ch:=readkey;
  799.      end;
  800.      clrscr;
  801.      writeln;
  802.      writeln('Classifica finale ...');
  803.      writeln;
  804.      writeln('Pos)       Nome    Totali    Vinte    Nulle    Perse      PUNTI   Eff.%');
  805.      if max_rob > 20 then
  806.      for step:=0 to pred(max_rob div 20) do begin
  807.        if not(batch) then writeln;
  808.        for index:=1 to 20 do
  809.        begin
  810.        writeln(index + (step*20):3,') ',rob[index + (20*step)].name:10,
  811.        '   ',rob[index + (20*step)].play:7,
  812.       '   ',rob[index + (20*step)].win:6,
  813.       '   ',rob[index + (20*step)].tie:6,
  814.       '   ',rob[index + (20*step)].lose:6,
  815.          '   ',rob[index+ (20*step)].point:8,
  816.      '    ',rob[index + (20*step)].eff:4:1);
  817.        end;
  818.        if not(batch) then begin
  819.         writeln;
  820.         write('Premi un tasto qualsiasi ...');
  821.         ch:=readkey;
  822.         writeln;
  823.        end;
  824.      clrscr;
  825.      end;
  826.      step:=(max_rob div 20)*20;
  827.      if not(batch) then writeln;
  828.      for index:=1 to (max_rob mod 20) do
  829.      begin
  830.        writeln(index + step:3,') ',rob[index + step].name:10,
  831.        '   ',rob[index + step].play:7,'   ',rob[index + step].win:6,
  832.        '   ',rob[index + step].tie:6,'   ',rob[index + step].lose:6,
  833.        '   ',rob[index + step].point:8,'    ',rob[index + step].eff:4:1);
  834.      end;
  835.      writeln;
  836.      if not(batch) then begin
  837. (* Interactive On *)
  838.        write('Vuoi salvare i risultati sul file ',path,'.txt ? [S/n] ');
  839.        ch:=upcase(readkey);
  840.      if ch = 'N' then
  841.        writeln(ch)
  842.      else
  843.      begin
  844.        writeln('S');
  845.    {$I-}
  846.        assign(resultfile,path + '.txt');
  847.        rewrite(resultfile);
  848.    {$I+}
  849.        if IOResult <> 0 then
  850.        begin
  851.      writeln;
  852.      writeln('Errore nella ceazione del file ',path +'.txt');
  853.      writeln('Il programma verra'' terminato');
  854.      halt(1);
  855.        end;
  856.        writeln(resultfile,'Classifica finale ...');
  857.        writeln(resultfile);
  858.        writeln(resultfile,'Pos)       Nome    Totali    Vinte    Nulle    Perse      PUNTI   Eff.%');
  859.        for index:=1 to max_rob do
  860.        begin
  861.      writeln(resultfile,index:3,') ',rob[index].name:10,
  862.      '   ',rob[index].play:7,'   ',rob[index].win:6,
  863.      '   ',rob[index].tie:6,'   ',rob[index].lose:6,
  864.      '   ',rob[index].point:8,'    ',rob[index].eff:4:1);
  865.        end;
  866.        close(resultfile);
  867.        if not(batch) then begin
  868.      writeln('Fatto ...');
  869.          writeln;
  870.        end;
  871.      end;
  872.      write('Vuoi salvare i risultati su file EXCEL CSV ? [S/n] ');
  873.      ch:=upcase(readkey);
  874.      if ch = 'N' then
  875.        writeln(ch)
  876.      else
  877.      begin
  878.        writeln('S');
  879.        write('Inserisci il nome e il path del file senza estensione (',EXTC,') ',F,' ');
  880.        readln(resultfilename);
  881.    {$I-}
  882.        assign(resultfile,resultfilename + EXTC);
  883.        rewrite(resultfile);
  884.    {$I+}
  885.        if IOResult <> 0 then
  886.        begin
  887.      writeln;
  888.      writeln('Errore nella ceazione del file ',resultfilename);
  889.      writeln('Il programma verra'' terminato');
  890.      halt(1);
  891.        end;
  892.        writeln;
  893.        writeln(resultfile,'Nome CRobot;Giocate;Vinte;Nulle;Perse;Punti;Efficienza');
  894.        for index:=1 to max_rob do
  895.        begin
  896.      str(rob[index].play,playchar);
  897.      str(rob[index].win,winchar);
  898.      str(rob[index].tie,tiechar);
  899.      str(rob[index].point,pointchar);
  900.      str(rob[index].eff:0:1,effchar);
  901.      effchar[pos('.',effchar)]:=',';
  902.      effchar:=concat(effchar,'%');
  903.      str(rob[index].lose,losechar);
  904.      writeln(resultfile,rob[index].name + ';'
  905.      + playchar + ';' + winchar + ';'
  906.      + tiechar + ';' + losechar + ';'
  907.      + pointchar + ';' + effchar);
  908.        end;
  909.        close(resultfile);
  910.        writeln('Fatto ...');
  911.      end;
  912.      writeln;
  913.      write('Vuoi salvare i risultati su file HTML ? [S/n] ');
  914.      ch:=upcase(readkey);
  915.      end else ch:='S';
  916. (* Interactive Off *)
  917.      if ch = 'N' then
  918.        writeln(ch)
  919.      else
  920.      begin
  921.        if not(batch) then begin
  922.      writeln('S');
  923.          write('Inserisci il nome e il path del file senza estensione (',EXTH,') ',F,' ');
  924.          readln(resultfilename);
  925.        end else resultfilename:=path;
  926.      if (not(batch) or (batch and (title <> NOHTML))) then begin
  927. (* HTML file in batch mode *)
  928.    {$I-}
  929.        assign(resultfile,resultfilename + EXTH);
  930.        rewrite(resultfile);
  931.    {$I+}
  932.        if IOResult <> 0 then
  933.        begin
  934.      writeln;
  935.      writeln('Errore nella ceazione del file ',resultfilename);
  936.      writeln('Il programma verra'' terminato');
  937.      halt(1);
  938.        end;
  939. (* HTML file in batch mode *)
  940.      end;
  941.        if not(batch) then begin
  942. (* Interactive On *)
  943.        write('Inserisci il titolo della pagina HTML ',F);
  944.        readln(title);
  945.        write('Inserisci la descrizione della pagina HTML ',F);
  946.        readln(description);
  947.        writeln;
  948. (* Interactive Off *)
  949.        end else description:='Torneo di Crobots';
  950.       if (not(batch) or (batch and (title <> NOHTML))) then begin
  951. (* HTML file in batch mode *)
  952.        writeln(resultfile,'<html>');
  953.        writeln(resultfile,'<!-- CRUtils (C) 1999 Maurizio Camangi -->');
  954.        writeln(resultfile,'<!-- Written by Maurizio "Joshua" Camangi, "joshua@ascu.unian.it"  -->');
  955.        writeln(resultfile,'<!-- This is free software: read COPYING file for details. -->');
  956.        writeln(resultfile,'<head>');
  957.        writeln(resultfile,'<meta name="GENERATOR" content="CRUTILS ',RELEASE,'">');
  958.        writeln(resultfile,'<meta name="KEYWORDS" content="Crobots Crutils">');
  959.        writeln(resultfile,'<meta name="DESCRIPTION" content="',description,'">');
  960.        writeln(resultfile,'<title>',title,'</title>');
  961.        writeln(resultfile,'</head>');
  962.        writeln(resultfile,'<body text="#000000" bgcolor="#FFFFFF"><center>');
  963.        writeln(resultfile,'<table border>');
  964.        writeln(resultfile,'<caption align=top>',title,'</caption>');
  965.        writeln(resultfile,'<tr nowrap>');
  966.        writeln(resultfile,'<th>Pos.</th><th>Nome CRobot</th><th>Giocate</th>',
  967.                '<th>Vinte</th><th>Nulle</th><th>Perse</th>',
  968.                '<th>Punti</th><th>Efficienza</th>');
  969.        for index:=1 to max_rob do
  970.        begin
  971.      str(rob[index].play,playchar);
  972.      str(rob[index].win,winchar);
  973.      str(rob[index].tie,tiechar);
  974.      str(rob[index].point,pointchar);
  975.      str(rob[index].eff:0:1,effchar);
  976.      effchar[pos('.',effchar)]:=',';
  977.      effchar:=concat(effchar,'%');
  978.      str(rob[index].lose,losechar);
  979.      writeln(resultfile,'<tr><td>',rob[index].name
  980.      + '</td><td>' + playchar + '</td><td>' + winchar + '</td><td>'
  981.      + tiechar + '</td><td>' + losechar + '</td><td>'
  982.      + pointchar + '</td><td>' + effchar + '</td></tr>');
  983.        end;
  984.        writeln(resultfile,'</table></center></body></html>');
  985.        close(resultfile);
  986. (* HTML file in batch mode *)
  987.       end;
  988.        if not(batch) then writeln('Fatto ...');
  989.      end;
  990.    end;
  991.  
  992. begin
  993.   max_rob:=0; rpath:='none';
  994.   if batch then begin
  995.     init_log;
  996.     auto_rob;
  997.     parsing;
  998.     result;
  999.   end else begin
  1000. (* Inrteractive On *)
  1001.   writeln;
  1002.   write('Inserimento robots <M>anuale o <A>utomatico ?  ',F);
  1003.   ch:=upcase(readkey);
  1004.   if ch='M' then begin
  1005.     writeln('Manuale');
  1006.     man_rob;
  1007.   end
  1008.     else begin
  1009.       writeln('Automatico');
  1010.       auto_rob;
  1011.     end;
  1012.   init_log;
  1013.   parsing;
  1014.   result;
  1015.   writeln;
  1016.   writeln('OK!');
  1017.   end;
  1018. (* Interactive Off *)
  1019. end;
  1020.  
  1021. procedure cycles;
  1022.  
  1023. const
  1024.     cy        = 'cycles =';
  1025.  
  1026. var
  1027.     lpath         : pathstr;
  1028.     work        : text;
  1029.     ch        : char;
  1030.     nfiles        : byte;
  1031.     globmatch,
  1032.     globcycles,
  1033.     totmatch,
  1034.     totcycles       : longint;
  1035.  
  1036. procedure open_file;
  1037. begin
  1038.   write('Inserisci il path e il file di LOG senza estensione ',f);
  1039.   readln(lpath);
  1040.   lpath:=lpath + EXTL;
  1041. {$I-}
  1042.   assign(work,lpath);
  1043.   reset(work);
  1044. {$I+}
  1045.   if IOresult <> 0 then
  1046.   begin
  1047.     writeln('Errore nell''apertura del file ',lpath);
  1048.     writeln('Programma terminato ...');
  1049.     halt(1);
  1050.   end;
  1051.   inc(nfiles);
  1052. end;
  1053.  
  1054. procedure r_cycles;
  1055. var
  1056.     instr    : string[80];
  1057.     strcy    : string[6];
  1058.     code    : integer;
  1059.     temp    : longint;
  1060.     pos1,
  1061.     pos2    : byte;
  1062. begin
  1063.   totcycles:=0;
  1064.   totmatch:=0;
  1065.   while not(eof(work)) do
  1066.   begin
  1067.     readln(work,instr);
  1068.     pos1:=pos(cy,instr);
  1069.     if pos1 > 0 then
  1070.     begin
  1071.       inc(totmatch);
  1072.       while instr[pos1] <> ':' do inc(pos1);
  1073.       pos2:=pred(pos1);
  1074.       strcy:='      ';
  1075.       pos1:=0;
  1076.       while instr[pos2] in num_char do
  1077.       begin
  1078.     strcy[6 - pos1]:=instr[pos2];
  1079.         inc(pos1);
  1080.     dec(pos2);
  1081.       end;
  1082.       val(strcy,temp,code);
  1083.       if code = 0 then totcycles:=totcycles + temp;
  1084.     end;
  1085.   end;
  1086. end;
  1087.  
  1088. procedure close_file;
  1089. begin
  1090.   write('Partite giocate         ',f); writeln(totmatch);
  1091.   write('Media cicli per partita ',f); writeln(totcycles div totmatch);
  1092.   writeln;
  1093.   if nfiles = 1 then
  1094.   begin
  1095.     globmatch:=totmatch;
  1096.     globcycles:=totcycles;
  1097.   end else
  1098.   begin
  1099.     globmatch:=globmatch + totmatch;
  1100.     globcycles:=globcycles + totcycles;
  1101.     write('Partite globali giocate         ',f); writeln(globmatch);
  1102.     write('Media globale cicli per partita ',f); writeln(globcycles div globmatch);
  1103.   end;
  1104.   close(work);
  1105. end;
  1106.  
  1107. begin
  1108.   globmatch:=0;
  1109.   globcycles:=0;
  1110.   nfiles:=0;
  1111.   repeat
  1112.     writeln;
  1113.     open_file;
  1114.     write('Lettura ',lpath,' ...');
  1115.     r_cycles;
  1116.     writeln('OK');
  1117.     writeln;
  1118.     close_file;
  1119.     writeln;
  1120.     write('Altro file [S]i/[n]o ? ',f); ch:=upcase(readkey);
  1121.     if ch = 'N' then writeln(ch)
  1122.     else writeln('S');
  1123.   until ch = 'N';
  1124.   writeln;
  1125.   writeln('OK!');
  1126. end;
  1127.  
  1128. BEGIN
  1129.   clrscr;
  1130.   writeln;
  1131.   writeln('CRUtils - Crobots (TM) Utilities Collection ',RELEASE);
  1132.   writeln(ABOUT1);
  1133.   writeln(ABOUT2);
  1134.   writeln(ABOUT3);
  1135.   writeln(ABOUT4);
  1136.   title:=NOHTML;
  1137. {$I-}
  1138.   assign(inifile,INI); (* Apertura di 'crobots.ini' *)
  1139.   reset(inifile);
  1140. {$I+}
  1141.   if IOresult <> 0 then batch:=FALSE
  1142.   else batch:=TRUE;
  1143.   if batch then begin
  1144.     writeln;
  1145.     writeln('Batch mode on...');
  1146.     writeln;
  1147.     parser
  1148.   end else begin
  1149. (* Interactive On *)
  1150.   SGNips:=0;
  1151.   repeat
  1152.     writeln;
  1153.     writeln('Quale utility vuoi utilizzare ?');
  1154.     writeln;
  1155.     writeln('1) Crobots batch file Creator.');
  1156.     writeln('2) Crobots LOG file Parser.');
  1157.     writeln('3) Cycles Counter.');
  1158.     writeln('0) Esci subito.');
  1159.     writeln;
  1160.     write('Inserisci la tua scelta ',F);
  1161. {$I-}
  1162.     readln(choice);
  1163.     case choice of
  1164.     1: crob;
  1165.     2: parser;
  1166.     3: cycles;
  1167.     0: begin
  1168.          writeln;
  1169.          writeln('Bye bye ...');
  1170.          halt(0);
  1171.        end
  1172.     end
  1173. {$I+}
  1174.   until true=false;
  1175. end;
  1176. (* Interactive Off *)
  1177.   if batch then close(inifile)
  1178.   else writeln;
  1179.   writeln('Bye bye ...');
  1180.   halt(0);
  1181.  
  1182. END.
  1183.