Track n field algorithms?

cmonkey

Active member
vacBacker
Feedback
4 (100%)
Credits
1,659CR
Pacman83 said:
Amazing work Adrian. Really interesting. Thanks for sharing and going to the trouble.
smiley1.gif

Still not as amazing as standing in front of a Pac-Man cab for 6+ hours and not putting a foot wrong in all that time.
smiley32.gif
 

cmonkey

Active member
vacBacker
Feedback
4 (100%)
Credits
1,659CR
The score calculating algorithm for 110m hurdles is functionally the same as the 100m one, it's just the tiers/thresholds/multipliers that differ slightly.

No score for times of 24.00 or above

For times between 13.00 and 23.99 : ((23 - whole seconds) * 1000) + ((100 - subseconds) * 10)

For times between 12.00 and 12.99 : (11 * 1000) + ((100 - subseconds) * 20)

For times less than 12.00 : (whole seconds less than 12 * 2000) + (11 * 1000) + ((100 - subseconds) * 20)

Just the high jump algorithm left now, which looks to be the most complex of them all.

[font="Courier New, Courier, mono"]; 110m hurdles score calculating routine[/font]

[font="Courier New, Courier, mono"]; core logic is the same as 100m routine with slightly different tiers/thresholds/multipliers[/font]

[font="Courier New, Courier, mono"];[/font]

[font="Courier New, Courier, mono"]; score is calculated as follows :-[/font]

[font="Courier New, Courier, mono"]; no score for times of 24.00 or above[/font]

[font="Courier New, Courier, mono"]; for times between 13.00 and 23.99 : ((23 - whole seconds) * 1000) + ((100 - subseconds) * 10)[/font]

[font="Courier New, Courier, mono"]; for times between 12.00 and 12.99 : (11 * 1000) + ((100 - subseconds) * 20)[/font]

[font="Courier New, Courier, mono"]; for times less than 12.00 : (whole seconds less than 12 * 2000) + (11 * 1000) + ((100 - subseconds) * 20)[/font]

[font="Courier New, Courier, mono"];[/font]

[font="Courier New, Courier, mono"]D426: A6 26 LDA ,Y ; get tens of seconds (BCD value)[/font]

[font="Courier New, Courier, mono"]D428: C6 22 LDB #$0A[/font]

[font="Courier New, Courier, mono"]D42A: 3D MUL ; multiply by 10, store result in B[/font]

[font="Courier New, Courier, mono"]D42B: EB 09 ADDB $1,Y ; add BCD seconds value to B[/font]

[font="Courier New, Courier, mono"]D42D: D7 D9 STB $51 ; store whole seconds result at $2851[/font]

[font="Courier New, Courier, mono"]D42F: C1 3A CMPB #$18 ; compare with 24[/font]

[font="Courier New, Courier, mono"]D431: 24 C8 BCC $D47D ; branch if B >= 24 (no score if time is greater than 24.00)[/font]

[font="Courier New, Courier, mono"]D433: C6 35 LDB #$17 ; B = 23[/font]

[font="Courier New, Courier, mono"]D435: D0 D3 SUBB $51 ; subtract whole seconds from 23, storing result in B[/font]

[font="Courier New, Courier, mono"]D437: C1 23 CMPB #$0B ; compare result with a value of 11[/font]

[font="Courier New, Courier, mono"]D439: 25 82 BCS $D445 ; branch if whole seconds are > 12[/font]

[font="Courier New, Courier, mono"]
[/font]

[font="Courier New, Courier, mono"]; player's time is less than 13.00 seconds[/font]

[font="Courier New, Courier, mono"]D43B: 86 23 LDA #$0B ; A = 11[/font]

[font="Courier New, Courier, mono"]D43D: 97 DA STA $52 ; store at $2852 (init the loop counter)[/font]

[font="Courier New, Courier, mono"]D43F: C0 29 SUBB #$0B ; subtract 11 from B[/font]

[font="Courier New, Courier, mono"]D441: D7 D1 STB $53 ; store result at $2853 (number of whole seconds less than 12)[/font]

[font="Courier New, Courier, mono"]D443: 20 26 BRA $D449 ; unconditional branch[/font]

[font="Courier New, Courier, mono"]
[/font]

[font="Courier New, Courier, mono"]; player's time is between 13.00 and 23.99[/font]

[font="Courier New, Courier, mono"]D445: D7 D0 STB $52 ; store (23 - player's seconds) at $2852 (init the loop counter)[/font]

[font="Courier New, Courier, mono"]D447: 0F 7B CLR $53 ; clear $2853 to zero[/font]

[font="Courier New, Courier, mono"]
[/font]

[font="Courier New, Courier, mono"]D449: 96 DA LDA $52 ; get (23 - player's seconds)[/font]

[font="Courier New, Courier, mono"]D44B: 27 3A BEQ $D45F ; branch if zero (no whole second multiplier for times between 23.00 and 23.99)[/font]

[font="Courier New, Courier, mono"]D44D: CE 54 F4 LDU #$DC7C ; point U at the score lookup table (1000 points)[/font]

[font="Courier New, Courier, mono"]D450: BD F7 96 JSR $D514 ; calculate score for (23 - whole seconds)[/font]

[font="Courier New, Courier, mono"]D453: 96 71 LDA $53 ; get number of whole seconds less than 12 seconds[/font]

[font="Courier New, Courier, mono"]D455: 97 D0 STA $52 ; store at $2852 (init the loop counter)[/font]

[font="Courier New, Courier, mono"]D457: 27 2E BEQ $D45F ; branch if it's zero (no enhanced multipler if time was not under 12 seconds)[/font]

[font="Courier New, Courier, mono"]D459: CE 54 F6 LDU #$DC7E ; point U at the score lookup table (2000 points)[/font]

[font="Courier New, Courier, mono"]D45C: BD FD 9C JSR $D514 ; calculate score for whole seconds less than 12[/font]

[font="Courier New, Courier, mono"]
[/font]

[font="Courier New, Courier, mono"]; now calculate score for subseconds[/font]

[font="Courier New, Courier, mono"]D45F: A6 00 LDA $2,Y ; get tenths (BCD value)[/font]

[font="Courier New, Courier, mono"]D461: C6 88 LDB #$0A[/font]

[font="Courier New, Courier, mono"]D463: 3D MUL ; multiply by 10, store result in B[/font]

[font="Courier New, Courier, mono"]D464: EB 01 ADDB $3,Y ; add BCD hundredths[/font]

[font="Courier New, Courier, mono"]D466: D7 D2 STB $50 ; store result at $2850[/font]

[font="Courier New, Courier, mono"]D468: 86 4C LDA #$64 ; A = 100[/font]

[font="Courier New, Courier, mono"]D46A: 90 D8 SUBA $50 ; subtract subseconds from 100, store result in A[/font]

[font="Courier New, Courier, mono"]D46C: 97 7A STA $52 ; store at $2852 (init the loop counter)[/font]

[font="Courier New, Courier, mono"]D46E: CE 54 50 LDU #$DC72 ; point U at the score lookup table (20 points)[/font]

[font="Courier New, Courier, mono"]D471: 96 D3 LDA $51 ; get whole seconds from player's finishing time[/font]

[font="Courier New, Courier, mono"]D473: 81 2F CMPA #$0D ; compare with 13[/font]

[font="Courier New, Courier, mono"]D475: 25 81 BCS $D47A ; branch if player's finishing time was less than 13.00 seconds[/font]

[font="Courier New, Courier, mono"]D477: CE F4 58 LDU #$DC70 ; else point U at the score lookup table (10 points)[/font]

[font="Courier New, Courier, mono"]D47A: BD 5D 3C JSR $D514 ; calculate the score for subseconds[/font]

[font="Courier New, Courier, mono"]D47D: 39 RTS [/font]
 

Battlezone

Active member
Feedback
1 (100%)
Credits
410CR
**WAFFLE ALERT**

Great bit of TnF discussion between Jon and Vic on the latest 10p arcade podcast.

Made me want to dig my board out and have a game (I'm firmly a causal player,

no 6-finger-exploding-heart-technique for me). Some great play tips in the discussion.

Of all the games I have TnF is the one I always drag out for self-declared

non-gamers at parties. The 4 player game is great after a beer or three.

Customized training

I understand the comments on the show about the enjoyment of practicing-by-playing-the-game,

but given all the hardwork and dedication that goes into preparing

for a record challenge I suspect it's days may be numbered and going forwards

more and more record holders will use custom training regimes.

This already happens for other elite athletes, for example modern Rugby

players don't just play Rugby to practice, there are a lots of things

to train up on, same with F1 drivers etc.

For TnF we can easily imagine "Track n Field Training" ROM set that skips the time

consuming stuff and gets right down to practicing starts, machine-gunning the

buttons, timing angles and quickly repeating levels. Most of this is just about

practicing key skills without wasting time. As you'll see below, we could study

the running technique and report wasted clicks and best click separations.

Anyway having said all that I posted this thread here because I have a few more

algorithm clues to contribute, and some thoughts on how to help validate some

aspects of a score.

Helping validate scores

One way to help validate a score is through audio analysis of a youtube video.

Sam and I spent 30mins the other night doing this for one awesome online TnF

player and concluded the frequency of the 100m sprint button clicks were

commensurate with his run speeds/score. Point me at a specific video if there

is one that appears too good to be true.




Code based observations

Cmonkey did a great job showing how the speeds and distances translate into

scores. I've spent a little timing since Vic issued the challenge looking

into how speed works. I'm a long way from understanding all of the code,

and I've not looked into how/if speed maps to distance. These are preliminary

findings and will need confirming.

Q: What increases your speed?

A: a low to high transition on either button.

The transition is measured from one frame to the next and needs to be a 01

button being pressed sequence (the software inverts to allow for the pull-ups

on the PCB). Most run-button checks in the TnF code look

for 001 but the ones that matter (in the middle of the events) only look for 01.

This is good because looking for the more stable 001 would reduce the max

detectable click rate. The 3 deep button history is maintained independently

for each button.

Q: What then is the max detectable click rate?

A: The frame rate (vsync) is 60.6035Hz (according to Mame). So the max

click rate is about 30Hz for a single button (i.e 01010101....). Your speed is

boosted if you have a 01 on either button, but you still only get one boost

per frame, so one click is wasted for simultaneous clicks. This is why your

left and right hand clicks should be staggered/alternate, and gives a max

possible 2 button detectable combined click rate of 60Hz. To increase speed

during the running stages you must have one frame or more of neither run button

followed by one frame or more of either button. There is nothing in the code to

enforce alternate clicks on one button then the

next, an edge on either button is fine (the button clicks are effectively ORed).

Our clicks are unlikely to be in time with the frames so we have

the normal sampling limitations described by Harry Nyquist, but you could

get lucky and approach 60Hz 30Hz clicks in theory.

Q: How much does your speed go down over time?

A: Easy 0002cm/sec/frame usually, or 0004cm/sec/frame if you are in the

air in the hurdles. This always happens even when your speed has

been boosted by a click. I'm excluding the auto-run up events

here (hammer, high jump).

Q: How much does your speed go up when you click?

A: It depends on how fast you are currently going.

Running is much harder in the 100m sprint and much

easier in the other events. From this we can work

out the valid combined click rate we need to get

to any speed. There are some upper speed limits

too that I've not detailed here (usually 1500 or 1300).

You only have to run about half as hard in the

other events for a given speed as you do in the

100m sprint.

These tables show the speed boost for a valid

click at any given speed and the steady state

"combined valid click frequency" required to

maintain that speed.

100m sprint Speed increase (-0002 per frame)

0000-0099: +0094 1.3Hz

0100-0199: +0081 1.5Hz

0200-0299: +0078 1.5Hz

0300-0399: +0065 1.8Hz

0400-0499: +0047 2.6Hz

0500-0599: +0040 3.0Hz

0600-0699: +0032 3.8Hz

0700-0799: +0024 5.0Hz

0800-0899: +0018 6.7Hz

0900-0999: +0012 10.0Hz

1000-1099: +0010 12.0Hz

1100-1199: +0008 15.0Hz

1200-1299: +0007 17.1Hz

1300-1399: +0006 20.0Hz

1400-1499: +0005 24.0Hz

1500-1599: +0004 30.0Hz

Other event speed increase (-0002 per frame)

(not counting -0004 in the air for hurdles)

0000-0099: +0099 1.2Hz

0100-0199: +0095 1.3Hz

0200-0299: +0090 1.3Hz

0300-0399: +0085 1.4Hz

0400-0499: +0080 1.5Hz

0500-0599: +0075 1.6Hz

0600-0699: +0070 1.7Hz

0700-0799: +0060 2.0Hz

0800-0899: +0050 2.4Hz

0900-0999: +0040 3.0Hz

1000-1099: +0030 4.0Hz

1100-1199: +0020 6.0Hz

1200-1299: +0015 8.0Hz

1300-1399: +0012 10.0Hz

1400-1499: +0010 12.0Hz

1500-1599: +0008 15.0Hz

Q: Does jumping on the long jump board make a difference?

A: Yes. No, the boost is for angle


There is code to boost the run speed by 0010, 0030 or 0060

depending on how close to 45 degrees the long jump foul line you get.

I don't think this speed boost is always displayed, but it's

added into the internal speed. I've not checked to see if

something similar happens for javalin or high jump.

Q: Does clicking the buttons after a jump make any difference?

A: Yes, in more events than I was expecting.

It's not much but we'll take what we can get. It's plus

a half a cm/sec per valid click on both long jump and javalin

flights. Although the long jump code checks for the buttons

being pressed they make no difference to the distance.

That is +0001 every 2 valid clicks.

What was more surprising was the +0001 every 3 valid clicks

during the hammer spin-up (I've not found any "lift" code for hammer

flight let). I wonder if a burst of speed during the hammer

spin might allow a more controlled release at a higher speed.

The hammer spin speed drops periodically if it overflows so

a speed boost during a spin may allow a better release just

before an overflow.

Battlezone2016-08-16 09:28:21
 

tronads

Active member
Feedback
5 (100%)
Credits
454CR
cmonkey said:
Do you have any kind of proof that the first throw on the javelin is always less distance than the second/third throws if the speed/angle are the same on all 3 throws?

I don't have any "proof" on this, its just something any advanced player will know, I am sure Jon will back me up on it. The first Javelin throw is always much lower than the following 2. Once respectable records are set, it was always impossible to get on on that first throw.

Back in the day T&F was a game I used to be able to play all day on one credit, but it was one we used to play as a pair, so one person would run, and the other would jump....but as I have said to Jon in the past, although the scores and speeds we used to achieve in the past were very good, playing on your own is a completely different kettle of fish.

I'm completely screwed when it comes to the hurdles on my own with no-one there to jump for me :)

I'm loving all these code breakdowns, thanks for taking the time to disect, its fascinating reading.
 

Pacman83

The Pac-Master
vacBacker
Credits
212CR
No question. On the Javelin, you'll never get a WR throw on your first attempt. I've run 1450 speed with a 43° angle and rarely get 93m. Then on the second throw, same speed, over 96m.
I echo the comments from above. Incredible work on this guys ??
 

cmonkey

Active member
vacBacker
Feedback
4 (100%)
Credits
1,659CR
Pacman83 said:
No question. On the Javelin, you'll never get a WR throw on your first attempt. I've run 1450 speed with a 43° angle and rarely get 93m. Then on the second throw, same speed, over 96m.
I echo the comments from above. Incredible work on this guys ??

OK, I should know better than to doubt such gaming heroes as Jon and Dave....

So it does indeed seem like there's some mileage in this. I can now break into the game at the point where you've released the javelin and set my own speed and angle for the throw. This allows me to simulate identical throws every time.

I've done 10 sample runs where I throw the javelin directly from the start position and, although the results are not conclusive at this time, it does seem that the first throw is never quite as good as the second and third throws.

I'd like a volunteer to repeat these tests, if possible (probably Eric, if he's not too busy!)

Using the MAME rom set trackfld set a breakpoint in the debugger when you launch the game, as follows :-

bp e8b3,1,{d@28b0=01040500;b@28d8=2b;g}

Then start a new game, complete the 100m race and long jump and then take a snapshot at the start of the javelin event (shift F7). This will allow you to rollback to the start of the javelin event quickly after 3 throws. If you can't be bothered to do the 100m race and long jump then set the value of memory location $2884 to 2 during the initial entry process, this will start the game directly on the javelin event.

Once you're in the javelin event do a very quick tap on one of the run buttons (you can't throw the javelin until you've tapped at least one run button) and then a very quick tap on the throw button.

At that point the MAME debugger will set the speed of the throw to 1450cm/sec and the angle to 43 degrees and commence the throw.

In theory all 3 throws should be identical, as they're all initiating from exactly the same start point, using the same speed and same throw angle. However in reality, as you'll see from the pics below, that's not the case.

I'm pretty sure that there's a random number being thrown into the mix somewhere, maybe they did it to simulate the effects of wind during the throw. Who knows?

I'll probably continue looking for the cause of this, if not to satisfy my own curiosity.

tnf_1.png


tnf_2.png


tnf_3.png


tnf_4.png


tnf_5.png


tnf_6.png


tnf_7.png


tnf_8.png


tnf_9.png


tnf_10.png


cmonkey2016-07-31 21:37:30
 

Hurray Banana

Moderator
Staff member
vacBacker
Feedback
8 (100%)
Credits
2,756CR
Done one, was having trouble until I realised the angle release address should be $28d8 (not 28db)

here's one about to run a few more

run 1

1) 49.47

2) +2.17 (diff +4.4%)

3) +2.17 (diff +4.4%)

run0001.png


Hurray Banana2016-07-31 20:47:18
 

Shekel

Newbie
Credits
5CR
I was listening to the postcast mentioned at the start of the thread, just for the Track and Field interview.

The guy mentioned someone who had beaten Hector's score and said there was some controversy about it. Does anyone know his name of have Twin Galaxies links? Their site is quite bad for finding anything.
 

Hurray Banana

Moderator
Staff member
vacBacker
Feedback
8 (100%)
Credits
2,756CR
more runs
run 2

1) 51.84

2) -1.60 ?? (diff - 3.1%)

3) +1.40 (diff +2.7%)

run0002.png


run 3

1) 49.85

2) +2.56 (diff +5.1%)

3) +2.37 (diff + 4.8%)

run0003.png


run 4

1) 49.47

2) +1.53 (diff +3.1%)

3) +0.57 (diff + 1.1%)

run0004.png


run 5

1) 49.85

2) +2.37 (diff +4.85)

3) +3.20 (diff +6.4%)

run0005.png


run 6

1) 50.24

2) +1.02 (diff +2.0%)

3) +4.35 (diff + 8.7%)

run0006.png


Some interesting results ranging up to nearly 9% larger than first throw. There is definitely some random there and it does look skewed towards the final throw
 

Hurray Banana

Moderator
Staff member
vacBacker
Feedback
8 (100%)
Credits
2,756CR
more runs
run 7

1) 47.48

2) +3.52 (diff +7.4%)

3) +1.99 (diff +4.2%)

run0007.png


run 8

1) 50.43

2) -1.79 (diff - 3.5%)

3) +1.79 (diff +3.5%) - spooky

run0008.png


run 9

1) 51.84

2) +0.19 (diff + 0.4%)

3) -0.39 (diff -0.8%)

run0009.png


run A

1) 49.47

2) +2.37 (diff + 4.8%)

3) +0.57 (diff +1.2%)

run000a.png
 

cmonkey

Active member
vacBacker
Feedback
4 (100%)
Credits
1,659CR
My apologies for giving the wrong address for the angle Eric, the old eyes ain't as good as they used to be.
smiley6.gif
I've updated the post with the correct address.

Thanks very much for doing the testing. It definitely does look like the game engine is favouring the 2nd and 3rd throws. Need to find the PRNG and see if it's being called during the throw state of the javelin state machine. I'm pretty sure that there's some randomness in this.
 

tronads

Active member
Feedback
5 (100%)
Credits
454CR
I always thought it was a bit weird that they would intentionally weaken the 1st throw, but not do something similar on the long jump and the hammer....kind of led me to believe all these years that it might be a bug.
 

Hurray Banana

Moderator
Staff member
vacBacker
Feedback
8 (100%)
Credits
2,756CR
cmonkey said:
My apologies for giving the wrong address for the angle Eric, the old eyes ain't as good as they used to be.
smiley6.gif
I've updated the post with the correct address.

Thanks very much for doing the testing. It definitely does look like the game engine is favouring the 2nd and 3rd throws. Need to find the PRNG and see if it's being called during the throw state of the javelin state machine. I'm pretty sure that there's some randomness in this.

No worries Ade, easy mistake that one. I wish I had time to look into this. Got to get a better work life balance going.
 

CharlieFar

Active member
Feedback
1 (100%)
Credits
51CR
Wow! Great work on deciphering the code.

(Cheeky aside - If any of you should wander into the Galaxian code by accident in the future, I'd personally love to know what flag the difficulty maxes out. It's the question I get asked the most when I play).
 
Top