Page 1 of 3 123>
Topic Options
#201073 - 2010-12-06 06:01 PM Kixgolf - Bowling Calculator - Public Round
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Please post your code...
Top
#201074 - 2010-12-06 06:06 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: Allen]
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Here is my 156 code

 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

 Quote:

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 Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Here is Jochen's 155
 Code:
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
#201077 - 2010-12-06 06:27 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: Allen]
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
so yeah....almost the same code \:\)
_________________________
Eric

Top
#201079 - 2010-12-06 06:42 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: maciep]
ShaneEP Moderator Offline
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.
 Code:
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
#201080 - 2010-12-06 07:36 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Man I wish I had the math logic down like you guys. I can barely wrap my head around how to do it, even after seeing your code and explanations.
Top
#201081 - 2010-12-06 07:54 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: ShaneEP]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
my 181:
 Code:
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
#201084 - 2010-12-06 09:44 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
153 from jochen's:
 Code:
function a($x)
    dim $v, $b, $
    while $x
        $ = left($x,1)
        $x = right($x,~)
        if $>!
            $v = ($=X)*10 + $ + ($="/")*(10-$v)

            $a = $a +($b+($b<2))*$v
            $b = ($b>1) + (2*($=X)^$="/")*($x<!)
endfunction
_________________________
!

download KiXnet

Top
#201085 - 2010-12-06 09:53 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: Lonkero]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Nice one Jooel,
why haven't I thought about that before \:o
_________________________



Top
#201087 - 2010-12-06 10:41 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: Jochen]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
 Code:
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
#201088 - 2010-12-06 10:49 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: BradV]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Same here Brad. I started with something very similar to yours. Had to rewrite it about 5 times just to get it down to what I ended up with.
Top
#201089 - 2010-12-06 11:22 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: ShaneEP]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
J, dunno but looked weird and kept bugging me for total of 2 mins until I decided something has to give ;\)
and indeed there was extra strokes \:\)
_________________________
!

download KiXnet

Top
#201091 - 2010-12-07 08:00 AM Re: Kixgolf - Bowling Calculator - Public Round [Re: Lonkero]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Maybe I haven't had this constellation long enough to bug my eye.. It was the improvement from 163 to 157.
_________________________



Top
#201092 - 2010-12-07 08:46 AM Re: Kixgolf - Bowling Calculator - Public Round [Re: Jochen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh.
doesn't really hurt you eyes when you think "this baby is my leader" \:\)
_________________________
!

download KiXnet

Top
#201093 - 2010-12-07 09:53 AM Re: Kixgolf - Bowling Calculator - Public Round [Re: Lonkero]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
ok, now to squeeze one or more out of my baby.. that'll be hard.
_________________________



Top
#201094 - 2010-12-07 10:55 AM Re: Kixgolf - Bowling Calculator - Public Round [Re: Jochen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
don't have time to look at it now but there should be more to be shaved in there.
still looks too "messy"
_________________________
!

download KiXnet

Top
#201095 - 2010-12-07 03:09 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
clever code you guys managed to put out. nice.
_________________________
!

download KiXnet

Top
#201096 - 2010-12-07 03:23 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: Lonkero]
BradV Offline
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 Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Someone mind explaining this line?

 Code:
2*($=X)^$="/"

Top
#201099 - 2010-12-07 11:05 PM Re: Kixgolf - Bowling Calculator - Public Round [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
basicly the same as 2*($=x)+($='/')
_________________________
!

download KiXnet

Top
Page 1 of 3 123>


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

Who's Online
0 registered and 393 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.086 seconds in which 0.027 seconds were spent on a total of 15 queries. Zlib compression enabled.

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