-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrule_based_defender.h
More file actions
153 lines (135 loc) · 3.23 KB
/
Copy pathrule_based_defender.h
File metadata and controls
153 lines (135 loc) · 3.23 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// Created by qzz on 2024/1/25.
//
#ifndef BRIDGE_LEARNING_PLAYCC_RULE_BASED_DEFENDER_H_
#define BRIDGE_LEARNING_PLAYCC_RULE_BASED_DEFENDER_H_
#include <functional>
#include <map>
#include "bridge_lib/bridge_state.h"
namespace ble = bridge_learning_env;
// https://www.bridgebum.com/bridge_defense.php
enum DefenderRule {
// Principles.
kRuleOf10And12,
kRuleOf11,
kThirdHandHigh,
// Opening lead.
kAceFromAceKing,
kFalsecardsOnOpeningLead,
kFourthBestLeads,
kJackDeniesTenImplies,
kJournalistLeads,
kMUD,
kRusinowLeads,
kStandardLeads,
kThirdAndFifthLeads,
kTrumpLeads,
// Discard.
kLavinthalDiscards,
kOddEvenDiscards,
kRevolvingDiscards,
// SignalType
kAttitudeSignals,
kBechgaardSignals,
kCountSignals,
kFosterEcho,
kPresentCount,
kScanianSignals,
kSequenceSignals,
kSmithEcho,
kSuitPreferenceSignals,
kTrumpEcho,
kUpsideDownCountAndAttitude,
kVinjeSignals,
// Defensive Play
kCrocodileCoup,
kDeschapellesCoup,
kEmperorsCoup,
kGrosvenorGambit,
kDuckingPlay,
kIdiotCoup,
kMerrimacCoup,
kTrumpPromotion,
kUnblockingPlay,
kUnderruff,
kUppercut
};
const std::vector<std::string> kRuleStrings = {
"Rule of 10 and 12",
"Rule of 11",
"Third Hand High",
"Ace from Ace-King",
"Falsecards on opening lead",
"Fourth-best leads",
"Jack denies, Ten implies",
"Journalist leads",
"MUD",
"Rusinow leads",
"Standard leads",
"Third and fifth leads",
"Trump leads",
"Lavinthal discards",
"Odd-even discards",
"Revolving discards",
"Attitude signals",
"Bechgaard signals",
"Count signals",
"Foster echo",
"Present count",
"Scanian signals",
"Sequence signals",
"Smith echo",
"Suit-preference signals",
"Trump echo",
"Upside-down count and attitude",
"Vinje signals",
"Crocodile Coup",
"Deschapelles Coup",
"Emperor's Coup",
"Grosvenor Gambit",
"Ducking (Hold-up) Play",
"Idiot Coup",
"Merrimac Coup",
"Trump Promotion",
"Unblocking Play",
"Underruff",
"Uppercut"
};
// enum OpeningLeadRules {};
//
// enum DiscardRules {
//
// };
//
// enum SignalType {
// };
//
// enum DefensivePlays {
//
// };
std::string DefenderRuleToString(DefenderRule defender_rule);
struct RuleResults {
// Priciples will get how many higher cards declarer holds in the suit.
int higher_cards_declarer_hold = -1;
};
using RuleFunc = std::function<RuleResults(const ble::BridgeState&)>;
class RuleRegisterer {
public:
RuleRegisterer(const std::string& rule_name,
const RuleFunc& rule_func);
static void RegisterRule(const std::string& rule_name,
const RuleFunc& rule_func);
static RuleFunc GetByName(const std::string& rule_name);
static bool IsRuleRegistered(const std::string& rule_name);
private:
static std::map<std::string, RuleFunc>
factories() {
static std::map<std::string, RuleFunc> impl;
return impl;
}
};
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#define REGISTER_DEFENDER_RULE(info, func) RuleRegisterer CONCAT(rule, __COUNTER__)(info, func);
RuleResults RuleOf10And12(const ble::BridgeState& state);
#endif //BRIDGE_LEARNING_PLAYCC_RULE_BASED_DEFENDER_H_