Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Duckworth Lewis Calculator for Windows Mobile

0.00/5 (No votes)
23 Jun 2009 1  
A Duckworth Lewis calculator for Windows Moblie and .NET 3.5.

Introduction

This is an interpretation of the Duckworth Lewis method of calculating rain-affected Cricket scores.

Background

The formula for this code is credited to David Holland on the Active State website: http://code.activestate.com/recipes/334728/. I have interpreted this into C# and for use in the Windows Mobile.

For some reason, the ICC will not publish the exact formula; instead they release a set of inaccurate lookup tables that do not match the actual DL targets set in First Class Cricket. For this reason, the formula here will need some tweaking as updates are made. But it is a start, and follows the principles of the DL method.

Using the code

//Array of constants

double[,] dlewisdict1 = { { 293.8, 241.93, 217.21, 173.32, 142.84, 102.94, 81.705, 
                            51.471, 26.708, 17.995 }, { 0.033468, 0.043685, 0.044921, 
                            0.059491, 0.071912, 0.10011, 0.12843, 
                            0.21507, 0.41548, 0.26668 } };

//Get the number of Wickets lost
int wicksremain = 10 - (int)InnsWicks2nd.Value;
int wicksremain2 = 10 - (int)InnsWicks1st.Value;

double w = dlewisdict1[1, wicksremain] * (double)innOvers2nd.Value;
double v = dlewisdict1[1, wicksremain] * (double)innOvers1st.Value;

double d1 = 1-System.Math.Exp(-v);
d1 = d1 * dlewisdict1[0, 0];
double d = 1-System.Math.Exp(-w);
d = d * dlewisdict1[0, wicksremain];
double x = ((d1 / 235) * 100);
double y = ((d / 235) * 100);
d = ((double)innScore1st.Value / x) * y;
d = Math.Round(d);
textBox1.Text = d.ToString();

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here