General solution to solve different sports results in different languages
- by sq2
I currently have some code that checks if squash and tennis scores are valid, both in javascript and PHP.
This results in 4 blocks of code existing, 2 languages * 2 sports, which does not scale well should any extra sports come around, or extra languages...
How can one describe the valid scores of games via a settings/text file, so that each language can parse them and apply these rules.
I'm stumped with the strange tie break situations in tennis should it reach 6-6 in a set, and also infinite play off in the final set should it reach 2 sets all.
ie:
tennis = {
"format": [
{
"name": "sets"
"min": 3,
"max": 5,
"winby": 1
},
{
"name": "games"
"min": 6,
"max": 7,
"winby": 2
}
]
}
squash = {
"format": [
{
"name": "games"
"min": 3,
"max": 5,
"winby": 1
},
{
"name": "points"
"min": 15,
"max": 0,
"winby": 2
}
]
}