forked from rggibson/open-pure-cfr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
card_abstraction.hpp
99 lines (82 loc) · 3.06 KB
/
card_abstraction.hpp
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
#ifndef __PURE_CFR_CARD_ABSTRACTION_HPP__
#define __PURE_CFR_CARD_ABSTRACTION_HPP__
/* card_abstraction.hpp
* Richard Gibson, Jun 28, 2013
*
* Home of the card_abstraction abstract class and all implementing classes
*
* Copyright (C) 2013 by Richard Gibson
*/
/* C / C++ / STL indluces */
/* project_acpc_server includes */
extern "C" {
#include "acpc_server_code/game.h"
}
/* Pure CFR includes */
#include "constants.hpp"
#include "betting_node.hpp"
/* Base class */
class CardAbstraction {
public:
CardAbstraction( );
virtual ~CardAbstraction( );
virtual int num_buckets( const Game *game, const BettingNode *node ) const = 0;
virtual int num_buckets( const Game *game, const State &state ) const = 0;
virtual int get_bucket( const Game *game,
const BettingNode *node,
const uint8_t board_cards[ MAX_BOARD_CARDS ],
const uint8_t hole_cards[ MAX_PURE_CFR_PLAYERS ]
[ MAX_HOLE_CARDS ] ) const = 0;
virtual bool can_precompute_buckets( ) const { return false; }
virtual void precompute_buckets( const Game *game,
hand_t &hand ) const;
protected:
};
/* The null card abstraction treats every set of cards as its own bucket.
* This is a naive abstraction that does not take suit isomorphism into account.
* Further, more buckets are used than necessary as card removal and order
* are ignored.
*/
class NullCardAbstraction : public CardAbstraction {
public:
NullCardAbstraction( const Game *game );
virtual ~NullCardAbstraction( );
virtual int num_buckets( const Game *game, const BettingNode *node ) const;
virtual int num_buckets( const Game *game, const State &state ) const;
virtual int get_bucket( const Game *game,
const BettingNode *node,
const uint8_t board_cards[ MAX_BOARD_CARDS ],
const uint8_t hole_cards[ MAX_PURE_CFR_PLAYERS ]
[ MAX_HOLE_CARDS ] ) const;
virtual bool can_precompute_buckets( ) const { return true; }
virtual void precompute_buckets( const Game *game,
hand_t &hand ) const;
protected:
virtual int get_bucket_internal( const Game *game,
const uint8_t board_cards[ MAX_BOARD_CARDS ],
const uint8_t hole_cards[ MAX_PURE_CFR_PLAYERS ]
[ MAX_HOLE_CARDS ],
const int player,
const int round ) const;
const int deck_size;
int m_num_buckets[ MAX_ROUNDS ];
};
/* The blind card abstraction treats every set of cards as the same.
* This is a simple abstraction that enforces the agent to not look at its cards.
*/
class BlindCardAbstraction : public CardAbstraction {
public:
BlindCardAbstraction( );
virtual ~BlindCardAbstraction( );
virtual int num_buckets( const Game *game, const BettingNode *node ) const;
virtual int num_buckets( const Game *game, const State &state ) const;
virtual int get_bucket( const Game *game,
const BettingNode *node,
const uint8_t board_cards[ MAX_BOARD_CARDS ],
const uint8_t hole_cards[ MAX_PURE_CFR_PLAYERS ]
[ MAX_HOLE_CARDS ] ) const;
virtual bool can_precompute_buckets( ) const { return true; }
virtual void precompute_buckets( const Game *game,
hand_t &hand ) const;
};
#endif