65.9K
CodeProject is changing. Read more.
Home

Duckworth Lewis Calculator for Windows Mobile

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Jun 23, 2009

CPOL
viewsIcon

37003

downloadIcon

510

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();