Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对称性加速是个啥原理 没看懂 #207

Open
xjay111 opened this issue Dec 26, 2024 · 11 comments
Open

对称性加速是个啥原理 没看懂 #207

xjay111 opened this issue Dec 26, 2024 · 11 comments

Comments

@xjay111
Copy link

xjay111 commented Dec 26, 2024

void PCfrSolver::findGameSpecificIsomorphisms() {
    // hand isomorphisms
    vector<Card> board_cards = Card::long2boardCards(this->initial_board_long);
    for(int i = 0;i <= 1;i ++){
        vector<PrivateCards>& range = i == 0?this->range1:this->range2;
        for(std::size_t i_range = 0;i_range < range.size();i_range ++) {
            PrivateCards one_range = range[i_range];
            uint32_t range_hash[4]; // four colors, hash of the isomorphisms range + hand combos
            for(int i = 0;i < 4;i ++)range_hash[i] = 0;
            for (int color = 0; color < 4; color++) {
                for (Card one_card:board_cards) {
                    if (one_card.getCardInt() % 4 == color) {
                        range_hash[color] = range_hash[color] | (1 << (one_card.getCardInt() / 4));
                    }
                }
            }
            for (int color = 0; color < 4; color++) {
                for (int one_card_int:{one_range.card1,one_range.card2}) {
                    if (one_card_int % 4 == color) {
                        range_hash[color] = range_hash[color] | (1 << (one_card_int / 4 + 16));
                    }
                }
            }
            // TODO check whethe hash is equal with others
        }
    }
  
    // 
    uint16_t color_hash[4];
    for(int i = 0;i < 4;i ++)color_hash[i] = 0;
    for (Card one_card:board_cards) {
        int rankind = one_card.getCardInt() % 4;
        int suitind = one_card.getCardInt() / 4;
        color_hash[rankind] = color_hash[rankind] | (1 << suitind);
    }
    for(int i = 0;i < 4;i ++){
        this->color_iso_offset[0][i] = 0;
        for(int j = 0;j < i;j ++){
            if(color_hash[i] == color_hash[j]){
                this->color_iso_offset[0][i] = j - i;
                continue;
            }
        }
    }
    for(std::size_t deal = 0;deal < this->deck.getCards().size();deal ++) {
        uint16_t color_hash[4];
        for(int i = 0;i < 4;i ++)color_hash[i] = 0;
        // chance node isomorphisms
        for (Card one_card:board_cards) {
            int rankind = one_card.getCardInt() % 4;
            int suitind = one_card.getCardInt() / 4;
            color_hash[rankind] = color_hash[rankind] | (1 << suitind);
        }
        Card one_card = this->deck.getCards()[deal];
        int rankind = one_card.getCardInt() % 4;
        int suitind = one_card.getCardInt() / 4;
        color_hash[rankind] = color_hash[rankind] | (1 << suitind);
        for (int i = 0; i < 4; i++) {
            this->color_iso_offset[deal + 1][i] = 0;
            for (int j = 0; j < i; j++) {
                if (color_hash[i] == color_hash[j]) {
                    this->color_iso_offset[deal + 1][i] = j - i;
                    continue;
                }
            }
        }
    }
}
@xjay111
Copy link
Author

xjay111 commented Dec 26, 2024

我看似乎在betstresponse里面用这个跳过了很多计算 但是没看懂是什么原理

@bupticybee
Copy link
Owner

我看似乎在betstresponse里面用这个跳过了很多计算 但是没看懂是什么原理

讲起来挺费劲的,其实不用这个也行,只是慢一点

@bupticybee
Copy link
Owner

N 年前写的屎山代码了,现在看我感觉没半个小时都想不起来当时思路是什么

@xjay111
Copy link
Author

xjay111 commented Dec 26, 2024

用cuda做加速的可行性怎么样 策略树这么大 感觉显存是不是会不够

@xjay111
Copy link
Author

xjay111 commented Dec 26, 2024

   if(root->getPlayer() == 1 && root->getParent() != nullptr && root->getParent()->getType() == GameTreeNode::GameTreeNodeType::CHANCE){
                shared_ptr<ChanceNode> chanceNodeBeforeThis = std::dynamic_pointer_cast<ChanceNode>(root->getParent());
                if(chanceNodeBeforeThis->isDonk())
                    betType = BetType::DONK;

似乎发现donksize 没作用好像.... 反主动下注尺寸这个策略似乎并不会出现在策略树里面

@bupticybee
Copy link
Owner

   if(root->getPlayer() == 1 && root->getParent() != nullptr && root->getParent()->getType() == GameTreeNode::GameTreeNodeType::CHANCE){
                shared_ptr<ChanceNode> chanceNodeBeforeThis = std::dynamic_pointer_cast<ChanceNode>(root->getParent());
                if(chanceNodeBeforeThis->isDonk())
                    betType = BetType::DONK;

似乎发现donksize 没作用好像.... 反主动下注尺寸这个策略似乎并不会出现在策略树里面

不能把,应该是有作用,我肯定测试过

@bupticybee
Copy link
Owner

用cuda做加速的可行性怎么样 策略树这么大 感觉显存是不是会不够

有相关论文,现在有一个PR在做这个事情

@xjay111
Copy link
Author

xjay111 commented Dec 27, 2024

微信截图_20241227160019
微信截图_20241227160046

转牌策略树里边没有出现donk的选项呀

@bupticybee
Copy link
Owner

微信截图_20241227160019 微信截图_20241227160046

转牌策略树里边没有出现donk的选项呀

这样的话就有可能是个bug了

@xjay111
Copy link
Author

xjay111 commented Dec 27, 2024

微信截图_20241227191819
这个地方的nextplayer有点疑惑呀 ,我看你在root节点传入的玩家默认是1,是不是代表当前node的玩家ID应该是下一次行动轮的玩家,因为OP是0 IP是1,第一次行动的玩家应该是0,那么这里的这个winner玩家是不是应该传入player而不是nextplayer?

@bupticybee
Copy link
Owner

微信截图_20241227191819 这个地方的nextplayer有点疑惑呀 ,我看你在root节点传入的玩家默认是1,是不是代表当前node的玩家ID应该是下一次行动轮的玩家,因为OP是0 IP是1,第一次行动的玩家应该是0,那么这里的这个winner玩家是不是应该传入player而不是nextplayer?

这个太细节了真的不记得了,你可以打断点看这里

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants