Page 1 of 3 123>
Topic Options
#66025 - 2002-06-04 04:38 AM KixGolf scoring script
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
code:
; This function scores the specified file and returns the KixGolf score.
; That is the total number of key strokes used to build a script not counting
; comments, spaces, tabs, or any ascii character above 126.
Function KixGolf($A)
if open (1,$A) = 0
$X=0
$Q=""
$C=readLine(1)
while @error=0
$j=len($C) ; Get length of the line
for $h=1 to $j ; Loop through each character in line
$D=asc(substr($C,$h,1))
if $D=34 or $D=39
if $Q=""
$Q=$D
else
if $Q=$D
$Q=""
endif
endif
endif

if $D=59 ; Ignore comment lines
$h=$j ; Terminate loop
else
if $Q<>""
$X=$X+1 ; Count the valid characters
else
if $D>32 and $D<127
$X=$X+1 ; Count the valid characters
endif
endif
endif
next
$C=readLine(1)
loop
else
? "$A ??" ; Show bad file name
endif
if $Q<>""
? "Mis-matched quotes. Probable score error." ?
endif
$KixGolf=$X
EndFunction

? "KixGolf score = " + KixGolf($A) ;$A must be initialized on the command line.
;%tmp%\kix32 kixgolf.kix $A=Kixgolf.kix



[ 04 June 2002, 19:46: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66026 - 2002-06-04 02:30 PM Re: KixGolf scoring script
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Nice work Howard - ok, we have our clubs (Kixtart) and now we have our scorecards (KixGolf), all we need now is a fairway (Jens) and a rainy weekend ... four !!! [or should we say: four point one zero!!!] [Wink]

-Shawn

Top
#66027 - 2002-06-04 03:39 PM Re: KixGolf scoring script
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
So Howard, I guess the strategy would be to develop our solution as a UDF (assuming the puzzle was presented as such) in a seperate file, say kixgolf.kix, and this script would contain just a single function - the UDF being worked on. Then we would also have a "proof script", that included and called the puzzle UDF, this would be our driver script.

Then, we would run your kixgolf script against our solution script, and that we be the official golf score, yeah ?

-Shawn

Top
#66028 - 2002-06-04 04:04 PM Re: KixGolf scoring script
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Once presented with a problem, we could all write a solution then post just the KixGolf score. It would be interesting if everyone that tried would post thier score even if it was not the best. They could then retry and post an improved score if possible. Then after 24 hours we could post the code.

The solution could be what ever was called for, a UDF or just script code. You would save your entry to a file (you choose the name). Then score your solution by executing:

Kix32 KixGolf $A=YourFile

You will first have to save the above code to a file called KixGolf.kix. It just so happens that I used the script on itself just to see how many strokes it was. [Wink]

{edit}
I see how the score for the scoring script can be improved by one stroke already.

[ 04 June 2002, 16:08: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66029 - 2002-06-04 04:25 PM Re: KixGolf scoring script
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Might be able to improve the kixgolf script score by a few strokes if you used the split function to "parse-out" the script, line-by-line. A default split (no second parm specified) should be able automatically skip over all the white-space that your checking for now, then all thats left is to do some sort of instr($c,";") to get at the comments ?

-Shawn

Top
#66030 - 2002-06-04 04:26 PM Re: KixGolf scoring script
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
slight problem with the script:

What if someone encloses a ; between quotes? Or what if a space is enclosed between quotes? Shouldn't these count as part of your score as well because they are pertinent to the code?

IMHO:

The only spaces or tabs that shouldn't be counted are at the beginning and end of a line. All text within quotes should be counted. Other characters above ASCII 127 should count as well, because who would use them unless they pertained to the code?

Brian

[ 04 June 2002, 16:28: Message edited by: BrianTX ]

Top
#66031 - 2002-06-04 04:31 PM Re: KixGolf scoring script
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Good catch. Any suggestions to correct it. If not, I'll look into it.

Questions: Should all text within quotes be counted? What characters should definitely not be counted?

Before we start using it, I want it to be sound and everyone buy off on it.

[ 04 June 2002, 16:32: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66032 - 2002-06-04 04:35 PM Re: KixGolf scoring script
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Brian, would you penalized someone for:

$A = 1 vs. $A=1
or
$A=1 ;Set var $a

because the spaces are not at the beginning of the line?

[ 04 June 2002, 16:35: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66033 - 2002-06-04 04:41 PM Re: KixGolf scoring script
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
You have a good point, but I thought the objective was NOT to maximize readability, but to minimized the size of the file. If you're talking about having a space where one need not be, then why penalize for the size of variable names, either?

Either you can optimize for execution speed (i.e. number of keywords, variables, operators), or you can optimize for size.

Just my 2 cents.

Brian

[ 04 June 2002, 16:42: Message edited by: BrianTX ]

Top
#66034 - 2002-06-04 04:51 PM Re: KixGolf scoring script
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I guess since we have a potential scoring script that could permit some enhanced readability we could score around those additional spaces. The variable length is also a good point but that would start to complicate the scoring script. I guess we need to clarify what is really important and what the ultimate goal really is.

If we really want cryptic hard to read/understand code we could go with raw file size, but if the goal is to strive for good coding technique then we could permit some improved readability and attempt to only count applicable code.

I just want to write the solutions and had a hard time understanding how they compared to to others. This is why I wrote the scoring script. that way we all could easily calculate a score based on the same rules.

We just need to clarify what those rule will be.

[ 04 June 2002, 16:52: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66035 - 2002-06-04 05:08 PM Re: KixGolf scoring script
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
I'm with you on that! I agree that a scoring script/function is a great idea. I just think that we need to make sure that the rules regarding what syntax is counted follows common sense.

Obviously, having extra spaces where they are not needed is done strictly for readability, but some spaces are still necessary for scripts to function properly.

Examples:

code:
If $hello = "hi, how are you?" $yes = 1 Endif

Cannot be shortened to:
code:
If$hello="hi,howareyou?"$yes=1Endif

However,
code:
$a = $a + 1

can be shortened to:
code:
$a=$a+1

I suppose my point is that KiXtart code needs spaces and carriage returns in some cases and in other cases does not. As such, should these be counted?

I feel that definitely ALL characters in quotes should be counted. As for counting which spaces are necessary and which are not, that is probably not very easy to do.. that's why I suggested counting all spaces not at the beginning or end of the line. If this sounds like it is making things too complex, then it's not really a big deal. Any further thoughts?

Brian

Top
#66036 - 2002-06-04 05:58 PM Re: KixGolf scoring script
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
The Script at the top of this post has been modified to count all characters enclosed in quotes.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66037 - 2002-06-04 08:10 PM Re: KixGolf scoring script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11163
Loc: Boston, MA, USA
I guess I should chime in, too, since I did manually counting for the scores. Thus
code:
$a=$a+1
$a = $a + 1

both lines get the same score since the spaces are not important.
Also,
code:
IF $a=1 ? 'test' ENDIF
IF $a=1
? 'test'
ENDIF

will also result in the same score. Oh, and everything enclosed within wuotes gets counted, too.
That's why i think a GolfScore UDF is hard to implement because people write code differently. Anyway, I will try to come up with another challenge by this weekend (couldn't do anything last weekend because I trashed my home computer with a stupid mistake). I will also update the rules that nobody is allowed to post a solution within the first 24 hours except the KiXtart Golf score. In a second 24 hour period, everybody is allowed to post code and improve other people's code, too. Therefore, the fairways will get harder, too. No more par 3's.

[ 04 June 2002, 20:11: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#66038 - 2002-06-04 08:14 PM Re: KixGolf scoring script
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Jens, did you give the KixGolf.kix a go around yet? If not, please check it out and let me know if it scores as you would.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66039 - 2002-06-04 09:55 PM Re: KixGolf scoring script
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
I thought of another situation.. what if you have single quotes inside double quotes or the other way? How will you handle that?
(Howard, hope you don't mind.. I borrowed a little from your script...) I added enhancements including multiple quote handling, file closing, better text formatting on printed messages....

Give this script a go:
code:
$Q = 0 
$R = 0
$C = 0
if Open (1,$f) = 0
While @error=0
$L = READLINE(1)
$M = LEN($L)
For $I = 1 to $M
$A=asc(substr($L,$i,1))
IF $A = 34 AND $R = 0
$Q = $Q + 1 & 1
ENDIF
IF $A = 39 AND $Q = 0
$R = $R + 1 & 1
Endif
If $A = 59 $I = $M
Else
If $Q|$R
$C = $C + 1
Else
If $A > 32 AND $A < 127
$C = $C + 1
Endif
Endif
Endif
Next
Loop
$ = Close(1)
Else
"$F?" ?
Endif
If $Q|$R
"Mis-matched quotes. Probable score error." ?
Endif
"KixGolf score = " + $C

$f is passed on the commandline
$f=filename.kix

Brian

Top
#66040 - 2002-06-05 01:45 AM Re: KixGolf scoring script
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Brian, I don't mind help but I do not quite understand the double quote issue that your code corrects. The currently posted code above handles quotes within quotes.

Both the current script and your script seem to yield the same results on my test files.

I wasn't concerned with the nicety of using close since file handle "1" isn't used again and would be forced closed when Kix32 exits. Formally closing the file handle is better style but I do not believe it matters in this case.

I do like your use of the "&" to keep $Q and $R to either "0" or "1". This reduced the code requirement that my empty string or ASCII value approach required. You score some points. [Smile]

[ 05 June 2002, 02:32: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66041 - 2002-06-05 02:34 AM Re: KixGolf scoring script
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
how about just manually stripping out comments
and not counting any spaces, even if in text. If you have more and a few spaces, you would probably have quite a few 'words' which would most likely push up your score anyway. 4 additional 'words' would probably have about 10-15 or more characters in it, the 3 spaces wouldn't make a big deal of difference.

The idea is efficiency... succinct(sp) output should be a requirement also
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#66042 - 2002-06-05 02:46 AM Re: KixGolf scoring script
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Radimus, I think that we are just about finished with the scoring script. If we can agree on the script rules, scoring would be much faster. Did you give the scripts a try yet?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#66043 - 2002-06-05 03:37 AM Re: KixGolf scoring script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11616
Loc: CA
When can I supply CODE for you guys to clean up? [Big Grin] hehehe
Top
#66044 - 2002-06-05 04:12 AM Re: KixGolf scoring script
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Well Doc, you have to be "in the game" to get your code scanned - so we'll make sure to invite you to the "Kixtart Classic Invitational Golf Tournie" this weekend (if we play). Depends on the "weather", and on "whether" Jens can get another course designed ...
Top
Page 1 of 3 123>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 301 anonymous users online.
Newest Members
Quicky76, Tonny, Kelar18, korunekosama, Varro18
17783 Registered Users

Generated in 0.069 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org