-
Notifications
You must be signed in to change notification settings - Fork 0
/
bridge_observation.h
82 lines (59 loc) · 2.62 KB
/
bridge_observation.h
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
//
// Created by qzz on 2023/9/20.
//
#ifndef BRIDGE_LEARNING_BRIDGE_LIB_BRIDGE_OBSERVATION_H_
#define BRIDGE_LEARNING_BRIDGE_LIB_BRIDGE_OBSERVATION_H_
#include "bridge_game.h"
#include "bridge_hand.h"
#include "bridge_state.h"
namespace bridge_learning_env {
int PlayerToOffset(Player pid, Player observer_pid);
// In bridge, a player can observe
// (1) His hand.
// (2) Auction history
// (3) Contract
// (4) Play history
// (5) Vulnerability
class BridgeObservation {
public:
BridgeObservation(const BridgeState& state, Player observing_player);
BridgeObservation(const BridgeState& state)
: BridgeObservation(state, state.CurrentPlayer()) {
}
Player ObservingPlayer() const { return observing_player_; }
// offset of current player from observing player.
int CurPlayerOffset() const { return cur_player_offset_; }
std::string ToString() const;
std::array<Trick, kNumTricks> Tricks() const { return tricks_; }
const std::vector<BridgeHistoryItem>& AuctionHistory() const { return auction_history_; }
const std::vector<BridgeHistoryItem>& PlayHistory() const { return play_history_; }
const std::vector<BridgeHistoryItem>& DealHistory() const { return deal_history_; }
const std::vector<BridgeHand>& Hands() const { return hands_; }
const std::shared_ptr<BridgeGame>& ParentGame() const { return parent_game_; }
const std::vector<BridgeMove>& LegalMoves() const { return legal_moves_; }
bool IsPlayerVulnerable() const { return is_player_vulnerable_; }
bool IsOpponentVulnerable() const { return is_opponent_vulnerable_; }
Phase CurrentPhase() const { return current_phase_; }
Contract GetContract() const { return contract_; }
int NumCardsPlayed() const { return static_cast<int>(play_history_.size()); }
int NumDeclarerTricks() const { return num_declarer_tricks_; }
Player Dummy() const { return Partner(contract_.declarer); }
private:
int cur_player_offset_; // offset of current_player_ from observing_player
Player observing_player_;
Phase current_phase_;
// hands_[0] contains observing player's hand.
std::vector<BridgeHand> hands_;
std::vector<BridgeMove> legal_moves_;
std::vector<BridgeHistoryItem> deal_history_;
std::vector<BridgeHistoryItem> auction_history_;
std::vector<BridgeHistoryItem> play_history_;
const Contract contract_;
bool is_player_vulnerable_;
bool is_opponent_vulnerable_;
std::array<Trick, kNumTricks> tricks_;
int num_declarer_tricks_;
std::shared_ptr<BridgeGame> parent_game_ = nullptr;
};
} // namespace bridge
#endif // BRIDGE_LEARNING_BRIDGE_LIB_BRIDGE_OBSERVATION_H_