home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-09-12 | 28.4 KB | 1,183 lines |
- {
- CRUtils - CROBOTS (TM) Linux Utilities ver.2.04d - 12-set-1999
- Copyright (C) 1999 Maurizio Camangi
- CRUtils comes with ABSOLUTELY NO WARRANTY; for details read COPYING file.
- This is free software, and you are welcome to redistribute it
- under certain conditions; read COPYING file for details.
-
- Maurizio "Joshua" Camangi <joshua@ascu.unian.it>
- }
- program crutils;
-
- uses crt,dos;
-
- const
- RELEASE = 'ver.2.04d, 12-set-1999';
- ABOUT1 = 'Copyright (C) 1999 Maurizio "Joshua" Camangi <joshua@ascu.unian.it>';
- ABOUT2 = 'CRUtils comes with ABSOLUTELY NO WARRANTY; for details read COPYING file.';
- ABOUT3 = 'This is free software, and you are welcome to redistribute it';
- ABOUT4 = 'under certain conditions; read COPYING file for details.';
- F = '-> ';
- EXTR = '.r';
- EXTC = '.csv';
- EXTH = '.html';
- EXTL = '.log';
- NUM_CHAR = ['0'..'9'];
- UP2LOW : array['A'..'Z'] of char = ('a','b','c','d','e','f',
- 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
- 'w','x','y','z');
- PATHCHAR = [' ','/','\',':','.'];
- CHARSET = ['A'..'Z'];
- INI = 'crobots.ini';
- NOHTML = 'nohtml';
- AVERAGE = 100000;
-
- type
- QUARK = array[1..4] of byte;
- var
- choice : byte;
- title : string[80];
- rpath,
- path : pathstr;
- SGNips : longint;
- batch : boolean;
- inifile : text;
-
- procedure crob;
-
- const
- max = 100;
- log_path = 'crobots';
-
- var
- p :array[1..MAX] of pathstr;
- outpath,
- crob_path : pathstr;
- outrand: array[1..10626] of QUARK;
- g,
- cy :string[6];
- save,
- torneo,
- video :boolean;
- np,
- nm,
- k,
- i,
- j,
- x :integer;
- i1,i2,
- i3,i4 :byte;
- cc :char;
- t :text;
- file_r :searchrec;
- tot,match,
- index,
- cycles :longint;
-
- procedure enter;
- var
- tmp:pathstr;
- pth:boolean;
- i,j:integer;
- begin
- write('Elenco robots ad inserimento <M>anuale o <A>utomatico ? ');
- cc:=upcase(readkey);
- if cc='M' then
- begin
- writeln(cc);
- writeln;
- writeln('Elenco robots ( non includere l''estensione <',EXTR,'> )');
- writeln;
- for i:=1 to np do
- begin
- write('Crobot n^ ',i,' ',f,' ');
- readln(p[i]);
- p[i]:=p[i] + EXTR;
- end;
- end else
- begin
- writeln('Auto');
- write('Path per la ricerca dei file con estensione ',EXTR,' ',f,' ');
- readln(tmp);
- write('Vuoi includere il path nei nomi dei robots (s/N) ? ',f,' ');
- cc:=upcase(readkey);
- if cc = 'S' then
- pth:=true
- else begin
- cc:='N';
- pth:=false;
- end;
- writeln(cc);
- rpath:=concat(tmp,'*'+EXTR);
- k:=0; writeln;
- findfirst(rpath,archive,file_r);
- while (doserror = 0) and (k <= np) do
- begin
- inc(k);
- p[k]:=file_r.name;
- for j:=1 to length(p[k]) do
- if p[k][j] in CHARSET then p[k][j]:=UP2LOW[p[k][j]];
- if pth then p[k]:=concat(tmp,p[k]);
- writeln(p[k]);
- findnext(file_r);
- end;
- if k=0 then
- begin
- writeln('Nessun robot trovato!');
- halt(1);
- end else if k < np then
- begin
- writeln('Numero dei robots trovati : ',k);
- write('Vuoi continuare (s/N) ? ');
- cc:=upcase(readkey);
- if cc='S' then
- begin
- writeln(cc);
- np:=k;
- end else
- begin
- writeln('N');
- halt(1);
- end;
- end;
- end;
- writeln;
- end;
-
- procedure time_match;
- const lnc = - 4.30103;
- disksp1 = 0.35;
- disksp2 = 0.082;
- var
- ecc : byte;
- tsec,avec: longint;
-
- function log(x:longint):real;
- begin
- log:=ln(x)/ln(10);
- end;
-
- begin
- if SGNips < 1000 then ecc:=5
- else if SGNips < 3000 then ecc:=4
- else if SGNips < 10000 then ecc:=3
- else if SGNips < 20000 then ecc:=2
- else ecc:=1;
- if nm = 3 then
- SGNips:=SGNips + (SGNips div 4)
- else if nm = 2 then
- SGNips:=SGNips + (SGNips div 3);
- if cycles = 200000 then avec:=AVERAGE
- else avec:=round( 1000*(log(cycles) + lnc) ) * 100;
- tsec:=((tot*match*avec) div SGNips) + (ecc*tot);
- write('Tempo stimato : ');
- if tsec < 0 then begin
- writeln('Non computabile.');
- exit;
- end;
- if (tsec > 3600) then begin
- write(tsec div 3600,'h');
- tsec:=tsec mod 3600;
- if (tsec > 60) then write(' ',tsec div 60,'min');
- end else if (tsec > 60) then write(tsec div 60,'min')
- else write(tsec,'sec');
- writeln('.');
- writeln('Spazio su disco necessario per il file batch : ',tot*disksp2:0:0,'kB circa');
- writeln('Spazio su disco necessario per il file di log : ',tot*match*disksp1:0:0,'kB circa')
- end;
-
- begin
- writeln;
- if SGNips = 0 then begin
- write('Quanti SGNips calcola il tuo PC ? ');
- readln(SGNips);
- if SGNips < 0 then begin
- writeln('Ops!');
- exit;
- end;
- writeln;
- end;
- repeat
- write('Numero Crobots (min. 2 - max. ',MAX,') ',f,' ');
- readln(np)
- until (np > 1) and (np < max + 1);
- writeln;
- writeln('Vuoi generare un file batch con le specifiche di Torneo ?');
- writeln('a) 4 crobots in simultanea; massimo 24 crobots totali.');
- writeln('b) 200000 cicli per incontro.');
- writeln('c) Almeno 1000 incontri tra ciascuna coppia di crobots.');
- writeln('d) Sequenza di incontri (semi)casuale.');
- write('(S/n) ',f,' ');
- cc:=upcase(readkey);
- if cc = 'N' then begin
- writeln('N'); torneo:=FALSE;
- repeat
- writeln;
- write('Numero crobots in simultanea: 2, 3 o 4 ? ',f,' ');
- readln(nm)
- until (nm > 1) and (nm < 5);
- write('Numero di ripetizioni per incontro (default=100) ',f,' ');
- readln(g);
- val(g,match,i);
- if (g='') or (i <> 0) then begin
- g:='100';
- match:=100;
- end else if (i=0) and (match < 1) then begin
- g:='100';
- match:=100;
- end else writeln;
- if np < 25 then torneo:=TRUE;
- write('Numero cicli per incontro (default=200000) ',f,' ');
- readln(cy);
- val(cy,cycles,i);
- if (cy='') or (i <> 0) then begin
- cy:='200000';
- cycles:=200000;
- end else if (i=0) and (cycles < 1) then begin
- cy:='200000';
- cycles:=200000;
- end else writeln;
- end else begin
- writeln('S');
- torneo:=TRUE;
- nm:=4;
- if (np < nm) then begin
- writeln('Robots insufficienti !');
- halt;
- end else if (np > 24) then begin
- writeln('Numero troppo elevato di robots !');
- halt;
- end;
- cy:='200000'; cycles:=200000;
- match:=2000 div ((np - 2) * (np - 3));
- if (2000 mod ((np - 2) * (np - 3))) > 0 then inc(match);
- str(match,g);
- end;
- tot:=0;
- case nm of { Il metodo diretto di calcolo non funziona, bug del BP ? }
- 2 : for j:=1 to np-1 do
- for k:=j+1 to np do
- inc(tot);
- 3 : for j:=1 to np-2 do
- for k:=j+1 to np-1 do
- for x:=k+1 to np do
- inc(tot);
- 4 : for j:=1 to np-3 do
- for k:=j+1 to np-2 do
- for x:=k+1 to np-1 do
- for i:=x+1 to np do begin
- inc(tot);
- if torneo then begin
- outrand[tot][1]:=j;
- outrand[tot][2]:=k;
- outrand[tot][3]:=x;
- outrand[tot][4]:=i;
- end;
- end;
- end;
- write('Ridirezione su ',log_path + EXTL,' (s/N) ? ');
- cc:=upcase(readkey);
- if cc='S' then begin
- outpath:=log_path;
- writeln(cc);
- end
- else begin
- writeln('N');
- write('Nuovo path e file di ridirezione (senza estensione ',EXTL,') ',f,' ');
- readln(outpath);
- end;
- writeln;
- enter;
- writeln('Verranno generate ',tot,' combinazioni per un totale di ',tot*match,' incontri.');
- time_match;
- video:=false; save:=false;
- writeln;
- write('Vuoi salvare i dati su file "start" (s/N) ? ');
- cc:=upcase(readkey);
- if cc='S' then
- begin
- writeln(cc);
- crob_path:='start';
- save:=true;
- end
- else begin
- writeln('N');
- write('Vuoi specificare un nuovo path (s/N) ? ');
- cc:=upcase(readkey);
- if cc='S' then
- begin
- writeln(cc);
- write('Nuovo path per il file batch "start" ',f,' ');
- readln(crob_path);
- crob_path:=concat(crob_path,'start');
- save:=true;
- end
- else writeln('N');
- end;
- if save then
- begin
- {$I-}
- assign(t,crob_path);
- rewrite(t);
- {$I+}
- if IOresult <> 0 then begin
- writeln('Errore nella creazione del file ...');
- halt(1);
- end;
- end else
- begin
- write('Vuoi vedere l''elenco su video (s/N) ? ');
- cc:=upcase(readkey);
- if cc='S' then
- begin
- writeln(cc);
- {$I-}
- assigncrt(t);
- rewrite(t);
- {$I+}
- video:=true;
- if IOresult <> 0 then begin
- writeln('Errore nella creazione del file ...');
- halt(1);
- end;
- end else begin
- writeln('N');
- exit;
- end;
- end;
- writeln;
- write('Attendi ... ');
- if video then clrscr;
- if torneo then randomize;
- case nm of
- 2 : for j:=1 to np-1 do
- for k:=j+1 to np do
- writeln(t,concat('crobots -m',g,' -l',cy,' ',
- p[j],' ',p[k],' <cr >>',outpath,EXTL));
- 3 : for j:=1 to np-2 do
- for k:=j+1 to np-1 do
- for x:=k+1 to np do
- writeln(t,concat('crobots -m',g,' -l',cy,' ',
- p[j],' ',p[k],' ',p[x],' <cr >>',outpath,EXTL));
- 4 : for j:=1 to np-3 do
- for k:=j+1 to np-2 do
- for x:=k+1 to np-1 do
- for i:=x+1 to np do begin
- if torneo then begin
- index:=random(tot) + 1;
- i1:=outrand[index][1];
- i2:=outrand[index][2];
- i3:=outrand[index][3];
- i4:=outrand[index][4];
- for cycles:=index to pred(tot) do outrand[cycles]:=outrand[succ(cycles)];
- dec(tot);
- end else begin
- i1:=j; i2:=k; i3:=x; i4:=i;
- end;
- writeln(t,concat('crobots -m',g,' -l',cy,' ',
- p[i1],' ',p[i2],' ',p[i3],' ',p[i4],' <cr >>',outpath,EXTL));
- end;
- end;
- close(t);
- writeln('OK!');
- end;
-
- procedure parser;
-
- const
- WINS = 'wins=';
- M = 6;
- MAX = 100;
- MATCH = 'Match';
-
- type
- robstr = string[10];
- robot = record
- name : robstr;
- win,
- tie,
- play,
- lose,
- point : word;
- eff : real;
- end;
- robots = array[1..MAX] of robot;
-
- var
- rob : robots;
- strn,
- description : string[80];
- index,
- max_rob : word;
- mem_wins,
- mem_ties : array[1..MAX] of word;
- work,
- resultfile : text;
- ch : char;
- resultfilename : pathstr;
-
-
- (* Bubble Sort per creare la classifica aggiornata *)
-
- procedure bsort(var vects : robots;n : word);
- var
- i,
- j : word;
- flag : boolean;
- swapper : robot;
- begin
- i:=1;
- repeat
- inc(i);
- flag:=true;
- for j:=n downto i do
- if (vects[j].point > vects[pred(j)].point) then
- begin
- swapper:=vects[j];
- vects[j]:=vects[pred(j)];
- vects[pred(j)]:=swapper;
- flag:=false;
- end
- until flag or (n = i);
- end;
-
-
- (* Parsing della singola riga *)
-
- procedure pars;
- var
- code : integer;
- total : word;
- x : string[M];
- position,
- cnt,
- found : byte;
-
- begin
- index:=0;
- found:=0;
- while (index < max_rob) and (found < 2) do
- begin
- inc(index);
- position:=pos(rob[index].name,strn);
- if position > 0 then
- if strn[pred(position)] in PATHCHAR then
- begin
- cnt:=position;
- position:=pos(WINS,strn);
- if position > 0 then
- begin
- inc(found);
- inc(rob[index].play);
- while strn[cnt] <> '=' do inc(cnt);
- inc(cnt);
- while strn[cnt] in NUM_CHAR do inc(cnt);
- dec(cnt);
- total:=0;
- x:=' ';
- position:=0;
- while strn[cnt] in NUM_CHAR do
- begin
- x[M - position]:=strn[cnt];
- dec(cnt);
- inc(position);
- end;
- val(x,total,code);
- if code = 0 then mem_wins[index]:=total;
- inc(cnt);
- while strn[cnt] <> '=' do inc(cnt);
- inc(cnt);
- while strn[cnt] in NUM_CHAR do inc(cnt);
- dec(cnt);
- total:=0;
- x:=' ';
- position:=0;
- while strn[cnt] in NUM_CHAR do
- begin
- x[M - position]:=strn[cnt];
- dec(cnt);
- inc(position);
- end;
- val(x,total,code);
- if code = 0 then mem_ties[index]:=total;
- end;
- end;
- end;
- end;
-
-
- (* Inserimento manuale dei robots *)
-
- procedure man_rob;
- var
- loc_rob : string[8];
- { l : byte; }
- count : word;
-
- begin
- count:=0;
- while (count < 1) or (count > MAX) do
- begin
- writeln;
- write('Inserisci il numero di ROBOTS ',F);
- readln(count);
- end;
- writeln;
- writeln('Inserisci i robots SENZA l''estensione ',EXTR,' e SENZA PATH');
- writeln;
- index:=0;
- while (index < count) do
- begin
- inc(index);
- write('Robot n^ ',index,' ',F);
- readln(loc_rob);
- if loc_rob <> '' then
- begin
- rob[index].name:=loc_rob + EXTR;
- with rob[index] do
- begin
- play:=0;
- win:=0;
- tie:=0;
- lose:=0;
- point:=0;
- eff:=0.0;
- end;
- end else dec(index);
- end;
- writeln;
- max_rob:=index;
- writeln('Robots totali ',F,max_rob);
- end;
-
-
- (* Inserimento automatico dei robots *)
-
- procedure auto_rob;
- var dirinfo : searchrec;
- old_path : pathstr;
- n : word;
- search : robstr;
- found,
- not_exit : boolean;
- i : byte;
-
- begin
- if batch then begin (* Lettura dei nomi robots *)
- index:=0;
- while (not(eof(inifile)) and (index < MAX)) do begin
- inc(index);
- readln(inifile,rob[index].name);
- for i:=1 to length(rob[index].name) do
- if rob[index].name[i] in CHARSET then
- rob[index].name[i]:=UP2LOW[rob[index].name[i]];
- rob[index].name:=rob[index].name+EXTR;
- end;
- max_rob:=index;
- for i:=1 to max_rob do
- with rob[i] do
- begin
- play:=0;
- win:=0;
- tie:=0;
- lose:=0;
- point:=0;
- eff:=0.0;
- end;
- end else begin
- (* Interactive On *)
- not_exit:=true;
- while (max_rob = 0) or not_exit do
- begin
- writeln;
- index:=0;
- write('Inserisci il path completo dei Crobots ',F);
- old_path:=rpath;
- readln(rpath);
- if (max_rob > 0) and (old_path = rpath) then
- begin
- writeln('Non posso cercare nella stessa subdirectory !');
- writeln('I crobots devono essere tutti diversi !');
- end else
- begin
- findfirst(rpath+'*'+EXTR,anyfile,dirinfo);
- while doserror = 0 do
- begin
- inc(index);
- if (index+max_rob) > MAX then
- begin
- write('Impossibile caricare altri crobots,');
- writeln(' risorse esaurite !');
- write('Continuo ? [s/N] : ',F);
- ch:=upcase(readkey);
- if (ch = 'S') then
- begin
- writeln(ch);
- exit;
- end else
- begin
- writeln('N');
- halt(1);
- end;
- end;
- found:=false;
- rob[index+max_rob].name:=dirinfo.name;
- for i:=1 to length(rob[index+max_rob].name) do
- if rob[index+max_rob].name[i] in CHARSET then
- rob[index+max_rob].name[i]:=UP2LOW[rob[index+max_rob].name[i]];
- search:=rob[index+max_rob].name;
- write('CRobot n^ ',index,' ',F,rob[index+max_rob].name,' ...');
- n:=1;
- while (n < (max_rob + index)) and not(found) do
- begin
- if (search = rob[n].name) then
- begin
- found:=true;
- dec(index);
- end;
- inc(n);
- end;
- if not(found) then
- begin
- with rob[index+max_rob] do
- begin
- play:=0;
- win:=0;
- tie:=0;
- lose:=0;
- point:=0;
- eff:=0.0;
- end;
- writeln(' OK!');
- end else writeln(' gia'' trovato, NON valido !');
- findnext(dirinfo);
- end;
- end;
- max_rob:=max_rob+index;
- writeln('CRobots trovati ',F,index);
- writeln('CRobots totali ',F,max_rob);
- if index = 0 then
- begin
- writeln('Nessun Crobot trovato !!');
- if max_rob = 0 then
- begin
- writeln;
- write('Vuoi uscire ? [s/N] ',F);
- ch:=upcase(readkey);
- if ch = 'S' then
- begin
- writeln(ch); halt(1);
- end else writeln('N');
- end;
- end;
- if max_rob > 0 then
- begin
- write('Altri Crobots ? [S/n] ',F);
- ch:=upcase(readkey);
- if (ch = 'N') then
- begin
- writeln(ch);
- not_exit:=false;
- end else writeln('S');
- end;
- end;
- (* Interactive Off *)
- end;
- end;
-
-
- (* Apertura del file di LOG *)
-
- procedure init_log;
-
- begin
- if batch then begin
- readln(inifile,title); (* Lettura del titolo della pagin web *)
- readln(inifile,path); (* Lettura del nome file di log *)
- {$I-}
- assign(work,path + EXTL);
- reset(work);
- {$I+}
- if IOresult <> 0 then begin
- halt(1);
- end;
- end else begin
- (* Interactive On *)
- writeln;
- writeln('Inserisci il path completo e il nome del file LOG :');
- write('Non includere l''estensione <',EXTL,'> ',F,' ');
- readln(path);
- {$I-}
- assign(work,path + EXTL);
- reset(work);
- {$I+}
- if IOresult <> 0 then
- begin
- writeln('Errore nell''apertura del file ',path + EXTL);
- halt(1);
- end;
- end;
- (* Interactive Off *)
- end;
-
- (* Parsing del file di LOG *)
-
- procedure parsing;
- var
- code : integer;
- index,
- tmp : word;
- cnt,
- position : byte;
- n_m : string[M];
-
- begin
- write('Parsing file ',F,path+EXTL,'...');
- for index:=1 to max_rob do begin
- mem_wins[index]:=0;
- mem_ties[index]:=0;
- end;
- while not(eof(work)) do
- begin
- readln(work,strn);
- cnt:=pos(MATCH,strn);
- if cnt > 0 then
- begin
- while strn[cnt] <> ':' do inc(cnt);
- dec(cnt);
- n_m:=' ';
- position:=0;
- while strn[cnt] in NUM_CHAR do
- begin
- n_m[M - position]:=strn[cnt];
- dec(cnt);
- inc(position);
- end;
- val(n_m,tmp,code);
- if tmp = 1 then
- for index:=1 to max_rob do
- begin
- rob[index].win:=mem_wins[index] + rob[index].win;
- rob[index].tie:=mem_ties[index] + rob[index].tie;
- mem_wins[index]:=0;
- mem_ties[index]:=0;
- end;
- end;
- pars;
- end;
- for index:=1 to max_rob do
- begin
- rob[index].win:=mem_wins[index] + rob[index].win;
- rob[index].tie:=mem_ties[index] + rob[index].tie;
- end;
- close(work);
- writeln('OK!');
- end;
-
- procedure result;
- var
- step : byte;
- winchar,
- losechar,tiechar,
- playchar,effchar,
- pointchar : string;
- index : word;
-
- begin
- for index:=1 to max_rob do
- begin
- rob[index].point:=rob[index].win*3 + rob[index].tie;
- rob[index].lose:=rob[index].play - rob[index].win - rob[index].tie;
- if rob[index].play > 0 then
- rob[index].eff:=(rob[index].point / (rob[index].play * 3)) * 100;
- end;
- bsort(rob,max_rob);
- if not(batch) then begin
- writeln;
- write('Premi un tasto qualsiasi ...');
- ch:=readkey;
- end;
- clrscr;
- writeln;
- writeln('Classifica finale ...');
- writeln;
- writeln('Pos) Nome Totali Vinte Nulle Perse PUNTI Eff.%');
- if max_rob > 20 then
- for step:=0 to pred(max_rob div 20) do begin
- if not(batch) then writeln;
- for index:=1 to 20 do
- begin
- writeln(index + (step*20):3,') ',rob[index + (20*step)].name:10,
- ' ',rob[index + (20*step)].play:7,
- ' ',rob[index + (20*step)].win:6,
- ' ',rob[index + (20*step)].tie:6,
- ' ',rob[index + (20*step)].lose:6,
- ' ',rob[index+ (20*step)].point:8,
- ' ',rob[index + (20*step)].eff:4:1);
- end;
- if not(batch) then begin
- writeln;
- write('Premi un tasto qualsiasi ...');
- ch:=readkey;
- writeln;
- end;
- clrscr;
- end;
- step:=(max_rob div 20)*20;
- if not(batch) then writeln;
- for index:=1 to (max_rob mod 20) do
- begin
- writeln(index + step:3,') ',rob[index + step].name:10,
- ' ',rob[index + step].play:7,' ',rob[index + step].win:6,
- ' ',rob[index + step].tie:6,' ',rob[index + step].lose:6,
- ' ',rob[index + step].point:8,' ',rob[index + step].eff:4:1);
- end;
- writeln;
- if not(batch) then begin
- (* Interactive On *)
- write('Vuoi salvare i risultati sul file ',path,'.txt ? [S/n] ');
- ch:=upcase(readkey);
- if ch = 'N' then
- writeln(ch)
- else
- begin
- writeln('S');
- {$I-}
- assign(resultfile,path + '.txt');
- rewrite(resultfile);
- {$I+}
- if IOResult <> 0 then
- begin
- writeln;
- writeln('Errore nella ceazione del file ',path +'.txt');
- writeln('Il programma verra'' terminato');
- halt(1);
- end;
- writeln(resultfile,'Classifica finale ...');
- writeln(resultfile);
- writeln(resultfile,'Pos) Nome Totali Vinte Nulle Perse PUNTI Eff.%');
- for index:=1 to max_rob do
- begin
- writeln(resultfile,index:3,') ',rob[index].name:10,
- ' ',rob[index].play:7,' ',rob[index].win:6,
- ' ',rob[index].tie:6,' ',rob[index].lose:6,
- ' ',rob[index].point:8,' ',rob[index].eff:4:1);
- end;
- close(resultfile);
- if not(batch) then begin
- writeln('Fatto ...');
- writeln;
- end;
- end;
- write('Vuoi salvare i risultati su file EXCEL CSV ? [S/n] ');
- ch:=upcase(readkey);
- if ch = 'N' then
- writeln(ch)
- else
- begin
- writeln('S');
- write('Inserisci il nome e il path del file senza estensione (',EXTC,') ',F,' ');
- readln(resultfilename);
- {$I-}
- assign(resultfile,resultfilename + EXTC);
- rewrite(resultfile);
- {$I+}
- if IOResult <> 0 then
- begin
- writeln;
- writeln('Errore nella ceazione del file ',resultfilename);
- writeln('Il programma verra'' terminato');
- halt(1);
- end;
- writeln;
- writeln(resultfile,'Nome CRobot;Giocate;Vinte;Nulle;Perse;Punti;Efficienza');
- for index:=1 to max_rob do
- begin
- str(rob[index].play,playchar);
- str(rob[index].win,winchar);
- str(rob[index].tie,tiechar);
- str(rob[index].point,pointchar);
- str(rob[index].eff:0:1,effchar);
- effchar[pos('.',effchar)]:=',';
- effchar:=concat(effchar,'%');
- str(rob[index].lose,losechar);
- writeln(resultfile,rob[index].name + ';'
- + playchar + ';' + winchar + ';'
- + tiechar + ';' + losechar + ';'
- + pointchar + ';' + effchar);
- end;
- close(resultfile);
- writeln('Fatto ...');
- end;
- writeln;
- write('Vuoi salvare i risultati su file HTML ? [S/n] ');
- ch:=upcase(readkey);
- end else ch:='S';
- (* Interactive Off *)
- if ch = 'N' then
- writeln(ch)
- else
- begin
- if not(batch) then begin
- writeln('S');
- write('Inserisci il nome e il path del file senza estensione (',EXTH,') ',F,' ');
- readln(resultfilename);
- end else resultfilename:=path;
- if (not(batch) or (batch and (title <> NOHTML))) then begin
- (* HTML file in batch mode *)
- {$I-}
- assign(resultfile,resultfilename + EXTH);
- rewrite(resultfile);
- {$I+}
- if IOResult <> 0 then
- begin
- writeln;
- writeln('Errore nella ceazione del file ',resultfilename);
- writeln('Il programma verra'' terminato');
- halt(1);
- end;
- (* HTML file in batch mode *)
- end;
- if not(batch) then begin
- (* Interactive On *)
- write('Inserisci il titolo della pagina HTML ',F);
- readln(title);
- write('Inserisci la descrizione della pagina HTML ',F);
- readln(description);
- writeln;
- (* Interactive Off *)
- end else description:='Torneo di Crobots';
- if (not(batch) or (batch and (title <> NOHTML))) then begin
- (* HTML file in batch mode *)
- writeln(resultfile,'<html>');
- writeln(resultfile,'<!-- CRUtils (C) 1999 Maurizio Camangi -->');
- writeln(resultfile,'<!-- Written by Maurizio "Joshua" Camangi, "joshua@ascu.unian.it" -->');
- writeln(resultfile,'<!-- This is free software: read COPYING file for details. -->');
- writeln(resultfile,'<head>');
- writeln(resultfile,'<meta name="GENERATOR" content="CRUTILS ',RELEASE,'">');
- writeln(resultfile,'<meta name="KEYWORDS" content="Crobots Crutils">');
- writeln(resultfile,'<meta name="DESCRIPTION" content="',description,'">');
- writeln(resultfile,'<title>',title,'</title>');
- writeln(resultfile,'</head>');
- writeln(resultfile,'<body text="#000000" bgcolor="#FFFFFF"><center>');
- writeln(resultfile,'<table border>');
- writeln(resultfile,'<caption align=top>',title,'</caption>');
- writeln(resultfile,'<tr nowrap>');
- writeln(resultfile,'<th>Pos.</th><th>Nome CRobot</th><th>Giocate</th>',
- '<th>Vinte</th><th>Nulle</th><th>Perse</th>',
- '<th>Punti</th><th>Efficienza</th>');
- for index:=1 to max_rob do
- begin
- str(rob[index].play,playchar);
- str(rob[index].win,winchar);
- str(rob[index].tie,tiechar);
- str(rob[index].point,pointchar);
- str(rob[index].eff:0:1,effchar);
- effchar[pos('.',effchar)]:=',';
- effchar:=concat(effchar,'%');
- str(rob[index].lose,losechar);
- writeln(resultfile,'<tr><td>',rob[index].name
- + '</td><td>' + playchar + '</td><td>' + winchar + '</td><td>'
- + tiechar + '</td><td>' + losechar + '</td><td>'
- + pointchar + '</td><td>' + effchar + '</td></tr>');
- end;
- writeln(resultfile,'</table></center></body></html>');
- close(resultfile);
- (* HTML file in batch mode *)
- end;
- if not(batch) then writeln('Fatto ...');
- end;
- end;
-
- begin
- max_rob:=0; rpath:='none';
- if batch then begin
- init_log;
- auto_rob;
- parsing;
- result;
- end else begin
- (* Inrteractive On *)
- writeln;
- write('Inserimento robots <M>anuale o <A>utomatico ? ',F);
- ch:=upcase(readkey);
- if ch='M' then begin
- writeln('Manuale');
- man_rob;
- end
- else begin
- writeln('Automatico');
- auto_rob;
- end;
- init_log;
- parsing;
- result;
- writeln;
- writeln('OK!');
- end;
- (* Interactive Off *)
- end;
-
- procedure cycles;
-
- const
- cy = 'cycles =';
-
- var
- lpath : pathstr;
- work : text;
- ch : char;
- nfiles : byte;
- globmatch,
- globcycles,
- totmatch,
- totcycles : longint;
-
- procedure open_file;
- begin
- write('Inserisci il path e il file di LOG senza estensione ',f);
- readln(lpath);
- lpath:=lpath + EXTL;
- {$I-}
- assign(work,lpath);
- reset(work);
- {$I+}
- if IOresult <> 0 then
- begin
- writeln('Errore nell''apertura del file ',lpath);
- writeln('Programma terminato ...');
- halt(1);
- end;
- inc(nfiles);
- end;
-
- procedure r_cycles;
- var
- instr : string[80];
- strcy : string[6];
- code : integer;
- temp : longint;
- pos1,
- pos2 : byte;
- begin
- totcycles:=0;
- totmatch:=0;
- while not(eof(work)) do
- begin
- readln(work,instr);
- pos1:=pos(cy,instr);
- if pos1 > 0 then
- begin
- inc(totmatch);
- while instr[pos1] <> ':' do inc(pos1);
- pos2:=pred(pos1);
- strcy:=' ';
- pos1:=0;
- while instr[pos2] in num_char do
- begin
- strcy[6 - pos1]:=instr[pos2];
- inc(pos1);
- dec(pos2);
- end;
- val(strcy,temp,code);
- if code = 0 then totcycles:=totcycles + temp;
- end;
- end;
- end;
-
- procedure close_file;
- begin
- write('Partite giocate ',f); writeln(totmatch);
- write('Media cicli per partita ',f); writeln(totcycles div totmatch);
- writeln;
- if nfiles = 1 then
- begin
- globmatch:=totmatch;
- globcycles:=totcycles;
- end else
- begin
- globmatch:=globmatch + totmatch;
- globcycles:=globcycles + totcycles;
- write('Partite globali giocate ',f); writeln(globmatch);
- write('Media globale cicli per partita ',f); writeln(globcycles div globmatch);
- end;
- close(work);
- end;
-
- begin
- globmatch:=0;
- globcycles:=0;
- nfiles:=0;
- repeat
- writeln;
- open_file;
- write('Lettura ',lpath,' ...');
- r_cycles;
- writeln('OK');
- writeln;
- close_file;
- writeln;
- write('Altro file [S]i/[n]o ? ',f); ch:=upcase(readkey);
- if ch = 'N' then writeln(ch)
- else writeln('S');
- until ch = 'N';
- writeln;
- writeln('OK!');
- end;
-
- BEGIN
- clrscr;
- writeln;
- writeln('CRUtils - Crobots (TM) Utilities Collection ',RELEASE);
- writeln(ABOUT1);
- writeln(ABOUT2);
- writeln(ABOUT3);
- writeln(ABOUT4);
- title:=NOHTML;
- {$I-}
- assign(inifile,INI); (* Apertura di 'crobots.ini' *)
- reset(inifile);
- {$I+}
- if IOresult <> 0 then batch:=FALSE
- else batch:=TRUE;
- if batch then begin
- writeln;
- writeln('Batch mode on...');
- writeln;
- parser
- end else begin
- (* Interactive On *)
- SGNips:=0;
- repeat
- writeln;
- writeln('Quale utility vuoi utilizzare ?');
- writeln;
- writeln('1) Crobots batch file Creator.');
- writeln('2) Crobots LOG file Parser.');
- writeln('3) Cycles Counter.');
- writeln('0) Esci subito.');
- writeln;
- write('Inserisci la tua scelta ',F);
- {$I-}
- readln(choice);
- case choice of
- 1: crob;
- 2: parser;
- 3: cycles;
- 0: begin
- writeln;
- writeln('Bye bye ...');
- halt(0);
- end
- end
- {$I+}
- until true=false;
- end;
- (* Interactive Off *)
- if batch then close(inifile)
- else writeln;
- writeln('Bye bye ...');
- halt(0);
-
- END.
-