This is a simple card game in form of interactive problems - hopefully you already solved some of them.
As the problem is based upon a game with some randomness and "imperfect information", you may need to retry a few times even with "potentially winning" strategy. Many thanks to Clive Fraser for help in improving these aspects.
Two players use a deck of 36
cards, arranged in 4
suits (WXYZ
) and 9
ranks (012345678
). Both sets
of symbols are slightly uncommon, but "consecutive" in the sense of ASCII, which may simplify coding.
To start, each player gets a "hand" of 9
random cards, remaining 18
are left in a single pack on a table,
their backs up. One of the suits is chosen trump
, except the case when no-trump
game is played.
Game is played in rounds, in which one player chooses a card to attack and the other chooses a card to defend (both from their respecitve "hand"). If the defender's card is of same suit, but higher rank - or defender's card is of a trump suit while attacker's is not - in both such cases defender scores this "trick". Otherwise it is scored to attacker.
Additional rule is that defender should "follow suit" of attacker - i.e. respond with the same-suit card if possible. However in the absense of the suitable suit playing with trump is not obligatory.
After each round two cards are dealt from the pack on the table, if it is not exhausted yet. So players keep
the hand of 9
cards during first 10
rounds, while remaining 8
rounds are played with steadily decreasing
hand.
First to attack is chosen randomly, but after that the attacker is always those who have won the previous trick.
The game is won by whoever scores more tricks.
GAME-NAME is tricks
- use it in the server url given in the instruction above.
Input data gives you a token to play and answer should contain victory token returned to you by server (while the game is in test mode you'll never get it).
You are playing several simultaneous games however. They use separate decks, so they are completely independent.
Every turn server will respond you with states
variable, which contains space-separated chunks of symbols
describing latest changes in every on N
simultaneously played games.
Immediately after start there'll be also sequence of card's in your hands and trump suit separated by colon, e.g.
Z1X1Y1Z2Z0Y5W3:X - you get cards Z1,X1,Y1,Z2,Z0,Y5,W3 and X suit is trump
No-trump game is denoted by letter N
.
The game actions are denoted by the following fragments:
>
followed by card - means this card is played by your opponent+
or -
mean the outcome of defend - either you have won the trick or notThese fragments are chained in the natural order of actions in the game. Let's look at few examples:
>X6-W3>Y4
- your opponent played X6
and it was defence, since next is -
meaning you lost the trick; you
got W3
from the pack and your opponent attacks with Y4
; it's your turn to defend now>X1+Z0
- your opponent played X1
and it was defence, since next is +
meaning you won the trick;
you got Z0
from the pack and it is your turn to attack now+
- your last played card was defence and it was successful, you won the trick and you got nothing from
the pack (because it is exhausted); it is your turn to attackInitial state with description of your hand is immediately followed by >
and some card if your opponent is
the first to attack. Otherwise it is you to attack first.
Your moves are specified by move
variable in the request, containing N
cards separated by space - whatever
cards you choose to play in each of N
simultaneous games. Be careful - failure to follow suit, or naming the
card which you don't have in hand at all - both are considered grave mistakes and corresponding game is ended
immediately with all remaining tricks awarded to your opponent.
Besides token
you can specify _games
variable, integer, which defines how many simultaneous games to play,
default is 3
but you can reduce it to 1
to facilitate manual play for example.
Winning Condition
After all games have ended, your overall score is calculated as +1
for every game won and -1
for every
game lost (0
for draws). To win you need the overall score of 35
or higher. This means you'll need to
set _games
parameter to 35
at least (maximum is 200
games).
Suppose you test the game manually using curl
command line tool:
Request (with "form-data" format):
curl <server>/tricks.php -d 'token=...&_games=2'
Response:
states: Z2X0Z7W6Z1Z3W3X2W8:N Z5Y0Y5W4Z4X7Y2Y3Y7:X>Z0
scores: 0:0 0:0
Here the first of two games is no-trump, the second has X
as trumps. Also in the first you are to attack
while in the second your opponent attacks with Z0
.
Request, sending cards to play on both tables:
curl <server>/tricks.php -d 'token=...&move=W6 Z5'
Response:
states: >W4+Y1 +X6
scores: 0:1 0:1
Thus on the first table your opponent passed with W4
, you won the trick, got Y1
from pack and is expected
to attack on the next move. On the second table you won the trick (you were defending) and got X6
and also
is expected to attack.