def what_should_i_do(self, my_id, state): board_cards = poker.get_board_cards(self.game, state) hole_cards = poker.get_hole_cards(self.game, state, my_id) nplayers = self.game.numPlayers nremaining = poker.numActingPlayers(self.game, state) if nremaining == 1: action = poker.Action() action.type = poker.CALL action.size = 0 return action # pot features are chips in pot, chips to call, number of opponents, and position chips_in_pot = poker.getPotSize(state, nplayers) p = poker.eval_hand_potential(nremaining, hole_cards, board_cards) expected_winning = p / (1.001 - p) * chips_in_pot chips_to_call = poker.chipsToCall(state, my_id) my_chips_in_pot = poker.getSpent(state, my_id) action = poker.Action() if chips_to_call <= expected_winning: action.type = poker.CALL else: action.type = poker.FOLD if (poker.isValidAction(self.game, state, 0, action) <= 0): action.type = poker.CALL print expected_winning, chips_in_pot, chips_to_call print action.type, action.size assert (poker.isValidAction(self.game, state, 0, action) > 0) return action
def what_should_i_do(self, my_id, state): board_cards = poker.get_board_cards(self.game, state) hole_cards = poker.get_hole_cards(self.game, state, my_id) nplayers = self.game.numPlayers nremaining = poker.numActingPlayers(self.game, state) if nremaining == 1: action = poker.Action() action.type = poker.CALL action.size = 0 return action # pot features are chips in pot, chips to call, number of opponents, and position chips_in_pot = poker.getPotSize(state, nplayers) p = poker.eval_hand_potential(nremaining, hole_cards, board_cards) expected_winning = p / (1.001-p) * chips_in_pot chips_to_call = poker.chipsToCall(state, my_id) my_chips_in_pot = poker.getSpent(state, my_id) action = poker.Action() if chips_to_call <= expected_winning: action.type = poker.CALL else: action.type = poker.FOLD if (poker.isValidAction(self.game, state, 0, action ) <= 0): action.type = poker.CALL print expected_winning, chips_in_pot, chips_to_call print action.type, action.size assert(poker.isValidAction( self.game, state, 0, action ) > 0) return action
def what_should_i_do(self, my_id, state): board_cards = poker.get_board_cards(self.game, state) hole_cards = poker.get_hole_cards(self.game, state, my_id) nplayers = self.game.numPlayers nremaining = poker.numActingPlayers(self.game, state) if nremaining == 1: action = poker.Action() action.type = poker.CALL action.size = 0 return action card_features = poker.calculate_card_features(nremaining, hole_cards, board_cards) # pot features are chips in pot, chips to call, number of opponents, and position chips_in_pot = poker.getPotSize(state, nplayers) chips_to_call = poker.chipsToCall(state, my_id) my_chips_in_pot = poker.getSpent(state, my_id) pos = poker.getNumActions(state, state.round) pot_features = [ my_chips_in_pot, chips_in_pot, chips_to_call, nremaining, pos ] chip_features = [ poker.getStack(self.game, i) - poker.getSpent(state, i) for i in range(nplayers) if not poker.getFolded(state, i) ] s = sum(chip_features) chip_features = [c / float(s) for c in chip_features] action_probabilities = self.neural_net.eval(nremaining, card_features, pot_features, chip_features)[0] print card_features print action_probabilities action = poker.Action() action.type = np.random.choice(self.actions, 1, p=action_probabilities)[0] action.size = 0 raisevalid, minsize, maxsize = poker.raiseIsValid(self.game, state) if action.type == poker.RAISE and raisevalid: action.size = minsize # for limit, size can be anything elif action.type == poker.RAISE and not raisevalid: action.type = poker.CALL elif (poker.isValidAction(self.game, state, 0, action) <= 0): action.type = poker.CALL print action.type, action.size assert (poker.isValidAction(self.game, state, 0, action) > 0) return action
def what_should_i_do(self, my_id, state): board_cards = poker.get_board_cards(self.game, state) hole_cards = poker.get_hole_cards(self.game, state, my_id) nplayers = self.game.numPlayers nremaining = poker.numActingPlayers(self.game, state) if nremaining == 1: action = poker.Action() action.type = poker.CALL action.size = 0 return action card_features = poker.calculate_card_features(nremaining, hole_cards, board_cards) # pot features are chips in pot, chips to call, number of opponents, and position chips_in_pot = poker.getPotSize(state, nplayers) chips_to_call = poker.chipsToCall(state, my_id) my_chips_in_pot = poker.getSpent(state, my_id) pos = poker.getNumActions(state, state.round) pot_features = [my_chips_in_pot, chips_in_pot, chips_to_call, nremaining, pos] chip_features = [poker.getStack(self.game, i) - poker.getSpent(state, i) for i in range(nplayers) if not poker.getFolded(state, i)] s = sum(chip_features) chip_features = [c/float(s) for c in chip_features] action_probabilities = self.neural_net.eval(nremaining, card_features, pot_features, chip_features)[0] print card_features print action_probabilities action = poker.Action() action.type = np.random.choice(self.actions, 1, p=action_probabilities)[0] action.size = 0 raisevalid, minsize, maxsize = poker.raiseIsValid(self.game, state) if action.type == poker.RAISE and raisevalid: action.size = minsize # for limit, size can be anything elif action.type == poker.RAISE and not raisevalid: action.type = poker.CALL elif (poker.isValidAction(self.game, state, 0, action ) <= 0): action.type = poker.CALL print action.type, action.size assert(poker.isValidAction( self.game, state, 0, action ) > 0) return action
def what_should_i_do(self, my_id, state): board_cards = poker.get_board_cards(self.game, state) hole_cards = poker.get_hole_cards(self.game, state, my_id) action = poker.Action() action.type = poker.CALL action.size = 0 assert(poker.isValidAction(self.game, state, 0, action ) > 0) return action
def what_should_i_do(self, my_id, state): board_cards = poker.get_board_cards(self.game, state) hole_cards = poker.get_hole_cards(self.game, state, my_id) action = poker.Action() action.type = poker.CALL action.size = 0 raisevalid, minsize, maxsize = poker.raiseIsValid(self.game, state) if raisevalid: action.type = poker.RAISE action.size = minsize assert(poker.isValidAction( self.game, state, 0, action ) > 0) return action
def what_should_i_do(self, my_id, state): board_cards = poker.get_board_cards(self.game, state) hole_cards = poker.get_hole_cards(self.game, state, my_id) nplayers = self.game.numPlayers nremaining = poker.numActingPlayers(self.game, state) if nremaining == 1: action = poker.Action() action.type = poker.CALL action.size = 0 return action card_features = poker.calculate_card_features(nremaining, hole_cards, board_cards) # pot features are chips in pot, chips to call, number of opponents, and position chips_in_pot = poker.getPotSize(state, nplayers) chips_to_call = poker.chipsToCall(state, my_id) my_chips_in_pot = poker.getSpent(state, my_id) pos = poker.getNumActions(state, state.round) pot_features = [my_chips_in_pot * 0.01, chips_in_pot * 0.01, chips_to_call * 0.01, nremaining, pos] chip_features = [poker.getStack(self.game, i) - poker.getSpent(state, i) for i in range(nplayers) if not poker.getFolded(state, i)] s = sum(chip_features) chip_features = [c/float(s) for c in chip_features] action_output = self.neural_net.eval(nremaining, card_features, pot_features, chip_features)[0] action_probabilities = action_output[:3] # action_probabilities[0] *= 100 s = sum(action_probabilities) action_probabilities = action_probabilities / s raise_amount = int(action_output[3]) print card_features print action_probabilities print 'Raise amount=', raise_amount action = poker.Action() action.type = np.random.choice(self.actions, 1, p=action_probabilities)[0] action.size = 0 raisevalid, minsize, maxsize = poker.raiseIsValid(self.game, state) if action.type == poker.RAISE and raisevalid: if raise_amount < minsize: action.size = minsize elif raise_amount > maxsize: action.size = maxsize else: action.size = raise_amount elif action.type == poker.RAISE and not raisevalid: action.type = poker.CALL elif (poker.isValidAction(self.game, state, 0, action ) <= 0): action.type = poker.CALL if action.type == poker.RAISE and self.prev_action == poker.RAISE: action.type = poker.CALL action.size = 0 print action.type, action.size self.prev_action = action.type assert(poker.isValidAction( self.game, state, 0, action ) > 0) return action
def what_should_i_do(self, my_id, state): board_cards = poker.get_board_cards(self.game, state) hole_cards = poker.get_hole_cards(self.game, state, my_id) nplayers = self.game.numPlayers nremaining = poker.numActingPlayers(self.game, state) if nremaining == 1: action = poker.Action() action.type = poker.CALL action.size = 0 return action card_features = poker.calculate_card_features(nremaining, hole_cards, board_cards) # pot features are chips in pot, chips to call, number of opponents, and position chips_in_pot = poker.getPotSize(state, nplayers) chips_to_call = poker.chipsToCall(state, my_id) my_chips_in_pot = poker.getSpent(state, my_id) pos = poker.getNumActions(state, state.round) pot_features = [ my_chips_in_pot * 0.01, chips_in_pot * 0.01, chips_to_call * 0.01, nremaining, pos ] chip_features = [ poker.getStack(self.game, i) - poker.getSpent(state, i) for i in range(nplayers) if not poker.getFolded(state, i) ] s = sum(chip_features) chip_features = [c / float(s) for c in chip_features] action_output = self.neural_net.eval(nremaining, card_features, pot_features, chip_features)[0] action_probabilities = action_output[:3] # action_probabilities[0] *= 100 s = sum(action_probabilities) action_probabilities = action_probabilities / s raise_amount = int(action_output[3]) print card_features print action_probabilities print 'Raise amount=', raise_amount action = poker.Action() action.type = np.random.choice(self.actions, 1, p=action_probabilities)[0] action.size = 0 raisevalid, minsize, maxsize = poker.raiseIsValid(self.game, state) if action.type == poker.RAISE and raisevalid: if raise_amount < minsize: action.size = minsize elif raise_amount > maxsize: action.size = maxsize else: action.size = raise_amount elif action.type == poker.RAISE and not raisevalid: action.type = poker.CALL elif (poker.isValidAction(self.game, state, 0, action) <= 0): action.type = poker.CALL if action.type == poker.RAISE and self.prev_action == poker.RAISE: action.type = poker.CALL action.size = 0 print action.type, action.size self.prev_action = action.type assert (poker.isValidAction(self.game, state, 0, action) > 0) return action