Пример #1
0
/* this will be replaced with something more sophisticated later */
void ActionSelector::preflopSelector(int potSize, bool myButton, 
				      const std::vector<std::string> &boardCards, 
				      const std::vector<std::string> &holeCards, 
				      const std::string &myDiscard,
				      const ActionSelector::LegalAction &legalAction,
				      ActionSelector::ActionInfo &actionInfo,
				      float equity)
{
  // open with the top 75% of hands on the button, and with top 50% otherwise
  int raise=0, adjustRaise, noise, toCall;
  toCall = legalAction.callMin;
  
  float discount = myButton ? 0.09 : 0;  
  float potOdds = (float)toCall/(toCall+potSize);
  
  // generate betting noise
  noise = (rand() % 3 - 1);

  bool canRaise=legalAction.raiseMax>0, isAllin=legalAction.raiseMax==0, mustCall=legalAction.callMin>0;;  
  if (canRaise > 0 && equity-discount > 0.5){
    int bucket = (int)(20*equity)-9;
    raise = std::max(7, 7 + (bucket + noise)*8);
    adjustRaise = std::max(std::min(raise,legalAction.raiseMax), legalAction.raiseMin);
    std::cout << "ActionSelector:L108 (equity, bucket, noise, raise, adjRaise): " << equity << " " <<bucket << " " << noise << " " << raise << " " << adjustRaise << std::endl;
  }  

  // for now no re-raising pre-flop more than our normal raise
  if (raise && (raise == adjustRaise)){ //can raise/bet without any problem
    if (legalAction.actionType == CHECK_BET)
      Bet(actionInfo,raise);
    else
      Raise(actionInfo,raise);
  } else {    
    if (isAllin) {
      if (equity > 0.59)
	Call(actionInfo);   //only call all-in if have top hands
      else 
	Fold(actionInfo);
    } else if (mustCall){
      if (equity > potOdds+0.05)
	Call(actionInfo);  // call if cheap enough to call
      else 
	Fold(actionInfo);
    } else {      
      Check(actionInfo);
    }    
  }   
}
Пример #2
0
/* this will be replaced with something more sophisticated later */
void ActionSelector::evalMagic(int potSize, bool myButton, 
				const std::vector<std::string> &boardCards, 
				const std::vector<std::string> &holeCards, 
				const std::string &myDiscard,
				const ActionSelector::LegalAction &legalAction,
				ActionSelector::ActionInfo &actionInfo,
				float equity){
  int coin = rand() % 3; //LOL
  int callMin = legalAction.callMin;
   
  if (coin == 1 && equity > 0.8){
    if (legalAction.raiseMax > 0){
      if (legalAction.actionType == CHECK_BET)
	Bet(actionInfo, legalAction.raiseMax);
      else 
	Raise(actionInfo, legalAction.raiseMax);
    } else { 
      std::cout << "ActionSelector.cpp:L78 Calling All-in" << std::endl;
      Call(actionInfo);
    }
    //std::cout << "raising to " << actionInfo.betAmount << std::endl;
    return;
  } 
   
  // compute pot odds and either call or fold    
  float potOdds = (float)callMin/(callMin+potSize);

  bool canRaise=legalAction.raiseMax>0, isAllin=legalAction.raiseMax==0, mustCall=legalAction.callMin>0;
  // raise with the worst and best cards in our range

  if (equity>0.62){
    std::cout << "myPotOdds: " << callMin << "/" << (callMin+potSize) << ":" << potOdds << " vs. equity: " << equity << std::endl;
    if (legalAction.raiseMax > 0){
      float oppEquity=1-equity;
      int newPotSize=callMin+potSize;
      
      int raise=(int)((newPotSize*equity/oppEquity)) + callMin;
      //	int raise=(int)((newPotSize*equity/oppEquity)) + callMin;
		
      int numBoardCards = boardCards.size();
      if (numBoardCards >= 3) raise = 7; //7std::max(raise, 100); // so we actually can make money      
      if (numBoardCards >= 4 && equity > 0.7) raise = std::max(raise, 200);      
      if (numBoardCards >= 5 && equity > 0.85) raise = std::max(raise, 300);      
	  
      int betAmt= std::max(std::min(raise,legalAction.raiseMax), legalAction.raiseMin);

      std::cout << "betAmt: " << betAmt << " vs. raise: " << raise << "(raiseMin, max) " << legalAction.raiseMin << ", " << legalAction.raiseMax << std::endl;
      if (betAmt){
	actionInfo.action= (legalAction.actionType == CHECK_BET) ? BET : RAISE;
	actionInfo.betAmount=betAmt;
      } else {
	actionInfo.action = (legalAction.actionType == CHECK_BET) ? CHECK : FOLD;
	actionInfo.betAmount=0;
      }//end if(betAmt)
    } else {	 
      if ((legalAction.callMin > 100 && equity < 0.65))
	Fold(actionInfo);
      else 
	Call(actionInfo);
    } //end if(raisMax > 0)
  }else{
    std::cout << "myPotOdds: " << callMin << "/" << (callMin+potSize) << ":" << potOdds << " vs. equity: " << equity << std::endl;

    float roundDiscount=0;
    int numBoardCards = boardCards.size();

    // Discount our equity, so we are less willing to call with low equity on later streets (especially the river)
    if (numBoardCards == 5){
      roundDiscount=0.2;
    }       

    if (legalAction.callMin > 0){
      if (numBoardCards>=3 && equity < 0.55){ // fold if our equity is bad by the turn	  
	Fold(actionInfo);
      }else if (equity-roundDiscount>(potOdds)+0.04){ //less likely to call if we are down
	Call(actionInfo);
      } else {
	Fold(actionInfo);
      }
    } else {      
      Check(actionInfo);
    }
  }
}
Пример #3
0
Bet ComputerPlayer::calculateBet(SmallDeck comm, int minBet, GameState state) {

	srand((unsigned) time(0));
	ifstream inputFile;
	inputFile.open("PocketRanking.txt");
	char temp[4];
	int rank;
	int card1;
	int card2;
	int suited;
	int cardsuits;
	int ComputerRank;

	Card temp1;
	Card temp2;
	Card temp3;
	Hand Current;
	SmallDeck d = *pocket;

	if (!comm.isEmpty()) {
		Current.evaluate(d, comm);
	}
	temp1 | d.getCard(0);
	temp2 | d.getCard(1);

	if (temp1.getSuit() == temp2.getSuit()) {
		cardsuits = 1;
	} else {
		cardsuits = 0;
	}
	if (temp2.getValue() > temp1.getValue()) {
		temp3 | temp1;
		temp1 | temp2;
		temp2 | temp3;
	}

	for (int i = 0; i < 169; i++) {

		inputFile.getline(temp, 4, '	');
		inputFile >> temp;
		rank = atoi(temp);

		inputFile.getline(temp, 4, '	');
		inputFile >> temp;
		card1 = atoi(temp);

		inputFile.getline(temp, 4, '	');
		inputFile >> temp;
		card2 = atoi(temp);

		inputFile.getline(temp, 4, '	');
		inputFile >> temp;
		suited = atoi(temp);

		if (card1 == temp1.getValue() && card2 == temp2.getValue()
				&& suited == cardsuits)
			ComputerRank = rank;

	}

	int PC; //PocketConfidence
	int FP; //Flop Confidence
	if (ComputerRank <= 169 && ComputerRank >= 120)
		PC = 0;
	else if (ComputerRank <= 119 && ComputerRank >= 80)
		PC = 1;
	else if (ComputerRank <= 79 && ComputerRank >= 30)
		PC = 2;
	else if (ComputerRank <= 29 && ComputerRank >= 20)
		PC = 3;
	else if (ComputerRank <= 19 && ComputerRank >= 10)
		PC = 4;
	else if (ComputerRank <= 9 && ComputerRank >= 1)
		PC = 5;

	BetAction betAct = CALL;
	int betAmt = 0;
	int percent = rand() % 10;
	if (state == NEWROUND) {

		switch (PC) {
		case 0: {
			if (percent < 5) {
				if (minBet == 0) {
					betAct = CALL;
					betAmt = 0;
				} else {
					betAct = FOLD;
					betAmt = 0;
				}
				break;
			} else {
				betAct = CALL;
				betAmt = minBet;
			}
			break;
		}
		case 1: {
			if (percent < 3) {
				if (minBet == 0) {
					betAct = CALL;
					betAmt = 0;
				} else {
					betAct = FOLD;
					betAmt = 0;
				}
				break;
			} else {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet; //	betAmt = money < betAmt ? money : betAmt;

			}
			break;
		}
		case 2: {
			if (percent < 1) {
				if (minBet == 0) {
					betAct = CALL;
					betAmt = 0;
				} else {
					betAct = FOLD;
					betAmt = 0;
				}
				break;
			} else if (percent < 8) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			}
			break;
		}
		case 3: {
			if (percent < 8) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			}
			break;
		}
		case 4: {

			if (percent < 7) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			}
			break;
		}
		case 5: {
			if (percent < 5) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			}
			break;
		}

		}
	} else {
		if (Current.getType() < 13 && Current.getType() >= 0 && PC > 2)
			FP = PC;
		else if (Current.getType() < 13 && Current.getType() >= 0 && PC <= 2)
			FP = PC - 1;
		else if (Current.getType() < 26 && Current.getType() >= 13 && PC > 2)
			FP = PC + 2;
		else if (Current.getType() < 26 && Current.getType() >= 13 && PC <= 2)
			FP = PC + 1;
		else if (Current.getType() < 38 && Current.getType() >= 26 && PC == 1)
			FP = PC + 3;
		else if (Current.getType() < 38 && Current.getType() >= 26 && PC > 1)
			FP = PC + 4;
		else if (Current.getType() < 106 && Current.getType() >= 38)
			FP = 10;
		switch (FP) {
		case -1: {
			if (minBet == 0) {
				betAct = CALL;
				betAmt = 0;
			} else {
				betAct = FOLD;
				betAmt = 0;
			}
			break;
		}
		case 0: {
			if (percent < 9) {
				if (minBet == 0) {
					betAct = CALL;
					betAmt = 0;
				} else {
					betAct = FOLD;
					betAmt = 0;
				}

			} else {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			}
			break;
		}
		case 1: {
			if (percent < 8) {
				if (minBet == 0) {
					betAct = CALL;
					betAmt = 0;
				} else {
					betAct = FOLD;
					betAmt = 0;
				}
				break;
			} else {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			}
			break;
		}
		case 2: {
			if (percent < 7) {
				if (minBet == 0) {
					betAct = CALL;
					betAmt = 0;
				} else {
					betAct = FOLD;
					betAmt = 0;
				}
				break;
			} else {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			}
			break;
		}
		case 3: {
			if (percent < 5) {
				if (minBet == 0) {
					betAct = CALL;
					betAmt = 0;
				} else {
					betAct = FOLD;
					betAmt = 0;
				}
				break;
			} else if (percent < 9) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			}
			break;
		}
		case 4: {
			if (percent < 3) {
				if (minBet == 0) {
					betAct = CALL;
					betAmt = 0;
				} else {
					betAct = FOLD;
					betAmt = 0;
				}
				break;
			} else if (percent < 8) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			}
			break;
		}
		case 5: {
			if (percent < 1) {
				if (minBet == 0) {
					betAct = CALL;
					betAmt = 0;
				} else {
					betAct = FOLD;
					betAmt = 0;
				}
				break;
			} else if (percent < 8) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			}
			break;
		}
		case 6: {
			if (percent < 8) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			}
			break;
		}
		case 7: {
			if (percent < 8) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			}
			break;
		}
		case 8: {
			if (percent < 7) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			}
			break;
		}
		case 9: {
			if (percent < 7) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else if (percent < 9) {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 120 : 3 * minBet;
			}
			break;
		}
		case 10: {
			if (percent < 3) {
				betAct = CALL;
				betAmt = minBet == 0 ? 40 : minBet;
			} else if (percent < 8) {
				betAct = RAISE;
				betAmt = minBet == 0 ? 80 : 2 * minBet;
			} else {
				betAct = RAISE;
				betAmt = minBet == 0 ? 120 : 3 * minBet;
			}
			break;
		}

		}
	}
	betAmt = money < betAmt ? money : betAmt;
	return Bet(betAct, betAmt);
}