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

Replaces int with std::size_t in for loops to prevent warnings #186

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/tools/qdebugstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class QDebugStream : public std::basic_streambuf<char>
{
m_string.append(p, p + n);

int pos = 0;
std::size_t pos = 0;
while (pos != std::string::npos)
{
pos = m_string.find('\n');
Expand Down
6 changes: 3 additions & 3 deletions include/tools/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void exchange_color(vector<T>& value,vector<PrivateCards> range,int rank1,int ra
if(value.empty())return;
vector<int> self_ind = vector<int>(value.size());
int privateint2ind[52 * 52 * 2] = {0};
for(int i = 0;i < range.size();i ++){
for(std::size_t i = 0;i < range.size();i ++){
PrivateCards& pc = range[i];
int card1 = pc.card1;
int card2 = pc.card2;
Expand All @@ -49,9 +49,9 @@ void exchange_color(vector<T>& value,vector<PrivateCards> range,int rank1,int ra
privateint2ind[card1 * 52 + card2] = i;
}

for(int i = 0;i < range.size();i ++) {
for(std::size_t i = 0;i < range.size();i ++) {
if(self_ind[i] == -1) continue;
int ind = privateint2ind[self_ind[i]];
std::size_t ind = privateint2ind[self_ind[i]];
//cout << range[i].toString() << " ";
//cout << range[ind].toString() << endl;
if(ind != i){
Expand Down
8 changes: 4 additions & 4 deletions src/Card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ string Card::intCard2Str(int card){

uint64_t Card::boardCards2long(vector<string> cards) {
vector<Card> cards_objs(cards.size());
for(int i = 0;i < cards.size();i++){
for(std::size_t i = 0;i < cards.size();i++){
cards_objs[i] = Card(cards[i]);
}
return Card::boardCards2long(cards_objs);
Expand All @@ -68,7 +68,7 @@ uint64_t Card::boardCard2long(Card& card){

uint64_t Card::boardCards2long(vector<Card>& cards){
std::vector<int> board_int(cards.size());
for(int i = 0;i < cards.size();i++){
for(std::size_t i = 0;i < cards.size();i++){
board_int[i] = Card::card2int(cards[i]);
}
return Card::boardInts2long(board_int);
Expand Down Expand Up @@ -133,15 +133,15 @@ vector<int> Card::long2board(uint64_t board_long) {
vector<Card> Card::long2boardCards(uint64_t board_long){
vector<int> board = long2board(board_long);
vector<Card> board_cards(board.size());
for(int i = 0;i < board.size();i ++){
for(std::size_t i = 0;i < board.size();i ++){
int one_board = board[i];
board_cards[i] = Card(intCard2Str(one_board));
}
if (board_cards.size() < 1 || board_cards.size() > 7){
throw runtime_error(tfm::format("board length not correct, board length %s",board_cards.size()));
}
vector<Card> retval(board_cards.size());
for(int i = 0;i < board_cards.size();i ++){
for(std::size_t i = 0;i < board_cards.size();i ++){
retval[i] = board_cards[i];
}
return retval;
Expand Down
16 changes: 8 additions & 8 deletions src/GameTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ GameTree::generateActionNode(json meta, vector<string> childrens_actions, vector
vector<shared_ptr<GameTreeNode>> childrens;

// 遍历所有children actions 来生成GameAction 的list,用于初始化ActionNode
for(int i = 0;i < childrens_actions.size();i++){
for(std::size_t i = 0;i < childrens_actions.size();i++){
string one_action = childrens_actions[i];
json one_children_map = childrens_nodes[i];
if(one_action.empty()) throw runtime_error("action is null");
Expand Down Expand Up @@ -471,7 +471,7 @@ shared_ptr<ShowdownNode> GameTree::generateShowdownNode(json meta, string round,
shared_ptr<TerminalNode> GameTree::generateTerminalNode(json meta, string round, shared_ptr<GameTreeNode> parent) {
vector<double> player_payoff_list = meta["payoff"];
vector<double> player_payoff(player_payoff_list.size());
for(int one_player = 0;one_player < player_payoff_list.size();one_player ++){
for(std::size_t one_player = 0;one_player < player_payoff_list.size();one_player ++){

double tmp_payoff = player_payoff_list[one_player];
player_payoff[one_player] = tmp_payoff;
Expand Down Expand Up @@ -527,7 +527,7 @@ long long GameTree::re_estimate_tree_memory(const shared_ptr<GameTreeNode>& node
vector<GameActions> actions = action_node->getActions();

long long retnum = 0;
for(int i = 0;i < childrens.size();i++){
for(std::size_t i = 0;i < childrens.size();i++){
shared_ptr<GameTreeNode> one_child = childrens[i];
retnum += re_estimate_tree_memory(one_child,deck_num, p1range_num, p2range_num, num_current_deal);
}
Expand Down Expand Up @@ -555,7 +555,7 @@ void GameTree::recurrentPrintTree(const shared_ptr<GameTreeNode>& node, int dept
vector<shared_ptr<GameTreeNode>> childrens = action_node->getChildrens();
vector<GameActions> actions = action_node->getActions();

for(int i = 0;i < childrens.size();i++){
for(std::size_t i = 0;i < childrens.size();i++){
shared_ptr<GameTreeNode> one_child = childrens[i];
GameActions one_action = actions[i];

Expand All @@ -575,11 +575,11 @@ void GameTree::recurrentPrintTree(const shared_ptr<GameTreeNode>& node, int dept
)) << endl;

prefix += "\t";
for(int i = 0;i < showdown_node->get_payoffs(ShowdownNode::ShowDownResult::TIE,-1).size();i++) {
for(std::size_t i = 0;i < showdown_node->get_payoffs(ShowdownNode::ShowDownResult::TIE,-1).size();i++) {
cout << (tfm::format("%sif player %s wins, payoff :", prefix,i));
vector<double> payoffs = showdown_node->get_payoffs(ShowdownNode::ShowDownResult::NOTTIE, i);

for (int player_id = 0; player_id < payoffs.size(); player_id++) {
for (std::size_t player_id = 0; player_id < payoffs.size(); player_id++) {
cout << (
tfm::format(" p%s %s ", player_id, payoffs[player_id])
);
Expand All @@ -589,7 +589,7 @@ void GameTree::recurrentPrintTree(const shared_ptr<GameTreeNode>& node, int dept
cout << (tfm::format("%sif Tie, payoff :", prefix));
vector<double> payoffs = showdown_node->get_payoffs(ShowdownNode::ShowDownResult::TIE, -1);

for (int player_id = 0; player_id < payoffs.size(); player_id++) {
for (std::size_t player_id = 0; player_id < payoffs.size(); player_id++) {
cout << (
tfm::format(" p%s %s ", player_id, payoffs[player_id])
);
Expand All @@ -607,7 +607,7 @@ void GameTree::recurrentPrintTree(const shared_ptr<GameTreeNode>& node, int dept
cout << (tfm::format("%sTerminal payoff :", prefix));
vector<double> payoffs = terminal_node->get_payoffs();

for (int player_id = 0; player_id < payoffs.size(); player_id++) {
for (std::size_t player_id = 0; player_id < payoffs.size(); player_id++) {
cout <<(
tfm::format("p%s %s ", player_id, payoffs[player_id])
);
Expand Down
2 changes: 1 addition & 1 deletion src/compairer/Dic5Compairer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Dic5Compairer::compair(vector<int> private_former, vector<int> private_latter, v

int Dic5Compairer::getRank(vector<Card> cards) {
vector<int> cards_int(cards.size());
for(int i = 0;i < cards.size();i++){
for(std::size_t i = 0;i < cards.size();i++){
cards_int[i] = cards[i].getCardInt();
}
return this->getRank(cards_int);
Expand Down
6 changes: 3 additions & 3 deletions src/ranges/PrivateCardsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PrivateCardsManager::PrivateCardsManager(vector<vector<PrivateCards>> private_ca
// 用一个二维数组记录每个Private Combo的对应index,方便从一方的手牌找对方的同名卡牌的index
for(int player_id = 0;player_id < player_number;player_id ++){
vector<PrivateCards> privateCombos = private_cards[player_id];
for(int i = 0;i < privateCombos.size();i ++){
for(std::size_t i = 0;i < privateCombos.size();i ++){
PrivateCards one_private_combo = privateCombos[i];
this->card_player_index[one_private_combo.hashCode()][player_id] = i;
}
Expand Down Expand Up @@ -66,7 +66,7 @@ void PrivateCardsManager::setRelativeProbs() {
int oppo = 1 - player_id;
float player_prob_sum = 0;

for(int i = 0;i < this->private_cards[player_id].size();i ++) {
for(std::size_t i = 0;i < this->private_cards[player_id].size();i ++) {
float oppo_prob_sum = 0;
PrivateCards* player_card = &this->private_cards[player_id][i];
uint64_t player_long = Card::boardInts2long(player_card->get_hands());
Expand All @@ -89,7 +89,7 @@ void PrivateCardsManager::setRelativeProbs() {
player_card->relative_prob = oppo_prob_sum * player_card->weight;
player_prob_sum += player_card->relative_prob;
}
for(int i = 0;i < this->private_cards[player_id].size();i ++) {
for(std::size_t i = 0;i < this->private_cards[player_id].size();i ++) {
this->private_cards[player_id][i].relative_prob = this->private_cards[player_id][i].relative_prob / player_prob_sum;
//player_card.relative_prob = player_card.relative_prob / player_prob_sum;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ranges/RiverRangeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ RiverRangeManager::getRiverCombos(int player, const vector<PrivateCards> &preflo
int index = 0;
vector<RiverCombs> riverCombos = vector<RiverCombs>(count);

for (int hand = 0; hand < preflopCombos.size(); hand++)
for (std::size_t hand = 0; hand < preflopCombos.size(); hand++)
{
PrivateCards preflopCombo = preflopCombos[hand];

Expand Down
28 changes: 14 additions & 14 deletions src/solver/BestResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ float BestResponse::printExploitability(shared_ptr<GameTreeNode> root, int itera
if(reach_probs[player_id].empty()) {
reach_probs[player_id] = vector<float>(private_combos[player_id].size());
}
for (int hc = 0; hc < private_combos[player_id].size(); hc++)
for (std::size_t hc = 0; hc < private_combos[player_id].size(); hc++)
reach_probs[player_id][hc] = private_combos[player_id][hc].weight;
}

Expand All @@ -69,7 +69,7 @@ float BestResponse::getBestReponseEv(shared_ptr<GameTreeNode> node, int player,
vector<PrivateCards>& player_combo = this->private_combos[player];
vector<PrivateCards>& oppo_combo = this->private_combos[1 - player];

for(int player_hand = 0;player_hand < player_combo.size();player_hand ++){
for(std::size_t player_hand = 0;player_hand < player_combo.size();player_hand ++){
float one_payoff = private_cards_evs[player_hand];
PrivateCards& one_player_hand = (player_combo)[player_hand];
uint64_t private_long = one_player_hand.toBoardLong();
Expand All @@ -78,7 +78,7 @@ float BestResponse::getBestReponseEv(shared_ptr<GameTreeNode> node, int player,
}
float oppo_sum = 0;

for(int oppo_hand = 0;oppo_hand < oppo_combo.size();oppo_hand ++){
for(std::size_t oppo_hand = 0;oppo_hand < oppo_combo.size();oppo_hand ++){
PrivateCards& one_oppo_hand = (oppo_combo)[oppo_hand];
uint64_t private_long_oppo = one_oppo_hand.toBoardLong();
if(Card::boardsHasIntercept(private_long,private_long_oppo)
Expand Down Expand Up @@ -130,7 +130,7 @@ BestResponse::chanceBestReponse(shared_ptr<ChanceNode> node, int player,const ve
vector<vector<float>> results(node->getCards().size());

#pragma omp parallel for
for(int card = 0;card < node->getCards().size();card ++) {
for(std::size_t card = 0;card < node->getCards().size();card ++) {
shared_ptr<GameTreeNode> one_child = node->getChildren();
Card one_card = node->getCards()[card];
uint64_t card_long = Card::boardInt2long(one_card.getCardInt());
Expand Down Expand Up @@ -198,7 +198,7 @@ BestResponse::chanceBestReponse(shared_ptr<ChanceNode> node, int player,const ve
results[one_card.getNumberInDeckInt()] = child_utility;
}

for(int card = 0;card < node->getCards().size();card ++) {
for(std::size_t card = 0;card < node->getCards().size();card ++) {
Card *one_card = const_cast<Card *>(&(node->getCards()[card]));
vector<float> child_utility;
int offset = this->color_iso_offset[deal][one_card->getCardInt() % 4];
Expand All @@ -220,7 +220,7 @@ BestResponse::chanceBestReponse(shared_ptr<ChanceNode> node, int player,const ve
#ifdef DEBUG
if(child_utility.size() != chance_utility.size()) throw runtime_error("length not match3 ");
#endif
for(int i = 0;i < child_utility.size();i ++)
for(std::size_t i = 0;i < child_utility.size();i ++)
chance_utility[i] += (child_utility)[i];
}

Expand All @@ -242,7 +242,7 @@ BestResponse::actionBestResponse(shared_ptr<ActionNode> node, int player, const
my_exploitability.assign(node_ev.begin(),node_ev.end());
first_action_flag = false;
}else {
for (int i = 0;i < node_ev.size();i ++) {
for (std::size_t i = 0;i < node_ev.size();i ++) {
my_exploitability[i] = max(my_exploitability[i],node_ev[i]);
}
}
Expand Down Expand Up @@ -273,7 +273,7 @@ BestResponse::actionBestResponse(shared_ptr<ActionNode> node, int player, const

vector<vector<vector<float>>> best_respond_arr_new_reach_probs = vector<vector<vector<float>>>(node->getChildrens().size());
// 构造reach probs矩阵
for(int action_ind = 0;action_ind < node->getChildrens().size();action_ind ++){
for(std::size_t action_ind = 0;action_ind < node->getChildrens().size();action_ind ++){
if(best_respond_arr_new_reach_probs[action_ind].empty()){
best_respond_arr_new_reach_probs[action_ind] = vector<vector<float>>(this->player_number);
}
Expand Down Expand Up @@ -314,7 +314,7 @@ BestResponse::actionBestResponse(shared_ptr<ActionNode> node, int player, const
);
#endif

for(int i = 0 ;i < total_payoffs.size();i ++){
for(std::size_t i = 0 ;i < total_payoffs.size();i ++){
total_payoffs[i] += action_payoffs[i];// * node_strategy[i] 的动作实际上已经在递归的时候做过了,所以这里不需要乘
}
}
Expand Down Expand Up @@ -350,7 +350,7 @@ BestResponse::terminalBestReponse(shared_ptr<TerminalNode> node, int player, con
float oppo_prob_sum = 0;

const vector<float>& oppo_reach_prob = reach_probs[1 - player];
for(int oppo_hand = 0;oppo_hand < oppo_combs.size(); oppo_hand ++){
for(std::size_t oppo_hand = 0;oppo_hand < oppo_combs.size(); oppo_hand ++){
const RiverCombs& one_hc = oppo_combs[oppo_hand];
uint64_t one_hc_long = Card::boardInts2long(one_hc.private_cards.get_hands());

Expand All @@ -365,7 +365,7 @@ BestResponse::terminalBestReponse(shared_ptr<TerminalNode> node, int player, con
}


for(int player_hand = 0;player_hand < player_combs.size();player_hand ++) {
for(std::size_t player_hand = 0;player_hand < player_combs.size();player_hand ++) {
const RiverCombs& player_hc = player_combs[player_hand];
uint64_t player_hc_long = Card::boardInts2long(player_hc.private_cards.get_hands());
if(Card::boardsHasIntercept(player_hc_long,board_long)){
Expand Down Expand Up @@ -413,12 +413,12 @@ BestResponse::showdownBestResponse(shared_ptr<ShowdownNode> node, int player,con
// 计算胜利时的payoff
float winsum = 0;
vector<float> card_winsum(52);
for(int i = 0;i < card_winsum.size();i ++) card_winsum[i] = 0;
for(std::size_t i = 0;i < card_winsum.size();i ++) card_winsum[i] = 0;

int j = 0;
std::size_t j = 0;
//if(player_combs.length != oppo_combs.length) throw new RuntimeException("");

for(int i = 0;i < player_combs.size();i ++){
for(std::size_t i = 0;i < player_combs.size();i ++){
const RiverCombs& one_player_comb = player_combs[i];
while (j < oppo_combs.size() && one_player_comb.rank < oppo_combs[j].rank){
const RiverCombs& one_oppo_comb = oppo_combs[j];
Expand Down
Loading
Loading