REM purpose: benchmark redmaker warriors and produce population stats REM this code requires QBASIC.EXE to run, command line: qbasic /run rmbench REM coded to use benchmark *.red files in c:\warbench\80, 800 and 8000 REM warrior *.red files to benchmark in warcode (for redmaker) REM edit below to set paths and filenames. note.. depends on the REM author of all warriors being tested to be "Anonymous", and has REM other redmaker-specific actions like accessing the iteration file. REM modifying for other evolvers should be trivial: change the test path, REM the author match string and modify the shelled commands that copy REM redmaker.dat into the report.. maybe change to another useful file. REM outputs bench.out containing raw pmars scores, bench.txt REM containing adjusted and sorted scores for unique members, REM and stats.txt containing soup stats, sorted scores for REM target and benchmark warriors, and the redmaker.dat to REM keep track of what iteration the report represents. REM programmed by Terry Newton, last mod September 2 2000 DIM hash(500) DIM population(500) DIM warname$(500) DIM membernames$(500) DIM scores$(500) 'where the benchmark *.red code is... benchdirT$ = "c:\warbench\80" benchdirB$ = "c:\warbench\800" benchdirN$ = "c:\warbench\8000" 'pmars command lines... pmarsT$ = "pmars -b -l 4 -d 4 -s 80 -p 80 -c 800 -r 1000" pmarsB$ = "pmars -b -l 20 -d 20 -s 800 -p 800 -c 8000 -r 100 -f" pmarsN$ = "pmars -b -l 100 -d 100 -s 8000 -p 8000 -c 80000 -r 50" 'directory to test... wardir$ = "warcode" 'filenames... logfile$ = "bench.out" 'redirected pmars output, the raw data outputfile$ = "bench.txt" 'score file produced by scorelog code statsfile$ = "stats.txt" 'report with separated scores and stats 'this must match pmars output when simulating the warriors being tested... authormatch$ = "by Anonymous" menu: CLS PRINT PRINT PRINT " Select...." PRINT PRINT " [1] Benchmark 8000" PRINT " [2] Benchmark 800" PRINT " [3] Benchmark 80" PRINT PRINT " [Q] Quit" PRINT PRINT " Note - Edit this prog to change pmars com line" PRINT " and bench directory for each type of test" PRINT menu1: a$ = "": WHILE a$ = "": a$ = UCASE$(INKEY$): WEND IF a$ = "1" GOTO select1 IF a$ = "2" GOTO select2 IF a$ = "3" GOTO select3 IF a$ = "Q" GOTO quit GOTO menu1 select1: benchdir$ = benchdirN$: pmars$ = pmarsN$: GOTO runbench select2: benchdir$ = benchdirB$: pmars$ = pmarsB$: GOTO runbench select3: benchdir$ = benchdirT$: pmars$ = pmarsT$: GOTO runbench quit: CLS : SYSTEM runbench: PRINT "Running benchmark of "; wardir$; " directory" PRINT "Raw scores output to "; logfile$ PRINT "Sorted scores will output to "; outputfile$ PRINT "Population statistics will output to "; statsfile$ PRINT PRINT "Do not press a key! If you do, backspace over key" PRINT "then press c and return to continue processing" PRINT hashp = 0 'create a list of redcode to test SHELL "DIR /-p /b /s " + wardir$ + "\*.red > warlist$.tmp" 'delete log if it exists SHELL "if exist " + logfile$ + " del " + logfile$ ' create battle batch... OPEN "bench$!-.bat" FOR OUTPUT AS #1 PRINT #1, "@echo off" PRINT #1, "if .%1==.loop goto %1" PRINT #1, "for %%a in ("; benchdir$; "\*.red) do call %0 loop %1 %%a" PRINT #1, "goto end" PRINT #1, ":loop" PRINT #1, pmars$; " %2 %3 > score$!-.tmp" PRINT #1, "type score$!-.tmp" PRINT #1, "type score$!-.tmp >> "; logfile$ PRINT #1, ":end" CLOSE #1 'run through list OPEN "warlist$.tmp" FOR INPUT AS #1 totalpop = 0 WHILE EOF(1) = 0 LINE INPUT #1, war$ totalpop = totalpop + 1 OPEN war$ FOR INPUT AS #2 'create a hash value for the warrior hashvalue = 0: startval = 0 WHILE EOF(2) = 0 LINE INPUT #2, a$: a$ = LTRIM$(RTRIM$(a$)) IF LEFT$(a$, 1) <> ";" THEN linehash = startval FOR i = 1 TO LEN(a$) linehash = linehash + i * ASC(MID$(a$, i, 1)) NEXT i hashvalue = hashvalue + linehash startval = startval + 100 ELSE 'get name IF LEFT$(LCASE$(a$), 6) = ";name " THEN warriorname$ = RIGHT$(a$, LEN(a$) - 6) END IF END IF WEND CLOSE #2 'determine if already done hit = 0 IF hashp > 0 THEN FOR i = 0 TO hashp - 1 IF hash(i) = hashvalue THEN population(i) = population(i) + 1 membernames$(i) = membernames$(i) + " " + warriorname$ PRINT "Skipping duplicate "; war$; " ("; warriorname$; ")" hit = 1: i = hashp END IF NEXT i END IF 'benchmark if not IF hit = 0 THEN 'determine name and author of warrior for stats OPEN war$ FOR INPUT AS #2 b$ = "": c$ = "" WHILE EOF(2) = 0 LINE INPUT #2, a$: a$ = LTRIM$(RTRIM$(a$)) IF LCASE$(LEFT$(a$, 6)) = ";name " THEN b$ = RIGHT$(a$, LEN(a$) - 6) WEND CLOSE #2 warname$(hashp) = b$: membernames$(hashp) = b$ IF b$ = "" THEN warname$(hashp) = "Unknown" population(hashp) = 1 hash(hashp) = hashvalue: hashp = hashp + 1 SHELL "bench$!-.bat " + war$ END IF WEND CLOSE #1 KILL "bench$!-.bat" KILL "score$!-.tmp" KILL "warlist$.tmp" IF hashp = 0 THEN PRINT "Nothing to do." SYSTEM END IF 'this was a shell to scorelog.bat which writes and runs another 'qbasic program, better to incorporate the code here... PRINT "Scoring log file, please wait..." '------- start scorelog extract, only minor changes (filenames, no exit) : ON ERROR GOTO donefile DIM war$(500), score(500), plays(500): maxwar = 0 'this can only run once! OPEN logfile$ FOR INPUT AS #1 L: LINE INPUT #1, a$: IF INSTR(a$, "Results:") = 0 GOTO L CLOSE #1: x = INSTR(a$, " "): y = INSTR(x + 1, a$, " ") z = INSTR(y + 1, a$, " "): q = VAL(MID$(a$, x, y - x)) r = VAL(MID$(a$, y, z - y)): s = VAL(RIGHT$(a$, LEN(a$) - z)) rounds = q + r + s: IF rounds = 0 GOTO done FOR i = 1 TO 500: war$(i) = "": score(i) = 0: plays(i) = 0: NEXT i OPEN logfile$ FOR INPUT AS #1 floop: LINE INPUT #1, a$: a$ = LTRIM$(RTRIM$(a$)) p = INSTR(a$, " scores "): IF p = 0 GOTO floop name$ = LEFT$(a$, p) IF maxwar = 0 THEN war$(0) = name$: j = 0: maxwar = 1 ELSE j = maxwar: FOR i = 0 TO maxwar - 1 IF name$ = war$(i) THEN j = i: i = maxwar - 1 NEXT i END IF IF j = maxwar THEN war$(maxwar) = name$: maxwar = maxwar + 1 u$ = RIGHT$(a$, 5): sp = INSTR(u$, " ") IF (sp = 0) = 0 THEN u$ = RIGHT$(u$, LEN(u$) - sp) plays(j) = plays(j) + 1: score(j) = score(j) + VAL(u$): GOTO floop donefile: CLOSE #1: RESUME writeresults writeresults: ON ERROR GOTO done OPEN outputfile$ FOR OUTPUT AS #1 IF maxwar = 0 THEN GOTO done FOR i = 0 TO maxwar - 1 ws = INT(((score(i) / plays(i)) / rounds) * 1000) / 10 + 1000.01 wscore$ = STR$(ws): MID$(wscore$, 2, 1) = " " MID$(wscore$, 8, 1) = " ": PRINT #1, wscore$, war$(i): NEXT i done: CLOSE #1: 'SYSTEM '------- end scorelog code 'write out statistics PRINT "Calculating stats..." OPEN statsfile$ FOR OUTPUT AS #1 PRINT #1, "Population Statistics..." PRINT #1, "Total members: "; totalpop PRINT #1, "Unique members: "; hashp sumofscores = 0: maxscore = 0 FOR i = 0 TO hashp - 1 'get score from output file OPEN outputfile$ FOR INPUT AS #2 score$ = "" WHILE EOF(2) = 0 LINE INPUT #2, a$ IF INSTR(a$, warname$(i)) > 0 THEN score$ = MID$(a$, 3, 5) END IF WEND CLOSE #2 scores$(i) = score$: scoreval = VAL(score$) sumofscores = sumofscores + (scoreval * population(i)) IF scoreval > maxscore THEN maxscore = scoreval NEXT i PRINT #1, "Average Score: "; INT((sumofscores / totalpop) * 10) / 10 PRINT #1, "Maximum Score: "; maxscore PRINT #1, "Pmars comline: "; pmars$ PRINT #1, "" PRINT #1, "Score Members Name" PRINT #1, "---------------------------------------" CLOSE #1 'print scores to temp file.. OPEN "score1$$.tmp" FOR OUTPUT AS #1 FOR i = 0 TO hashp - 1 PRINT #1, scores$(i), population(i), membernames$(i) NEXT i CLOSE #1 'use dos sort function to reverse-sort by score SHELL "sort /r < score1$$.tmp > score2$$.tmp" 'use dos to append sorted list to stats file SHELL "type score2$$.tmp >> " + statsfile$ KILL "score?$$.tmp" 'remove temps 'dos commands to finish the stats report SHELL "echo --------------------------------------->>" + statsfile$ SHELL "echo Benchmark warriors...>>" + statsfile$ q$ = CHR$(34): c$ = "find/v " + q$ + authormatch$ + q$ 'redmaker specific c$ = c$ + "<" + outputfile$ + ">>" + statsfile$: SHELL c$ SHELL "echo --------------------------------------->>" + statsfile$ SHELL "echo Iteration and survive score...>>" + statsfile$ SHELL "type warcode\redmaker.dat>>" + statsfile$ SHELL "echo --------------------------------------->>" + statsfile$ CLS SYSTEM