-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtask.txt
More file actions
51 lines (51 loc) · 2.36 KB
/
Copy pathtask.txt
File metadata and controls
51 lines (51 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* ## Stupid ##
*
* There's a Lithuanian/Russian card game called 'Stupid'.
*
* It has these (simplified) rules:
*
* Suites in ascending order: Hearts, Diamonds, Clubs, Spades.
* Card ranks in ascending order: 2, 3, 4, 5, 6, 7, 8, 9, T, Jack, Queen, King, Ace.
*
* Cards are ordered by their rank and then their suite.
*
* One suite is called the trump suite. Any trump card is always higher than
* any non-trump card.
*
* The trump suite is represented as the first line in data file by a letter:
* H|D|C|S.
*
* Two players get their cards which are represented by a line in the file:
* ST D2 CJ HQ DA | H2 D3 C4 S5 H6 D7 C8 S9
*
* First player starts as offense. Offense always starts.
*
* 1) He plays smallest non-trump card. If he does not have non-trump card,
* he plays smallest trump card then.
* 2) If defense has cards of the same rank, he plays smallest of them
* and passes the turn to offense. This can only be done if offense has enough
* cards to defend all of them. Roles of the attacker/defender switch then.
* 3) Whenever there is no card to be passed, defender must use
* smallest non-trump cards that are bigger than the each card on the table
* to cover them, starting with the smallest uncovered cards currently on
* table. Each card that is being used to cover a card needs to be of the same suite as
* the card that is being covered. If he doesn't have a non-trump card to cover any card, he
* can use a trump card to do that. If he doesn't have any card to cover current
* card, he shouldn't play any more cards in this turn.
* 4) Attacker then can add more cards that are of the same rank that
* currently exist on the table for defender to current. Maximum number of
* non-covered cards on the table cannot exceed defenders current hand size.
* If such scenario arises, attacker then plays the smallest card from their
* hand.
* 5a) If all cards are covered - defender wins this round, cards are
* discarded and defense becomes offense for the next turn.
* 5b) If not all cards are covered - go to 3). If defender can't cover all cards
* it loses the round and takes all cards to his hand. It's offense turn.
*
* Repeat this until one player does not have cards in his hand after a turn.
* That player wins.
*
* For each given line, print 0 if there is a tie (both players have no cards
* in their hands), 1 if p1 wins, 2 if p2 wins.
*/