Click here to Skip to main content
15,885,767 members
Articles / Mobile Apps / Windows Mobile
Article

Duckworth Lewis Calculator for Windows Mobile

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
23 Jun 2009CPOL 36.3K   509   23   2
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

C#
//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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) TRx Studio Limited
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGood job! Pin
SergioQ26-Sep-10 13:11
SergioQ26-Sep-10 13:11 
JokeAshes Pin
GavinSV24-Jun-09 11:47
GavinSV24-Jun-09 11:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.