Crazy Eights
Statement
Goal
The goal is to assess if we can win and endgame of Crazy Eights assuming both players play perfectly. The complete rules of the game can be found here*, but simplified:(1) First player to discard all their cards win.
(2) Players are forced to play a card if they can.
(3) At every time, there is a current card at play. The current player can choose a card that either matches the rank or the suit of the current card. The only exception being eights, that can be played at any time and allow the current player to choose the suit to play next. The played card becomes then the current card for the next player.
Now, some extra conditions to our case:
(1) There are only two players: player 1 and player 2.
(2) We are player 1 and we always start the game.
(3) All cards have been drawn so a player either plays a card or passes.
(4) Both players know the cards of their opponent.
*
Input
Line 1: A string current for the current card at play.
Line 2: A space separated string player1 for the cards of player1.
Line 3: A space separated string player2 for the cards of player2.
Line 2: A space separated string player1 for the cards of player1.
Line 3: A space separated string player2 for the cards of player2.
Output
Constraints
Every card is unique.
1 < Total number of cards <= 15
Example
Input
5C 2S 5S TS 3C JD
Output
true
Tags
Simulation, Minimax, Card games
Difficulty
Medium
Test cases
Basic Test
Input
5C
2S 5S TS
3C JD
Output
true
Validator 1 Validator
Input
5C
2S 5S TS
3C JD
Output
true
We start with player one Test
Input
QC
QS
QD
Output
true
Validator 2 Validator
Input
QC
QS
QD
Output
true
4. Just lose Test
Input
2C
3C 4C
3S 4S KS
Output
false
Validator 3 Validator
Input
2C
3C 4C
3S 4S KS
Output
false
4. Just lose (2) Test
Input
AC
KH 7D 2D
3D 2C
Output
false
Validator 4 Validator
Input
AC
KH 7D 2D
3D 2C
Output
false
5. Decisions (2) Test
Input
2C
3C 4C
3S KS
Output
true
Validator 5 Validator
Input
2C
3C 4C
3S KS
Output
true
6. Eights Test
Input
2C
8H 2S
2D
Output
true
Only need to simul 1 eight Validator
Input
2C
8H 8D 2S
2D
Output
true
7. Eights (2) Test
Input
2C
8H 3S
2S 4S
Output
true
Validator 7 Validator
Input
2C
8H 3S
2S 4S
Output
true
7. Random 1 Test
Input
7S
9D 8H QS 6D 7H
6H 2D 9S QC 5S
Output
true
Validator 8 Validator
Input
KS
7D 4H 2C JH 8S
TH 9H 5H 8D 4D
Output
false
8. Random 2 Test
Input
8S
KC 5S QS 2S 7D
2D QD 3S 7S 9D
Output
false
Validator 9 Validator
Input
5C
TH 7C JC KC 5S
7S JH 9C 4H 7H
Output
false
9. HardEST random Test
Input
QD
5S 9H 4H 7D JH 6S QH 8D
2C 8S 6H AD TH AH 7H
Output
false
Validator 10 Validator
Input
7S
9H AD 5S TD 2H JH 7H KH
QC TC 9C TS KC TH AC JC
Output
false
10. Hard random (2) Test
Input
JD
9D 8S 2D 3C 2C 9S AC 7S
3D 2S AS 7C KC TD 4D 6S
Output
true
Validator 11 Validator
Input
QC
8D QH 2D 6S 9D 5C 3D 4D
7C 6H 6C 8C 3H 5D 7H 9H
Output
false
Tricky eight (don't pass) Test
Input
2C
8D 5H
4H 3C 4C
Output
true
Validator 12 Validator
Input
2C
8S 5H 9H
4C 5C 6C 7C
Output
true
Best opponent Test
Input
9H
7D 6D
6H 4H
Output
false
Validator 13 Validator
Input
9H
7D 6D
6H 4H
Output
false
Important test Test
Input
6C
8D 6H 5S
3H KH 8H
Output
false
Validator 14 Validator
Input
6C
8D 6H 5S
3H KH 8H
Output
false
Crazy Eights Test
Input
3C
2S JC 6S QH 2C KD JD
8S 7S KC 7C 8D TC 8C
Output
false
Validator 15 Validator
Input
3C
2S JC 6S QH 2C KD JD
8S 7S KC 7C 8D TC 8C
Output
false
Solution language
Solution
Stub generator input