Core War Test Programs ====================== These programs require pmars.exe and qbasic.exe and should work under Windows or DosEmu/FreeDos. Set for coresize 8000 (standard), edit as needed. This is crude stuff designed for fairly advanced users who know about dos command lines, directories and stuff like that and don't mind a bit. These programs were written by Terry Newton and provided as-is without warrantee (but if there's a problem let me know). Do whatever you want with the code. Last updated 4/29/09. T8KW.BAT Benchmarks warriors in the current directory against a test set and produces a report containing sorted scores and a listing and benchmark chart for each warrior. Edit to specify the benchmark directory, battle rounds, pmars command line and report filename. HILL8000.BAT Runs a hill using the warriors in the current directory where every warrior battles every other warrior then the scores are tallied and sorted. Edit to specify number of rounds and pmars command line. Requires SCORELOG.BAT. SCORELOG.BAT Batch file used by HILL8000.BAT to tally the scores. Updated version that numbers ranking, 5-digit score resolution to help avoid ties. HILLREP.BAS QBasic program that reads the hill.out file generated by HILL8000.BAT or a varient and writes a hill.txt file containing performance charts for each warrior. After running the hill batch to write the hill.out file, run QBASIC /RUN [path\to\]HILLREP.BAS to generate charts. Edit to specify filename if raw pmars scores aren't in a file named hill.out. ::------- begin T8KW.BAT --------------------------------------------------- :: Benchmarks all warriors in current directory :: and produces a report file containing: :: time, date and pmars comline used :: sorted scores, filenames and warrior names :: for each warrior a listing and performance chart :: QBASIC and PMARS must be installed in a path dir :: Edit the block below to set the pmars command line, :: rounds, benchmark directory and report file name. :: last old mod Aug 24 2000 by WTN :: :: adapted to DosEmu/FreeDos, fixed up 2/17/09 WTN... :: added set testall=testall.bat then %0 replaced with %testall% :: calls testaset.bat to override settings in the batch file :: added code to sort the warriors in the report by filename :: replaced bench report code with code that handles more rounds :: @echo off if .%1==.Battle goto battlewarrior if .%1==.Test goto testwarrior :: set testall to this batch's filename... set testall=t8kw.bat :: ----------------------------- (defaults) :: set to benchmark directory... set test=d:\cwstuff\wilkies :: set to rounds... set rnds=250 :: pmars command line... (note: coresize=8000, fixed sequence) set pmars=pmars -b -l 100 -d 100 -s 8000 -p 8000 -c 80000 -r %rnds% -f :: name of report file... set report=rep_wilk.txt :: ----------------------------- (calls testaset.bat to override) :: call testaset.bat (disabled) :: if exist %test%\*.red goto testok echo no test redcode goto end :testok echo. echo Creating warrior benchmark report, don't press any keys... echo. :: initiate report file echo Warrior Benchmarks>%report% echo.|time|find "Cur">>%report% echo.|date|find "Cur">>%report% echo Comline: %pmars%>>%report% echo.>>%report% :: initiate temp report file echo ------------------------------------------------>report$$ :: remove existing score results file, will :: use to build sorted report if exist results$ del results$ :: loop thru all redcode in current dir :: for %%a in (*.red) do call %testall% Test %%a :: need to sort the warriors in the report, nicer... if exist testa$$.bat del testa$$.bat for %%a in (*.red) do echo call %testall% Test %%a >> testa$$.bat sort < testa$$.bat > testa$$$.bat call testa$$$.bat del testa$$*.bat :: turn into a report sort/r>%report% echo.>>%report% type report$$>>%report% del results$ del report$$ :: done... cls goto end :: batch sub.. :: test warrior specified in %2 against *.red in %test% :testwarrior if exist battle$1.out del battle$1.out for %%b in (%test%\*.red) do call %testall% Battle %2 %%b del score$$ :: create and qbasic program to chart performance :: gets name from file %2 :: writes bench results to battle$1.out :: appends score and warrior info to results$ :: modified to permit higher rounds echo> rank$.bas :on error goto Q echo>>rank$.bas open "%2" for input as #1::n$="Anonymous" echo>>rank$.bas while eof(1)=0:line input #1,a$ echo>>rank$.bas if left$(a$,6)=";name " then n$=right$(a$,len(a$)-6) echo>>rank$.bas wend:close #1 echo>>rank$.bas :on error goto X echo>>rank$.bas open "battle$1.out" for input as #1 echo>>rank$.bas open "score$2" for output as #2 echo>>rank$.bas ? #2, "Opponent Scores Results Performance of ";n$ echo>>rank$.bas ? #2, "--------------- --------- ----------- ---------=---------=---------=---------=" echo>>rank$.bas L:line input #1,a$:if instr(a$,"scores ")=0 goto L echo>>rank$.bas line input #1,b$:line input #1,c$:if instr(a$,"%name%")=0 goto L echo>>rank$.bas w$=left$(b$,instr(b$," by ")):w$=left$(w$+" ",15) echo>>rank$.bas ms=val(right$(a$,len(a$)-instr(a$,"scores ")-6)):ts=ts+ms echo>>rank$.bas os=val(right$(b$,len(b$)-instr(b$,"scores ")-6)):no=no+1 echo>>rank$.bas ms$=left$(str$(ms)+" ",5):os$=left$(str$(os)+" ",5) echo>>rank$.bas re$=right$(c$,len(c$)-8):re$=left$(re$+" ",13) echo>>rank$.bas ? #2,w$;ms$;os$;re$;:if os+ms=0 or ms=0 goto N echo>>rank$.bas ra=(ms/(%rnds%*3))*40:for z=1 to ra:? #2,"*";:next z echo>>rank$.bas N:? #2,"":goto L echo>>rank$.bas X:resume Y echo>>rank$.bas Y:? #2,"--------------- --------- ----------- ---------=---------=---------=---------=" echo>>rank$.bas if not no=0 then echo>>rank$.bas s=int(((ts/no)/(%rnds%/100))*10)/10 echo>>rank$.bas ? #2,"Adjusted Score:";s echo>>rank$.bas :on error goto Q echo>>rank$.bas open "results$" for append as #3 echo>>rank$.bas s$=ltrim$(rtrim$(str$(s))) echo>>rank$.bas if instr(s$,".")=0 then s$=s$+".0" echo>>rank$.bas s$=right$("00"+s$,5):? #3,s$,"%2",n$ echo>>rank$.bas end if echo>>rank$.bas Q:close:system qbasic /run rank$.bas del rank$.bas :: let user know something is happening echo. type score$2 echo. :: add redcode listing and bench results :: to the temp report file... echo.>>report$$ echo Warrior %2>>report$$ echo.>>report$$ type %2>>report$$ echo.>>report$$ type score$2>>report$$ echo.>>report$$ echo ------------------------------------------------>>report$$ del score$2 del battle$1.out goto end :: batch sub - run the battle using pmars :battlewarrior >score$$ %pmars% %2 %3 type score$$ type score$$>>battle$1.out :end ::------- end T8KW.BAT ----------------------------------------------------- ::------- begin HILL8000.BAT --------------------------------------------- :: run corewar hill - everyone plays everyone including self :: set to 100 rounds fixed sequence, 8000-coresize specs :: operates on *.red files in current dir :: writes pmars score results to hill.out :: runs scorelog.bat to score results when done :: modified to use new scorelog 3rd parm to avoid :: over-scoring self battles @echo off if .%1==.sub goto %1%2 set pmarscl=pmars -b -l 100 -d 100 -s 8000 -p 8000 -c 80000 -r 100 -f if exist hill.out del hill.out if exist results.txt del results.txt echo Running hill... do not press any keys... for %%a in (*.red) do call %0 sub 1 %%a del battle.tmp call scorelog.bat hill.out results.txt x ::cls ::list results.txt echo Results in results.txt goto end :sub1 for %%b in (*.red) do call %0 sub 2 %3 %%b goto end :sub2 %pmarscl% %3 %4 > battle.tmp type battle.tmp type battle.tmp >> hill.out :end ::------- end HILL8000.BAT ----------------------------------------------- ::------- begin SCORELOG.BAT --------------------------------------------- :: Takes raw score data and creates sorted score file, :: normalized 0-300. If no outfile types results to screen. :: Requires QBasic. Previous version Sept 9 2000 by Terry Newton :: Last modified April 28 2009 (increase score resolution, rank numbers) @echo off if .%1==. echo SCORELOG file [outfile] [x] if .%1==. echo as in SCORELOG temp.out score.fil if .%1==. echo use anything as 3rd parm to look only at 1st position if .%1==. goto quit if not exist %1 echo nothing to score if not exist %1 goto quit echo Scoring log file, please wait... echo> score$.bas :on error goto donefile echo>>score$.bas dim war$(500),score(500),plays(500):maxwar=0 echo>>score$.bas open "%1" for input as #1 echo>>score$.bas L:line input #1,a$:if instr(a$, "Results:")=0 goto L echo>>score$.bas close #1:x=instr(a$," "):y=instr(x+1,a$," ") echo>>score$.bas z=instr(y+1,a$," "):q=val(mid$(a$,x,y-x)) echo>>score$.bas r=val(mid$(a$,y,z-y)):s=val(right$(a$,len(a$)-z)) echo>>score$.bas rounds=q+r+s:if rounds=0 goto done echo>>score$.bas for i=1 to 500:war$(i)="":score(i)=0:plays(i)=0:next i echo>>score$.bas open "%1" for input as #1 echo>>score$.bas floop:line input #1,a$:a$=ltrim$(rtrim$(a$)) echo>>score$.bas p=instr(a$," scores "):if p=0 goto floop echo>>score$.bas name$=left$(a$,p) echo>>score$.bas if maxwar=0 then echo>>score$.bas war$(0)=name$:j=0:maxwar=1 echo>>score$.bas else echo>>score$.bas j=maxwar:for i=0 to maxwar-1 echo>>score$.bas if name$=war$(i) then j=i:i=maxwar-1 echo>>score$.bas next i echo>>score$.bas end if echo>>score$.bas if j=maxwar then war$(maxwar)=name$:maxwar=maxwar+1 echo>>score$.bas u$=right$(a$,5):sp=instr(u$," ") echo>>score$.bas if (sp=0)=0 then u$=right$(u$,len(u$)-sp) echo>>score$.bas plays(j)=plays(j)+1:score(j)=score(j)+val(u$) if .%3==. goto lookatboth echo>>score$.bas line input #1,a$ 'skip 2nd score line :lookatboth echo>>score$.bas goto floop echo>>score$.bas donefile:close #1:resume writeresults echo>>score$.bas writeresults:on error goto done echo>>score$.bas open "score$.tmp" for output as #1 echo>>score$.bas if maxwar=0 then goto done echo>>score$.bas for i=0 to maxwar-1 echo>>score$.bas ws=int(((score(i)/plays(i))/rounds)*10000)/100+1000.001 echo>>score$.bas wscore$=str$(ws):mid$(wscore$,2,1)=" " echo>>score$.bas mid$(wscore$,9,1)=" ":print #1,wscore$,war$(i):next i echo>>score$.bas done:close #1:system qbasic /run score$.bas del score$.bas if not exist score$.tmp echo ERROR if not exist score$.tmp goto quit sort /R < score$.tmp > score$.sor del score$.tmp echo> rank$.bas :on error goto nofile echo>>rank$.bas open "score$.sor" for input as #1 echo>>rank$.bas open "score$.out" for output as #2 echo>>rank$.bas rank=1 echo>>rank$.bas while not eof(1) echo>>rank$.bas line input #1,scoreline$ echo>>rank$.bas rank$=left$(str$(rank)+" ",3) echo>>rank$.bas print #2,rank$;scoreline$:rank=rank+1 echo>>rank$.bas wend echo>>rank$.bas nofile:close:system qbasic /run rank$.bas del rank$.bas del score$.sor if not .%2==. copy score$.out %2>nul if not .%2==. goto notype type score$.out|more pause :notype del score$.out :quit ::------- end SCORELOG.BAT ----------------------------------------------- '-------- begin HILLREP.BAS ---------------------------------------------- REM Generate hill report charts showing the performance REM of each warrior against all other warriors. 4/14/09 REM Setup... hillout$ = "hill.out" hillrep$ = "hill.txt" tempfile$ = "temp$$$$" REM End setup curwar$ = "" ON ERROR GOTO fileerror OPEN hillrep$ FOR OUTPUT AS #2 OPEN hillout$ FOR INPUT AS #3 OPEN tempfile$ FOR OUTPUT AS #1 WHILE NOT EOF(3) LINE INPUT #3, warriorscoreline$ LINE INPUT #3, opponentscoreline$ LINE INPUT #3, resultline$ z = INSTR(resultline$, "Results: ") IF z = 0 THEN GOTO bigtimeerror numbers$ = MID$(resultline$, 10) z = INSTR(numbers$, " ") n1 = VAL(LEFT$(numbers$, z - 1)) numbers$ = MID$(numbers$, z + 1) z = INSTR(numbers$, " ") n2 = VAL(LEFT$(numbers$, z - 1)) n3 = VAL(MID$(numbers$, z + 1)) rounds = n1 + n2 + n3 z = INSTR(warriorscoreline$, " by ") IF z = 0 THEN GOTO bigtimeerror warrior$ = LEFT$(warriorscoreline$, z - 1) IF curwar$ = "" THEN curwar$ = warrior$ IF warrior$ <> curwar$ THEN CLOSE #1 GOSUB processchart OPEN tempfile$ FOR OUTPUT AS #1 curwar$ = warrior$ END IF PRINT #1, warriorscoreline$ PRINT #1, opponentscoreline$ PRINT #1, resultline$ WEND CLOSE #3: CLOSE #1 GOSUB processchart CLOSE KILL tempfile$ SYSTEM bigtimeerror: CLOSE PRINT "Hill out file corrupt" SYSTEM fileerror: CLOSE PRINT "File error" SYSTEM processchart: OPEN tempfile$ FOR INPUT AS #1: no = 0: ts = 0 PRINT #2, "" PRINT #2, "Opponent Scores Results Performance of "; curwar$ PRINT #2, "----------------------- --------- ----------- ---------=---------=---------=---------=" WHILE NOT EOF(1) LINE INPUT #1, a$: LINE INPUT #1, b$: LINE INPUT #1, c$ w$ = LEFT$(b$, INSTR(b$, " by ")): w$ = LEFT$(w$ + " ", 23) ms = VAL(RIGHT$(a$, LEN(a$) - INSTR(a$, "scores ") - 6)): ts = ts + ms os = VAL(RIGHT$(b$, LEN(b$) - INSTR(b$, "scores ") - 6)): no = no + 1 ms$ = LEFT$(STR$(ms) + " ", 5): os$ = LEFT$(STR$(os) + " ", 5) re$ = RIGHT$(c$, LEN(c$) - 8): re$ = LEFT$(re$ + " ", 13) PRINT #2, w$; ms$; os$; re$; : IF os + ms = 0 OR ms = 0 GOTO N ra = (ms / (rounds * 3)) * 40: FOR z = 1 TO ra: PRINT #2, "*"; : NEXT z N: PRINT #2, "" WEND CLOSE #1 PRINT #2, "----------------------- --------- ----------- ---------=---------=---------=---------=" s = INT(((ts / no) / (rounds / 100)) * 10) / 10 PRINT #2, "Adjusted Score:"; s RETURN '-------- end HILLREP.BAS ------------------------------------------------ End of test programs.