Cheat is a card game where you're trying to get rid of your hand. A turn looks something roughly like this:
- Determine what card rank you have to play that turn. In most variants this is one rank higher than the previous turn.
- Play 1-4 cards, face down. These don't have to match the valid rank. If they don't, it's considered a cheat. At this point any player may challenge you.
- If nobody challenges you, play continues to the next player.
- If somebody challenges you and you didn't cheat, they have to take all of the played cards.
- If somebody challenges you and you did cheat, you have to take all of the played cards.
The strategy is mostly a mix of bluffing and card counting. I'm bad at math, though, so I'm going to cheat at Cheat and bring a bot with me.
Input
The input will be, in any order or format you want:
- The player's hand. If I know that they must have cards (for example, I've seen them pick them up), those will be listed in ascending order. Any unknowns will be listed afterwards as
?
. For example, if they have six cards and I know that two are 1's and one is a 4, a valid representation of the hand is114???
. ?'s will always be listed after known cards.141???
and11???4
are both invalid inputs and your code doesn't need to handle them. - The cards I definitely know are not part of their hand (I have them, I saw someone else pick them up, etc). The list will be in ascending order of rank. The list may be empty.
- The cards the player claimed to play. If they claimed to play 3 7's, a possible input here would be
777
. The cards will always be the same rank.
The number of played cards will always be 1-4 and the ranks will always be 0-9. A rank will never appear more than four times in their hand + not their hand.
This is an example valid input:
33577??
01555688
55
This is an example invalid input:
35377?? # Out of order
7779 # Five 7's in total
23 # Two separate ranks played
Output
A truthy value if we should definitely challenge. A falsey value if we might not want to challenge.
We always challenge if we know they cheated. We know they cheated if they played cards they couldn't possibly have:
12
3 # They don't have any 3's or ?'s
-------------
12?
33 # Fewer ?'s than played cards
-------------
123?
333
33 # Since we have three 3's they can't have two
The other time we challenge is if they play their last cards. Even if the play's legit it would end the game so we might as well challenge it.
1
1 # They'd win, so challenge anyway
More Test Cases
Truthy (should challenge)
11445678?
22
-------------
????????
4
4444
-------------
12345678
9
Falsey (should not challenge)
1?
222
2
-------------
12?
22
22
-------------
?????
1111
Scoring
Shortest code wins.