Septica is a well-known romanian trick-taking card game. The rules are as follows:
- There are 32 cards in total: 7, 8, 9, 10, 11, 12, 13, 14 (4 of each type).
- In our case, the game is played between two players: your program and the computer.
- At the beginning of the game, each player receives 4 randomly chosen cards from the deck.
- Players alternate taking turns. The computer always starts first.
- In each turn, a player chooses any card from his hand, and puts it face up on the table.
- Cutting is defined as playing a 7 or a card with the same value as the initial one.
- If a player cuts, the trick continues in the same manner, until one of the players does not cut. The last player that cut wins all cards used in the trick and leads the next trick.
- After a trick ends, both players draw cards from the deck until they have 4 cards in their hand or the deck is empty.
- When the deck contains no more cards, scores are calculated. The score of a player is defined as the total number of 10 and 14 cards he collected. The player who gets the highest score wins the game. In case of a draw, the computer loses.
Player commands
- x
- use card x
- 0
- end current trick. you can only use this command if you started the trick.
Note: After each command you should print a newline character and flush the output (using functions such as fflush(stdout) or cout.flush()).
Computer commands
At the beginning of each match, the computer prints c1 c2 c3 c4, the cards in your hand, followed by a newline.- x
- use card x
- 2 n x1 x2 … xn
- you receive cards x1 x2 … xn from the deck; computer moves next
- 3 n x1 x2 … xn
- you receive cards x1 x2 … xn from the deck; player moves next
- 4 Scomputer Splayer
- current match has ended, you get the scores
Notes
- When there are no more cards in the deck, the computer will use the commands 2 and 3, with n = 0.
- Your program will play 1000 different matches (you can use a for loop to repeat the functionality of one match, 1000 times). You need to win at least 500 of them in order to be accepted.
Sample
Computer | Player | Explanation |
---|---|---|
14 9 7 10 | Player's initial cards. | |
7 | Computer's first turn. | |
7 | Player uses card 7. | |
3 1 10 | Current trick ends. Player collects the cards. Player receives one card from the deck (10). Player moves next. | |
10 | Player uses card 10. | |
11 | Computer uses card 11. | |
0 | Player doesn't cut. Current trick ends. Player collects the cards. Player moves next. | |
3 1 9 | Player receives one card from the deck (9). | |
… | … | … |
14 | Player uses card 14. | |
14 | Computer uses card 14 (cut). | |
7 | Player uses card 7 (cut). | |
14 | Computer uses card 14 (cut). | |
0 | Player doesn't cut. Current trick ends. Computer collects cards. Computer moves next. | |
2 2 8 14 | Player receives two cards from the deck (8, 14). | |
8 | Computer uses card 8. | |
8 | Player uses card 8 (cut). | |
3 1 11 | Computer doesn't cut. Current trick ends. Player collects cards. Player receives one card from the deck (11). Player moves next. | |
… | … | … |
2 1 10 | Player receieves one card from the deck (10). Computer moves next. | |
10 | Computer uses card 10. | |
10 | Player uses card 10 (cut). | |
3 0 | Computer doesn't cut. Current trick ends. Player collects cards. Player receives no more cards, because the deck is empty. Player moves next. | |
10 | Player uses card 10. | |
13 | Computer uses card 13. | |
0 | Player doesn't cut. Current trick ends. Player collects cards. Player moves next. | |
3 0 | Player receives no more cards, because the deck is empty. | |
… | … | … |
2 0 | Player receives no more cards, because the deck is empty. Computer moves next. | |
13 | Computer uses card 13. | |
14 | Player uses card 14. | |
4 4 4 | Computer has no cards left. Player collects cards. Match has ended with score 4 - 4 (the player has won). Another match will start. | |
12 12 9 14 | Player's initial cards in the second match. | |
8 | Computer's first turn. | |
… | … | … |
The game of Septica can be broken down into two subproblems:
- finding a suitable strategy for the cases when you move first (this is also used by the computer);
- finding a suitable strategy for the cases when the opponent moves first.
There are 2 possible situations for starting a trick:
- Having at least 3 potential cuts in our set of cards (either valuable cards or 7s). In this situation, we start with a valuable card, because the chances of winning are high. Possible initial configurations (where X denotes any other card):
- 10 10 10 10
- 14 14 14 14
- 10 10 10 X
- 14 14 14 X
- 10 10 7 X
- 14 14 7 X
- 10 7 7 X
- 14 7 7 X
- 7 7 7 X
- 7 7 7 7
- Having less than 3 cuts in our set of cards. In this situation, we start with a random card, provided it is not valuable (choose anything but 7, 10, 14).
There are also 2 possible situations of responding to a trick started by the computer:
- The computer uses a valuable card (10 or 14) and we have at least 2 or 3 possible cuts in our hand. In this case, we can try to cut with a 7 or with the initial card used by the computer. If we don't have enough cuts, we use a random worthless card.
- The computer uses a worthless card. We try to cut with either a 7 or with the computer's initial card.
All the heuristics described above provide a good enough strategy for our problem. The success rate of this solution is greater than 70% on random matches.