Skip to content

Commit

Permalink
Merge pull request google-deepmind#996 from rezunli96:dou_dizhu
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 503138174
Change-Id: Id9fbd614f2c981d1e8abed0d50205ebd71452c3b
  • Loading branch information
lanctot committed Jan 23, 2023
2 parents de05f32 + 4f890d8 commit afe484c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 56 deletions.
6 changes: 4 additions & 2 deletions open_spiel/games/dou_dizhu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ DouDizhuState::DouDizhuState(std::shared_ptr<const Game> game) : State(game) {
}

std::string DouDizhuState::ActionToString(Player player, Action action) const {
if (action < kBiddingActionBase) {
return RankString(CardToRank(action));
if (action < kDealingActionBase) {
return absl::StrFormat("Decide first card up position %d", action);
} else if (action < kBiddingActionBase) {
return absl::StrFormat("Deal %s", CardString(action-kDealingActionBase));
} else if (action == kPass) {
return "Pass";
} else if (action > kPass && action < kPlayActionBase) {
Expand Down
19 changes: 19 additions & 0 deletions open_spiel/games/dou_dizhu/dou_dizhu_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ int CardToRank(int card) {
return card % (kNumRanks - 2);
}

int CardToSuit(int card) {
if (card == kNumCards - 2 || card == kNumCards - 1) {
SpielFatalError("No Suit defined for Jokers");
}
return card / (kNumRanks - 2);
}

std::string RankString(int rank) {
if (rank < kNumRanks - 2)
return std::string(1, kRankChar[rank]);
Expand All @@ -38,6 +45,18 @@ std::string RankString(int rank) {
SpielFatalError("Non valid rank");
}

std::string CardString(int card) {
int rank = CardToRank(card);
if (rank >= kNumRanks - 2) {
return RankString(rank);
} else {
int suit = CardToSuit(card);
SPIEL_CHECK_GE(suit, 0);
SPIEL_CHECK_LT(suit, kNumSuits);
return absl::StrFormat("%c%c", kSuitChar[suit], kRankChar[rank]);
}
}

std::string FormatSingleHand(absl::Span<const int> hand) {
std::string hand_format;
for (int rank = 0; rank < kNumRanks; ++rank) {
Expand Down
3 changes: 3 additions & 0 deletions open_spiel/games/dou_dizhu/dou_dizhu_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ inline constexpr int kNumKickersAirplanePairCombChainOfLengthThree = 120;
inline constexpr int kNumKickersAirplanePairCombChainOfLengthFour = 126;

constexpr char kRankChar[] = "3456789TJQKA2";
// only for dealing phase usages
constexpr char kSuitChar[] = "CDHS";

enum KickerType { kSolo = 1, kPair };

Expand Down Expand Up @@ -137,6 +139,7 @@ struct TrioCombParams {

int CardToRank(int card);
std::string RankString(int rank);
std::string CardString(int card);
std::string FormatSingleHand(absl::Span<const int> hand);
std::string FormatAirplaneCombHand(int action);

Expand Down
108 changes: 54 additions & 54 deletions open_spiel/integration_tests/playthroughs/dou_dizhu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ ObservationTensor(1): ◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯
ObservationTensor(2): ◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯
ChanceOutcomes() = [(0, 0.0196078431372549), (1, 0.0196078431372549), (2, 0.0196078431372549), (3, 0.0196078431372549), (4, 0.0196078431372549), (5, 0.0196078431372549), (6, 0.0196078431372549), (7, 0.0196078431372549), (8, 0.0196078431372549), (9, 0.0196078431372549), (10, 0.0196078431372549), (11, 0.0196078431372549), (12, 0.0196078431372549), (13, 0.0196078431372549), (14, 0.0196078431372549), (15, 0.0196078431372549), (16, 0.0196078431372549), (17, 0.0196078431372549), (18, 0.0196078431372549), (19, 0.0196078431372549), (20, 0.0196078431372549), (21, 0.0196078431372549), (22, 0.0196078431372549), (23, 0.0196078431372549), (24, 0.0196078431372549), (25, 0.0196078431372549), (26, 0.0196078431372549), (27, 0.0196078431372549), (28, 0.0196078431372549), (29, 0.0196078431372549), (30, 0.0196078431372549), (31, 0.0196078431372549), (32, 0.0196078431372549), (33, 0.0196078431372549), (34, 0.0196078431372549), (35, 0.0196078431372549), (36, 0.0196078431372549), (37, 0.0196078431372549), (38, 0.0196078431372549), (39, 0.0196078431372549), (40, 0.0196078431372549), (41, 0.0196078431372549), (42, 0.0196078431372549), (43, 0.0196078431372549), (44, 0.0196078431372549), (45, 0.0196078431372549), (46, 0.0196078431372549), (47, 0.0196078431372549), (48, 0.0196078431372549), (49, 0.0196078431372549), (50, 0.0196078431372549)]
LegalActions() = [0, 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]
StringLegalActions() = ["3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"]
StringLegalActions() = ["Decide first card up position 0", "Decide first card up position 1", "Decide first card up position 2", "Decide first card up position 3", "Decide first card up position 4", "Decide first card up position 5", "Decide first card up position 6", "Decide first card up position 7", "Decide first card up position 8", "Decide first card up position 9", "Decide first card up position 10", "Decide first card up position 11", "Decide first card up position 12", "Decide first card up position 13", "Decide first card up position 14", "Decide first card up position 15", "Decide first card up position 16", "Decide first card up position 17", "Decide first card up position 18", "Decide first card up position 19", "Decide first card up position 20", "Decide first card up position 21", "Decide first card up position 22", "Decide first card up position 23", "Decide first card up position 24", "Decide first card up position 25", "Decide first card up position 26", "Decide first card up position 27", "Decide first card up position 28", "Decide first card up position 29", "Decide first card up position 30", "Decide first card up position 31", "Decide first card up position 32", "Decide first card up position 33", "Decide first card up position 34", "Decide first card up position 35", "Decide first card up position 36", "Decide first card up position 37", "Decide first card up position 38", "Decide first card up position 39", "Decide first card up position 40", "Decide first card up position 41", "Decide first card up position 42", "Decide first card up position 43", "Decide first card up position 44", "Decide first card up position 45", "Decide first card up position 46", "Decide first card up position 47", "Decide first card up position 48", "Decide first card up position 49", "Decide first card up position 50"]

# Apply action "8"
# Apply action "Decide first card up position 5"
action: 5

# State 1
Expand Down Expand Up @@ -125,209 +125,209 @@ ObservationTensor(1): ◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯
ObservationTensor(2): ◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯
ChanceOutcomes() = [(51, 0.018518518518518517), (52, 0.018518518518518517), (53, 0.018518518518518517), (54, 0.018518518518518517), (55, 0.018518518518518517), (56, 0.018518518518518517), (57, 0.018518518518518517), (58, 0.018518518518518517), (59, 0.018518518518518517), (60, 0.018518518518518517), (61, 0.018518518518518517), (62, 0.018518518518518517), (63, 0.018518518518518517), (64, 0.018518518518518517), (65, 0.018518518518518517), (66, 0.018518518518518517), (67, 0.018518518518518517), (68, 0.018518518518518517), (69, 0.018518518518518517), (70, 0.018518518518518517), (71, 0.018518518518518517), (72, 0.018518518518518517), (73, 0.018518518518518517), (74, 0.018518518518518517), (75, 0.018518518518518517), (76, 0.018518518518518517), (77, 0.018518518518518517), (78, 0.018518518518518517), (79, 0.018518518518518517), (80, 0.018518518518518517), (81, 0.018518518518518517), (82, 0.018518518518518517), (83, 0.018518518518518517), (84, 0.018518518518518517), (85, 0.018518518518518517), (86, 0.018518518518518517), (87, 0.018518518518518517), (88, 0.018518518518518517), (89, 0.018518518518518517), (90, 0.018518518518518517), (91, 0.018518518518518517), (92, 0.018518518518518517), (93, 0.018518518518518517), (94, 0.018518518518518517), (95, 0.018518518518518517), (96, 0.018518518518518517), (97, 0.018518518518518517), (98, 0.018518518518518517), (99, 0.018518518518518517), (100, 0.018518518518518517), (101, 0.018518518518518517), (102, 0.018518518518518517), (103, 0.018518518518518517), (104, 0.018518518518518517)]
LegalActions() = [51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104]
StringLegalActions() = ["2", "(BWJ)", "(CJ)", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A", "2", "3"]
StringLegalActions() = ["Deal C3", "Deal C4", "Deal C5", "Deal C6", "Deal C7", "Deal C8", "Deal C9", "Deal CT", "Deal CJ", "Deal CQ", "Deal CK", "Deal CA", "Deal C2", "Deal D3", "Deal D4", "Deal D5", "Deal D6", "Deal D7", "Deal D8", "Deal D9", "Deal DT", "Deal DJ", "Deal DQ", "Deal DK", "Deal DA", "Deal D2", "Deal H3", "Deal H4", "Deal H5", "Deal H6", "Deal H7", "Deal H8", "Deal H9", "Deal HT", "Deal HJ", "Deal HQ", "Deal HK", "Deal HA", "Deal H2", "Deal S3", "Deal S4", "Deal S5", "Deal S6", "Deal S7", "Deal S8", "Deal S9", "Deal ST", "Deal SJ", "Deal SQ", "Deal SK", "Deal SA", "Deal S2", "Deal (BWJ)", "Deal (CJ)"]

# Apply action "3"
# Apply action "Deal D4"
action: 65

# State 2
# Apply action "4"
# Apply action "Deal H5"
action: 79

# State 3
# Apply action "8"
# Apply action "Deal S9"
action: 96

# State 4
# Apply action "8"
# Apply action "Deal H9"
action: 83

# State 5
# Apply action "6"
# Apply action "Deal H7"
action: 81

# State 6
# Apply action "A"
# Apply action "Deal H2"
action: 89

# State 7
# Apply action "Q"
# Apply action "Deal HK"
action: 87

# State 8
# Apply action "3"
# Apply action "Deal (CJ)"
action: 104

# State 9
# Apply action "T"
# Apply action "Deal CJ"
action: 59

# State 10
# Apply action "Q"
# Apply action "Deal CK"
action: 61

# State 11
# Apply action "7"
# Apply action "Deal D8"
action: 69

# State 12
# Apply action "8"
# Apply action "Deal D9"
action: 70

# State 13
# Apply action "8"
# Apply action "Deal C9"
action: 57

# State 14
# Apply action "5"
# Apply action "Deal H6"
action: 80

# State 15
# Apply action "J"
# Apply action "Deal CQ"
action: 60

# State 16
# Apply action "5"
# Apply action "Deal D6"
action: 67

# State 17
# Apply action "T"
# Apply action "Deal DJ"
action: 72

# State 18
# Apply action "2"
# Apply action "Deal C3"
action: 51

# State 19
# Apply action "3"
# Apply action "Deal S4"
action: 91

# State 20
# Apply action "T"
# Apply action "Deal SJ"
action: 98

# State 21
# Apply action "9"
# Apply action "Deal CT"
action: 58

# State 22
# Apply action "2"
# Apply action "Deal D3"
action: 64

# State 23
# Apply action "A"
# Apply action "Deal C2"
action: 63

# State 24
# Apply action "Q"
# Apply action "Deal SK"
action: 100

# State 25
# Apply action "2"
# Apply action "Deal (BWJ)"
action: 103

# State 26
# Apply action "3"
# Apply action "Deal H4"
action: 78

# State 27
# Apply action "6"
# Apply action "Deal C7"
action: 55

# State 28
# Apply action "9"
# Apply action "Deal ST"
action: 97

# State 29
# Apply action "2"
# Apply action "Deal S3"
action: 90

# State 30
# Apply action "(BWJ)"
# Apply action "Deal C4"
action: 52

# State 31
# Apply action "K"
# Apply action "Deal SA"
action: 101

# State 32
# Apply action "4"
# Apply action "Deal S5"
action: 92

# State 33
# Apply action "4"
# Apply action "Deal D5"
action: 66

# State 34
# Apply action "T"
# Apply action "Deal HJ"
action: 85

# State 35
# Apply action "K"
# Apply action "Deal HA"
action: 88

# State 36
# Apply action "5"
# Apply action "Deal C6"
action: 54

# State 37
# Apply action "5"
# Apply action "Deal S6"
action: 93

# State 38
# Apply action "(CJ)"
# Apply action "Deal C5"
action: 53

# State 39
# Apply action "7"
# Apply action "Deal S8"
action: 95

# State 40
# Apply action "7"
# Apply action "Deal H8"
action: 82

# State 41
# Apply action "K"
# Apply action "Deal DA"
action: 75

# State 42
# Apply action "A"
# Apply action "Deal S2"
action: 102

# State 43
# Apply action "J"
# Apply action "Deal HQ"
action: 86

# State 44
# Apply action "Q"
# Apply action "Deal DK"
action: 74

# State 45
# Apply action "7"
# Apply action "Deal C8"
action: 56

# State 46
# Apply action "9"
# Apply action "Deal HT"
action: 84

# State 47
# Apply action "6"
# Apply action "Deal D7"
action: 68

# State 48
# Apply action "J"
# Apply action "Deal SQ"
action: 99

# State 49
# Apply action "K"
# Apply action "Deal CA"
action: 62

# State 50
# Apply action "A"
# Apply action "Deal D2"
action: 76

# State 51
# Apply action "J"
# Apply action "Deal DQ"
action: 73

# State 52
Expand Down

0 comments on commit afe484c

Please sign in to comment.