Blog/2025-01-05/Mahjong Spreadsheets: Difference between revisions

From Rest of What I Know
No edit summary
m Roshan moved page Blog/2024-01-05/Mahjong Spreadsheets to Blog/2025-01-05/Mahjong Spreadsheets: Misspelled title: Wrong date
 
(One intermediate revision by the same user not shown)
Line 9: Line 9:
You can see the schema in the screenshot. The only thing that matters is the formulae in the cells:
You can see the schema in the screenshot. The only thing that matters is the formulae in the cells:


<syntaxhighlight lang="excel">
<syntaxhighlight lang="text">
=IF($G4=0, 0, IF($F4=B$1, IF($H4="All", ($G4+8)*3, $G4+3*8), IF(OR($H4=B$1, AND($H4="All", $F4<>B$1)), -$G4-8, -8)))
=IF($G4=0, 0, IF($F4=B$1, IF($H4="All", ($G4+8)*3, $G4+3*8), IF(OR($H4=B$1, AND($H4="All", $F4<>B$1)), -$G4-8, -8)))
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 05:46, 6 January 2025

As you can see, I'm not doing too well on this particular game. It's still only East Wind prevalent, though. Lots of time. Lots of time.

My friends and I play Mahjong quite often. We use these rules for scoring but the annoying part with using chips is that you always have to do the math and pass them around and avoid knocking them and stuff like that. And the worst of all is that you have to somehow retain state because games of mahjong can go on forever and we can usually only find an hour at a time to play. This seemed like a good opportunity to use an LLM to generate some useful spreadsheet so we can just use Google Sheets to write everything.

This would seem like the perfect opportunity for Gemini to shine, considering it's literally their LLM in their spreadsheet app, but unfortunately for me Google doesn't quite have the story together. You can't ask Gemini to add a column or a row. You can't ask it to generate a formula for a cell in the sheet it's looking at. It really can't do anything.

In the end, I used Claude and then wrote a bug in the code anyway. It is now fixed, so I'll explain it simply in case anyone else wants a quick way to do it. It's not complicated.

You can see the schema in the screenshot. The only thing that matters is the formulae in the cells:

=IF($G4=0, 0, IF($F4=B$1, IF($H4="All", ($G4+8)*3, $G4+3*8), IF(OR($H4=B$1, AND($H4="All", $F4<>B$1)), -$G4-8, -8)))

With Google Sheets's new "Tables" feature you can easily set drop-downs on various columns (which I have set to their names). Then we just select a Winner, a Loser, and type in the score and the annoying bookkeeping is recorded here.