Horse racing

From Rosetta Code
Revision as of 11:52, 14 August 2021 by PureFox (talk | contribs) (Minor tweaks.)
Horse racing is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Background

In three recent races at Rosetta Park, the results have been:

Race 1

Pos Horse Weight Dist Sex
1 A 9.00 0.0 Colt
2 B 8.06 2.0 Filly
3 C 9.04 1.5 Colt

Time 1 minute 36.0 seconds


Race 2

Pos Horse Weight Dist Sex
1 D 8.10 0.0 Filly
2 E 9.03 1.0 Colt
3 F 9.07 3.0 Colt

(F was slowly away and lost 2 lengths at the finish as a result)

Time 1 minute 36.4 seconds


Race 3

Pos Horse Weight Dist Sex
1 G 8.04 0.0 Colt
2 H 8.10 1.5 Colt
3 I 9.05 0.5 Filly

Time 1 minute 35.8 seconds


It is assumed that:

1. Weights carried are expressed in stones and pounds (traditional in US and UK racing) where 1 stone equals 14 pounds.

2. The distances are the actual distances between horses at the finish of the race.

3. All races are run at 1 mile in similar going and weather conditions and the time shown is the time taken by the winner to run the race.

4. 2 pounds slows a horse down by 1 length at the finish.

5. 1 second is equivalent to 5 lengths at the finish.


Task

All 9 of these horses, plus a further horse J, are due to compete against each other in Race 4 at Rosetta Park again over 1 mile and in similar conditions to the earlier races. Colts will carry 9.00 and fillies 8.11.

Suppose that:

1. Horse B has been moving well on the galops and her trainer thinks she has improved 4 pounds since her last outing.

2. Horse C has had a setback in training and his trainer expects him to perform 4 pounds below his best.

3. Horse H is being ridden by the champion jockey which is expected to improve his performance by 3 pounds compared to what it would otherwise have been.

4. Horse J, a filly, has never run before but her performance on the galops suggests she can run 1 mile in 1 minute 35.8 seconds when carrying 8.11.


Other things being equal (which they seldom are in actual horse racing!) what would you expect the full result of Race 4 to be including the time of the winner?

Wren

Library: Wren-fmt

<lang ecmascript>import "/fmt" for Fmt

// ratings on past form, assuming a rating of 100 for horse A var a = 100 var b = a - 8 - 2 * 2 // carried 8 lbs less, finished 2 lengths behind var c = a + 4 - 2 * 3.5 var d = a - 4 - 10 * 0.4 // based on relative weight and time var e = d + 7 - 2 * 1 var f = d + 11 - 2 * (4 - 2) var g = a - 10 + 10 * 0.2 var h = g + 6 - 2 * 1.5 var i = g + 15 - 2 * 2

// adjustments to ratings for current race b = b + 4 c = c - 4 h = h + 3 var j = a - 3 + 10 * 0.2

// filly's allowance to give weight adjusted weighting b = b + 3 d = d + 3 i = i + 3 j = j + 3

// create map of horse to its weight adjusted rating and whether colt var m = {

   "A": [a, true], 
   "B": [b, false], 
   "C": [c, true],
   "D": [d, false],
   "E": [e, true],
   "F": [f, true],
   "G": [g, true],
   "H": [h, true],
   "I": [i, false],
   "J": [j, false]

} // convert to list of {key, value} map entries var l = m.toList

// sort in descending order of rating l.sort{ |i, j| i.value[0] >= j.value[0] }

// show expected result of race System.print("Race 4\n") System.print("Pos Horse Weight Dist Sex") var p = 1 for (x in 0...l.count) {

   var wt = l[x].value[1] ? "9.00" : "8.11"
   var dist = 0
   if (p > 1) dist = (l[x-1].value[0] - l[x].value[0]) * 0.5
   var pos = (p == 1 || dist > 0) ? p.toString : (p - 1).toString + "="
   var sx = l[x].value[1] ? "colt" : "filly"
   Fmt.print("$-2s  $s      $s    $3.1f   $s", pos, l[x].key, wt, dist, sx)
   p = p + 1

}

// weight adjusted rating of winner var wr = l[0].value[0]

// expected time of winner (relative to A's time in Race 1) var t = 96 - (wr - 100) / 10 var min = (t/60).floor var sec = t % 60 System.print("\nTime %(min) minute %(sec) seconds")</lang>

Output:
Race 4

Pos Horse  Weight  Dist  Sex
1   I      8.11    0.0   filly
2   J      8.11    2.0   filly
3   A      9.00    1.0   colt
4   F      9.00    0.5   colt
5   H      9.00    0.5   colt
6   E      9.00    0.5   colt
7   B      8.11    1.0   filly
7=  D      8.11    0.0   filly
9   C      9.00    1.0   colt
10  G      9.00    0.5   colt

Time 1 minute 35.4 seconds