Python 2, 47 bytes
lambda a,b:[61>60-a>b<3+max(19,a)for b in-~b,b]
Outputs a list of two Booleans. Thanks to TFeld for writing a test suite in their answer that made it easy to check my solution.
ended: [False, True]
going: [True, True]
invalid: [False, False]
The key insight is that a valid score ends the game exactly if increasing the higher value b
makes the score invalid. So, we just code up the validity condition, and check it for (a,b+1)
in addition to (a,b)
to see if the game has ended.
Validity is checked via three conditions that are chained together:
b<3+max(19,a)
: Checks that the higher scoreb
isn't past winning, with eitherb<=21
orb<=a+2
(win by two)60-a>b
: Equivalent toa+b<=59
, ensuring the score isn't above(29,30)
61>60-a
: Equivalent toa>=0
, ensures the lower score is non-negative
Python 2, 44 bytes
lambda a,b:a<0 or cmp(b,2+max(19,a)%30-a/29)
Outputs:
ended: 0
going: -1
invalid: 1 (including True)