#178992 - 2007-08-09 10:53 AM
Re: KiXgolf: Top Secret
[Re: Björn]
|
Jochen
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
Top
|
|
|
|
#179017 - 2007-08-09 05:05 PM
Re: KiXgolf: Top Secret
[Re: Jochen]
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Crap. Only letters (A-Z and a-z) will add to my code.
|
Top
|
|
|
|
#179022 - 2007-08-09 05:26 PM
Re: KiXgolf: Top Secret
[Re: Jochen]
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
hehe... dude, I like you using the pre. looks lot nicer.
I modded the kixgolf_ts.kix:
; KiXtart Golf
;
;
break on
; standard KiXgolf variables
dim $sGolfScoreUDF, $bGolfScore, $sKiXgolfUDF, $sOutputFile
dim $sTitle, $iRC, $sKiXGolfScrEngVer, $sKiXformsVer, $objKiXforms
dim $sStartTimeDate, $sEndTimeDate, $sRunTime
dim $iKiXGolfScore, $sOutput, $sResult,$outputResult
dim $sKiXGolfINI, $asTests, $iTests, $iValid, $sTest, $sInput, $sOutput, $sResult, $iBlockSize,$sPermutation
; set required options
$sTitle='Top Secret'
$iRC=SETTITLE('KiXtart Golf: '+$sTitle)
$iRC=SETOPTION('Explicit','on')
$iRC=SETOPTION('NoVarsInStrings','on')
$iRC=SETOPTION('NoMacrosInStrings','on')
$iRC=SETOPTION('WrapAtEOL','on')
$iRC=SETOPTION('CaseSensitivity','on')
cls
$sGolfScoreUDF=@scriptdir+'\'+'kixgolf3.3.udf'
if exist($sGolfScoreUDF)
call $sGolfScoreUDF
$bGolfScore=1
else
? 'Unable to find the KiXgolf Scoring Engine, exiting script'
exit 2
endif
$sKiXGolfScrEngVer = '3.3'
; this is the actual KiXgolf UDF
$sKiXGolfUDF=@scriptdir+'\'+join(split(ucase(@scriptname),'.KIX'),'.udf')
if exist($sKiXGolfUDF)
call $sKiXGolfUDF
else
? 'KiXgolf UDF not present!'
exit 2
endif
; initialize official KiXtart Golf Score results file
$sOutputFile=@scriptdir+'\'+join(split(ucase(@scriptname),'.KIX'),'.txt')
; this is the start of the main loop
$sStartTimeDate=@DATE+' '+@TIME+'.'+right('000'+@MSECS,3)
$sKiXGolfINI=@scriptdir+'\'+join(split(ucase(@scriptname),'.KIX'),'.ini')
$asTests=split(readprofilestring($sKiXgolfINI,'',''),chr(10))
if $asTests[ubound($asTests)]=''
redim preserve $asTests[ubound($asTests)-1]
endif
$iTests=(ubound($asTests)+1)*2
$iValid=0
for each $sTest in $asTests
? 'Running '+$sTest+' Encoding...'
$iBlocksize=int(readprofilestring($sKiXgolfINI,$sTest,'Blocksize'))
$sPermutation=readprofilestring($sKiXgolfINI,$sTest,'Permutation')
$sInput=readprofilestring($sKiXgolfINI,$sTest,'Input')
$sOutput=readprofilestring($sKiXgolfINI,$sTest,'Output')
; testing the encoding of a message
$sResult=a($iBlocksize,$sPermutation,$sInput,'E')
if $sOutput==$sResult
$iValid=$iValid+1
else
? "failed: '" $sOutput "' =! '" $sResult "'"?
endif
'Decoding...'
; testing the decoding of a message
$sResult=a($iBlocksize,$sPermutation,$sResult,'D')
if $sInput==$sResult
$iValid=$iValid+1
else
? "failed: " $sInput " =! " $sResult ?
endif
'Done'
next
; this is the end of the main loop
$sEndTimeDate=@DATE+' '+@TIME+'.'+right('000'+@MSECS,3)
$sRunTime=datetimediff($sStartTimeDate, $sEndTimeDate)
; this is the end of main loop
if $iValid=$iTests
$outputResult='Solution passed all '+$iTests+' tests'
else
$outputResult='Solution failed '+($iTests-$iValid)+' of '+$iTests+' tests.'
endif
; generate KiXtart Golf Score
$iKiXGolfScore=KiXGolf($sKiXGolfUDF)
; generating official KiXGolf Score
$sOutput=''
$sOutput=$sOutput+@CRLF+'KiXtart'
$sOutput=$sOutput+@CRLF+'KiXtart Version = '+@KIX
$sOutput=$sOutput+@CRLF+'KiXGolf Script = '+@SCRIPTNAME
$sOutput=$sOutput+@CRLF+''
$sOutput=$sOutput+@CRLF+'Computer'
$sOutput=$sOutput+@CRLF+'OS = '+@PRODUCTTYPE
$sOutput=$sOutput+@CRLF+'CPU = '+@CPU
$sOutput=$sOutput+@CRLF+'Speed = '+@MHZ+' MHz'
$sOutput=$sOutput+@CRLF+'Memory = '+(round(cdbl(MEMORYSIZE(0))/2)*2)+' MB'
$sOutput=$sOutput+@CRLF+''
$sOutput=$sOutput+@CRLF+'KiXGolf Scoring Engine'
$sOutput=$sOutput+@CRLF+'Scoring Engine = '+$sKiXGolfScrEngVer
$sOutput=$sOutput+@CRLF+''
$sOutput=$sOutput+@CRLF+'KiXtart Golf Score'
$sOutput=$sOutput+@CRLF+'Tournament = '+$sTitle
$sOutput=$sOutput+@CRLF+'Processing Start = '+$sStartTimeDate
$sOutput=$sOutput+@CRLF+'Processing End = '+$sEndTimeDate
$sOutput=$sOutput+@CRLF+'Duration = '+$sRunTime
$sOutput=$sOutput+@CRLF+'KiXGolf Result = '+$outputResult
$sOutput=$sOutput+@CRLF+'KiXGolf Score = <font color="red">'+$iKiXGolfScore+'</font>'
$sOutput=$sOutput+@CRLF+' '
$sOutput=$sOutput+@CRLF+'Thank you for participating in KiXtart Golf!'
; saving and displaying official KiXtart Golf Score
$iRC=redirectoutput($sOutputFile,1)
'<br><br><pre style="background:white;border-style:solid;border-color:silver;">'
? $sOutput+@CRLF+'</pre><br><br>'
$iRC=redirectoutput('')
? $sOutput
; display score when using WKIX32
if @SCRIPTEXE='WKIX32.EXE'
? 'Press any key to continue...'
? 'Remember to post your scrore!'
get $iRC
run 'notepad '+$sOutputFile
endif
exit 0
; any modifications below this line will result in immediate disqualification
;support UDFs for date/time calculations
;FUNCTION DateTimeDiff
;
;ACTION Calculates the time difference between two date-times-groups
;
;AUTHOR Jens Meyer (sealeopard@usa.net)
;
;VERSION 1.1
;
;KIXTART 4.20
;
;SYNTAX DATETIMEDIFF(DTG1 [,DTG2])
;
;PARAMETYERS DTG1
; Required string as a date-time-group (DTG) in one of the following formats:
; "YYYY/MM/DD HH:MM[:SS.MSECS]"
; "YYYY/MM/DD" which assumes that HH:MM[:SS.MSECS] = 00:00:00.000
; "HH:MM[:SS.MSECS]" which assumes that "YYY/MM/DD" = @DATE
;
; DTG2
; Optional string as date-time-group (DTG) in one of the following formats:
; "YYYY/MM/DD HH:MM[:SS.MSECS]"
; "YYYY/MM/DD" which assumes that HH:MM[:SS.MSECS] = @TIME
; "HH:MM[:SS.MSECS]" which assumes that "YYY/MM/DD" = @DATE
; DTG2 will default to the current date and time if not provided in the form of
; @DATE+' ' +@TIME+'.'+@MSECS
;
;
;
;RETURNS Returns difference DTG2-DTG1 as "YYYY/MM/DD HH:MM[:SS.MSECS]"
;
;REMARKS none
;
;DEPENDENCIES SERIALTIME() @ http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000039
; SERIALDATE() @ http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000089
;
;EXAMPLE $rc=DATETIMEDIFF('23:20:33','01:01:01.245')
;
;KIXTART BBS http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000374
;
function datetimediff($time1,$time2)
Dim $date1, $date2, $datediff, $timediff
$datetimediff=''
if not instr($time1,' ')
select
case instr($time1,'/')
$time1=$time1+' 00:00:00.000'
case instr($time1,':')
$time1=@DATE+' '+$time1
case 1
exit 87
endselect
endif
if not instr($time2,' ')
select
case instr($time2,'/')
$time2=$time2+' '+@TIME+'.'+right('000'+@MSECS,3)
case instr($time2,':')
$time2=@DATE+' '+$time2
case 1
$time2=@DATE+' '+@TIME+'.'+right('000'+@MSECS,3)
endselect
endif
$time1=split($time1,' ')
$date1=$time1[0]
$time1=$time1[1]
$time2=split($time2,' ')
$date2=$time2[0]
$time2=$time2[1]
$datediff=serialdate($date2)-serialdate($date1)
$timediff=serialtime($time2)-serialtime($time1)
if $timediff=>86400
$timediff=$timediff-86400
$datediff=$datediff+1
endif
$datediff=serialdate(serialdate('0000/00/00')+$datediff-1)
$timediff=serialtime($timediff)
$datetimediff=$datediff+' '+$timediff
exit 0
endfunction
;FUNCTION SerialDate
;
;ACTION Convert dates to numbers (and back) for the purpose of performing date math
;
;AUTHOR ScriptLogic (http://www.scriptlogic.com)
;
;CONTRIBUTOR Jens Meyer (sealeopard@usa.net)
;
;VERSION 1.1
;
;SYNTAX SERIALDATE(DATE)
;
;PARAMETERS DATE or NUMBER
; if a date is used, it must be in the form of "YYYY/MM/DD"
; if a number is used, it must be a number previously derived from this function.
;
;RETURNS If a date is passed to this function, the function returns a number. If a number is
; passed to this function, a date "YYYY/MM/DD" is returned
;
;REMARKS This function was developed as a core routine for the DateMath( ) function. In
; normal usage, you would most like just use the DateMath( ) function which depends
; on this function.
; Algorithms used in the development of this routine were obtained from:
; http://www.capecod.net/~pbaum/date/date0.htm
;
; Fixed a couple of inconsistencies in the returned values and formatting
;
;DEPENDENCIES none
;
;EXAMPLE $rc=serialdate('2001/07/01')
;
;KIXTART BBS http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000089
;
function serialdate($ExpD)
dim $z,$h,$a,$b,$c,$y,$m,$d
if instr($ExpD,'/')
$ExpD=split($ExpD,'/')
$y=val($ExpD[0])
$m=val($ExpD[1])
$d=val($ExpD[2])
if $m<3
$m=$m+12
$y=$y-1
endif
$SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
else
$z=0+$ExpD+306
$h=100*$z-25
$a=$h/3652425
$b=$a-$a/4
$y=(100*$b+$h)/36525
$c=$b+$z-365*$y-$y/4
$m=(5*$c+456)/153
$d=$c-(153*$m-457)/5
if $m>12
$y=$y+1
$m=$m-12
endif
$SerialDate=right('0000'+$y,4)+'/'+right('00'+$m,2)+'/'+right('00'+$d,2)
endif
endfunction
;FUNCTION SerialTime
;
;AUTHOR Jens Meyer (sealeopard@usa.net)
;
;ACTION Convert time to numbers (and back) for the purpose of performing time math
;
;VERSION 1.1
;
;KIXTART 4.20
;
;SYNTAX SERIALTIME(STRTIME)
;
;PARAMETERS STRTIME
; Reqired string containing either a time "HH:MM[:SS.MSECS]" or an integer greater
; than zero and less than 86400 representing seconds and fractions
; e.g 20.040 for 20 seconds and 40 milliseconds
;
;RETURNS If supplied a time, returns seconds since midnight. If supplied seconds since
; midnight, returns time.
;
;REMARKS Reworked function based on the ScriptLogic UDF but without dependencies and adapted for milliseconds
; The original ScriptLogic UDF at
; http://www.scriptlogic.com/kixtart/FunctionLibrary_ViewFunction.aspx?ID=SerialTime
; cannot manage milliseconds and relies on three dependencies.
;
;DEPENDENCIES none
;
;EXAMPLE $rc=SERIALTIME('02:20:33.187')
;
;KIXTART BBS http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000039
;
function serialtime($strtime)
dim $hours, $minutes, $seconds, $milliseconds
if instr($strtime,':')
$strtime=split($strtime,':')
select
case ubound($strtime)<3
redim preserve $strtime[3]
if instr($strtime[2],'.')
$strtime[3]=right($strtime[2],len($strtime[2])-instr($strtime[2],'.'))
$strtime[2]=left($strtime[2],instr($strtime[2],'.')-1)
else
$strtime[3]=0
endif
case ubound($strtime)>3
$serialtime=-1
exit 87
endselect
$hours=val($strtime[0])
if $hours<0 or $hours>23
$serialtime=-1
exit 87
endif
$minutes=val($strtime[1])
if $minutes<0 or $minutes>59
$serialtime=-1
exit 87
endif
$seconds=val($strtime[2])
if $seconds<0 or $seconds>59
$serialtime=-1
exit 87
endif
$milliseconds=cdbl($strtime[3])
if $milliseconds<0 or $milliseconds>999
$serialtime=-1
exit 87
endif
$serialtime=0.0+($hours*3600)+($minutes*60)+($seconds)+($milliseconds/1000)
else
$strtime=val(cdbl($strtime)*1000)
if $strtime<=86400000 and $strtime>=0
$hours=$strtime/3600/1000
$strtime=$strtime-($hours*3600*1000)
$hours=right('00'+$hours,2)
$minutes=$strtime/60/1000
$strtime=$strtime-($minutes*60*1000)
$minutes=right('00'+$minutes,2)
$seconds=$strtime/1000
$strtime=$strtime-($seconds*1000)
$seconds=right('00'+$seconds,2)
$milliseconds=left($strtime,3)
$milliseconds=right('000'+$milliseconds,3)
$serialtime=$hours+':'+$minutes+':'+$seconds+'.'+$milliseconds
else
$serialtime='-1'
exit 87
endif
endif
endfunction
; this is a replacement for the formatnumber() function that seems to be buggy
function numberformat($number,$digits)
dim $comma
$comma=READVALUE('HKEY_CURRENT_USER\Control Panel\International','sDecimal')
$digits=val($digits)
if $digits<0
$digits=0
endif
$number=''+round(cdbl($number),$digits)
if not instr($number,$comma)
$number=$number+$comma
endif
$number=split($number,$comma)
if $digits=0
$numberformat=$number[0]
return
endif
while len($number[1])<$digits
$number[1]=$number[1]+'0'
loop
$number=join($number,$comma)
$numberformat=$number
endfunction
;FUNCTION ATrim
;
;ACTION Strips leading and trailing spaces from an input string or array and returns the result
;
;AUTHOR Jens Meyer (sealeopard@usa.net)
;
;VERSION 1.3
;
;KIXTART 4.20
;
;SYNTAX ATRIM(STRING)
;
;PARAMETERS STRING
; Required string or array from which to strip leading and trailing spaces
;
;RETURNS Input string/array without leading and trailing spaces
;
;REMARKS Function converts an array with a maximum of 26 dimensions
;
;DEPENDENCIES none
;
;EXAMPLE $array[0]=' String1'
; $array[1]=' String2 '
; $rc=atrim($array)
;
;KIXTART BBS http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000031
;
function atrim($array)
Dim $element, $maxelements, $arraydim, $rc, $a
select
case ubound($array,1)=-1
$array=trim($array)
case ubound($array,2)=-1
$maxelements=val(ubound($array))
for $element=0 to $maxelements
$array[$element]=trim($array[$element])
next
case ubound($array,27)=-1
$arraydim=0
do
$arraydim=$arraydim+1
until ubound($array,$arraydim)=-1
$arraydim=$arraydim-1
if $arraydim<=26
dim $cmd, $vars
$vars='$sub_a'
for $a=2 to $arraydim
$vars=$vars+', $sub_'+chr($a+96)
next
$cmd='dim '+$vars+@CRLF
for $a=1 to $arraydim
$cmd=$cmd+'for $sub_'+chr($a+96)+'=0 to ubound($array,'+$a+')'+@CRLF
next
$cmd=$cmd+'$array['+$vars+']=trim($array['+$vars+'])'+@CRLF
for $a=1 to $arraydim
$cmd=$cmd+'next'+@CRLF
next
$rc=execute($cmd)
endif
case 1
endselect
$atrim=$array
endfunction
to note, when there is a failure, I think showing the failure is crucial, that's why there is print line on the check part. with wkix32.exe, displaying the result could be totally supressed, if there are no errors, just splash the notepad open.
_________________________
!download KiXnet
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 539 anonymous users online.
|
|
|