So, I got this idea buzzing in my head about tennis scores the other day. Was watching some match, I think it involved a player named Baptiste, can’t quite recall the specifics. But it got me thinking, how do they actually keep track? It seems simple enough at first, right? 15, 30, 40, game. Easy peasy.
I figured, hey, let’s try and knock something together myself. Just a little something to follow along. Thought it’d be a quick afternoon thing.
Getting Started
First off, I just grabbed a piece of paper. Seemed logical. Player A, Player B. Started making marks. Okay, 15-0. Then 15-15. Alright, tracking okay. Then it hit 40-40. Ah, deuce. Right. So, it’s not just counting up. You gotta track this ‘advantage’ thing now. Advantage Player A. Then back to deuce. Then advantage Player B. My paper started looking like a mess real quick.
Okay, paper wasn’t cutting it. Too much erasing and scribbling. Thought maybe I could put together a simple script. Just something basic on my computer.
Trying to Code It
Fired up my editor. Decided to just use some basic stuff, nothing fancy. Started laying out the logic.
- Need points for Player A and Player B.
- Need game counts for Player A and Player B.
- Need set counts too.
Seemed straightforward. Then I got into the point logic. Okay, function to add a point. If score is less than 40, increment normally (0 to 15, 15 to 30, 30 to 40). If score is 40, check the other player’s score.
This is where it got fiddly.
If opponent is less than 40, you win the game. Easy. Reset points, add a game.
But if opponent is also 40 (deuce)? Now we need an ‘advantage’ state. Okay, added a variable for that.
If you score with advantage, you win the game.
If opponent scores when you have advantage, back to deuce.
If you score at deuce, you get advantage.
Got that part working, felt pretty good. Ran a few test cases. Looked alright. Then I remembered the games. Okay, win a game, increment game count. Simple enough.
Sets and Tie-Breaks… Oh Boy
Then came sets. Usually first to 6 games wins a set, right? But wait. You gotta win by two games. So 6-5 isn’t a set win. It goes to 7-5. Or… if it gets to 6-6? Then you have a tie-break! Jeez. Another whole set of rules.
The tie-break scoring is totally different. Just counts 1, 2, 3… First to 7 points, but again, gotta win by two. My nice clean point logic from before? Didn’t apply here. Had to write a whole separate function just for tie-breaks.
It started feeling less like a quick afternoon thing and more like proper work. You start with something simple, like tracking Baptiste’s score in a match, and suddenly you’re tangled up in all these edge cases and special rules. Deuce, advantage, win by two, tie-breaks… it keeps going.
Ended up with something that mostly works, I think. It handles the basic game, set, and even tie-breaks. But I wouldn’t exactly call it robust. Haven’t even thought about different set formats, like best of 3 vs best of 5, or those weird ‘no-ad’ scoring systems you sometimes see.
It was an interesting little exercise, though. Started out just wanting to follow a score, ended up wrestling with all the nitty-gritty details. Gives you a bit more appreciation for those electronic scoreboards, and the poor chair umpires who have to keep it all straight in their heads. Definitely not as simple as it looks watching Baptiste whack the ball back and forth.