#201074 - 2010-12-06 06:06 PM
Re: Kixgolf - Bowling Calculator - Public Round
[Re: Allen]
|
maciep
Korg Regular
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
Here is my 156 code
function a($s)
dim $,$t,$y,$z
while $s
$ = left($s,1)
$s = right($s,~)
if $>#
$a = (1+$y+$z)*(10*($=x)+$+($='/')*(10-$t)) + $a
$z = ($t=x)*$y
$y = ($=x | $='/')*($s<#)
$t = $
;endif
;loop
endfunction
And here is a brief explanation of it
Since we only care about the total score, we don't need to calculate each frame and then add those together. Instead we can keep a running total following the following idea:
Depending on the previous scores, we will add the current score -once, if no spares or strikes carry over -twice, if only one spare or strike carries over -3 times, if a strike and either another strike or spare carries over
So we loop through each character in the string of scores passed in. If the character is not a space, i.e. $># then process...
First, we calculate the total for this score $a = (1+$z+$y)*(10*($=x) + $ + ($='/')*(10-$t)) + $a
(1+$z+$y) This is the multiplier. It will always be at least 1
10*($=x) If it's a strike, then the score is 10.
$ if $ is a number, then just add the number itself. If it's not a number, then it will evaluate to 0
($='/')*(10-$t) If it's a spare, then the score is 10. BUT the spare means the current score PLUS the last one is 10, so we need to subtract the previous score from 10 Now multiply the multiplier times the score, add to our current total and move on.
Next, we figure out the multiplier for the next round
$z= ($t=x)*$y If the previous score was a strike and it we counted it this round, we'll count it next round
$y = ($=x | $='/')*($s<#) if this score was a strike or a spare, and not in the 10th frame, then count it. If it is not in the 10th frame then $x will begin with a space and therefore be less than #.
Store the current score in $y which will be needed if the next score is a spare, as well as for the next $z assignment.
$t=$ Set $t to the current score which we may need in the next round
_________________________
Eric
|
Top
|
|
|
|
#201075 - 2010-12-06 06:13 PM
Re: Kixgolf - Bowling Calculator - Public Round
[Re: maciep]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4548
Loc: USA
|
Here is Jochen's 155
function a($x)
dim $v, $b, $
while $x
$ = left($x,1)
$x = right($x,~)
if $>!
$v = ($=X)*10 + $ + ($="/")*(10-$v)
$a = $a + ($b-($b>1)+1)*$v
$b = ($b>1) + (2*($=X)^$="/")*($x<!)
endfunction
|
Top
|
|
|
|
#201079 - 2010-12-06 06:42 PM
Re: Kixgolf - Bowling Calculator - Public Round
[Re: maciep]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Here's my beast of a code. I went about it a bit differently (resulting in more strokes). I parsed the string into two matching arrays, one with the actual characters and one with the values of those characters. This allowed to cross reference and still be able to tell if a value came from a strike or spare. Nothing to complicated. Could have declared a multi dimen array instead of two and saved some strokes probably, but I kind of ran out of time to work on it. This week is finals week in school, so I probably shouldnt have worked on it at all...but priorities, ya know.
function a($z)
Dim $o,$j,$,$l,$v[22],$d[22]
$o=split($z," ")
$j=join($o,"")
for $=1 to 22
$l=substr($j,$,1)
$d[$]=$l
$v[$]=iif($l=X,10,iif($l="/",10-$v[$-1],cint($l)))
$a=$a+$v[$]
next
for $=1 to len($j)-len($o[9])
if $d[$]="/"
$a=$a+$v[$+1]
else
if $d[$]=X
$a=$a+$v[$+1]+$v[$+2]
; endif
; endif
; next
endfunction
|
Top
|
|
|
|
#201081 - 2010-12-06 07:54 PM
Re: Kixgolf - Bowling Calculator - Public Round
[Re: ShaneEP]
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
my 181:
function a($i)
dim $1,$
$=join(split($i),'')
$1=left($,1)
$a=substr($,3,1)
$=substr($,2,1)
if $
$a=($a='/')*(10-$)+$+iif($1=x | $='/',10*(1+(x=$a)+($=x))+$a,$1)+a(right($i,(x=$1)-3))
endfunction
_________________________
!download KiXnet
|
Top
|
|
|
|
#201087 - 2010-12-06 10:41 PM
Re: Kixgolf - Bowling Calculator - Public Round
[Re: Jochen]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
function a($)
dim $s[9], $c, $e, $k, $l, $m, $i
$s = Split($," ")
for $i = 9 to 0 step -1
$k = Substr($s[$i],1,1)
$l = Substr($s[$i],2,1)
if $i = 9
if $k = "X"
$m = Substr($s[$i],3,1)
if $m = "/"
$a = 20
else
$a = 10 + d($l) + d($m)
endif
else
if $l = "/"
$m = Substr($s[$i],3,1)
$a = 10 + d($m)
else
$a = 0 + d($k) + d($l)
endif
endif
$c = $k
$e = $l
else
if $k = "X"
$a = $a + d($k) + d($c) + d($e)
$e = $c
$c = $k
else
if $l = "/"
$a = $a + d($l) + d($c)
$c = $k
$e = 10 - $k
else
$a = $a + d($k) + d($l)
$c = $k
$e = $l
endif
endif
endif
next
endfunction
;!
function d($)
$d = iif(InStr($, "X") or InStr($, "/"),10,iif(InStr($, "-"),0,$))
endfunction
I obviously over complicated it.
|
Top
|
|
|
|
#201096 - 2010-12-07 03:23 PM
Re: Kixgolf - Bowling Calculator - Public Round
[Re: Lonkero]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
I was working on another version that first converted the "X/-" to numbers and then did a long immediate if to get the results. I had half successful, but didn't have time to finish. I'll have to look at your scripts this afternoon when I get home to try and understand.
|
Top
|
|
|
|
#201097 - 2010-12-07 10:13 PM
Re: Kixgolf - Bowling Calculator - Public Round
[Re: BradV]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4548
Loc: USA
|
Someone mind explaining this line?
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 307 anonymous users online.
|
|
|