二十一点极小algortihm [英] Blackjack minimax algortihm

查看:220
本文介绍了二十一点极小algortihm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行二十一点游戏有极大极小树,计算概率,并自动播放依赖于这个概率。

假设,我们用1台玩,第一场比赛庄家需要: 5 和球员需要 5 7 从而以总比分为12的球员

在这种情况下,首先我试图检查所有可能的概率为球员的的决定。

如果玩家的代表

我在甲板上像这样保持卡: 甲板结构(K,V)K:卡号,V:卡计数

 {1:4,2:4,3:4,4:4,5:2,6:4,7:3,8:4,9:4,10 :16}
 

现在,经销商要经过数17.有些例子可能是这样的:

  5(基础卡)+ 1(11)+ 1 = 17(本手的可能性:4/49 * 3/4​​8)
5(基卡)+ 1(11)+ 2 = 18(本手的可能性:4/49 * 4/48)
......
5(基卡)+ 10 + 1 + 1 = 17(本手的可能性:四十九分之十六* 4/48 * 3/4​​8)
 

我的问题是,我怎么能计算出这一切的可能性,并计算是否有球员决定站在最后的可能性。我想不通我怎么能codeD号这些的组合。

编辑:

我发现这个code的计算可能的组合。它类似于我的样子。我需要改变这个我的问题,我希望我能做到这一点。

高清subset_sum(数字,目标,偏= []):     S = SUM(部分)

 #检查,如果部分之和等于目标
如果s ==目标:
    打印和(%s)=%s的%(部分,目标)
如果S> =目标:
    返回#如果我们达到多少为什么还要继续

因为我在范围内(LEN(数字)):
    N =数字[I]
    剩下=号[I + 1:]
    subset_sum(剩余,目标,偏+ n])的
 

如果名称 ==主要:     subset_sum([3,9,8,4,5,7,10],15)

  #Outputs:
#sum([3,8,4])= 15
#sum([3,5,7])= 15
#sum([8,7])= 15
#sum([5,10])= 15
 

解决方案

这游戏是不是一个真正的局面极小。

在极小,两名球员做出这是从一个已知的位置决定的动作,并考虑到在确定其最佳动作对方球员的举动。

由于该例子中有两个玩家时,播放器(谁实际上并不在他改变板的除了决定是否站立或不状态感测移动)和经销商(谁只使移动随机地),在一个未知的板状态,随机选择,极小具体地说,不能使用。

在这种情况下,算法将工作得相当好。将开始与5和加入7-:

 基地= 5
卡= [7]
 

使用下面的公式:

 如果总和(卡)+基地< 16:
  击中()
其他:
  如果evalStand()> minStandChance:
    击中()
 

这是没有必要计算卡的树,而真实的,因为玩家需要反正拿到另一张卡。

在此之后,得到后站立的概率:

 高清evalStand():
  手=基地+ SUM(卡)
  金额= []
  对于cardValue,算上cards.items():
    因为我在范围内(计数):
      sums.append(cardValue +手)
  ([在款项我应该为,如果我和LT = 21])返回LEN /浮点(LEN(款项))
 

简单地过滤掉可能的双手,将仍然得到球员和LT的比例= 21。常用的策略,在这场比赛中,以蠕变对21这个模拟它。如果站在下一轮后的概率小于,比如说0.5,玩家可以停止获取卡。

另外,这种情况是不好的极大极小,但这应该是一个不错的替代解决方案。

编辑:

由于@NickLarsen指出, minStandChance 重presents启发式。没有一个变量,它是100%准确,但可以根据你想要多大的风险的AI玩进行调整。 (接近0是有风险的,越接近1是保守的)。

I am implementing a blackjack game with minimax tree which calculates the probabilities and play automatically depend on this probabilities.

Assume that, we play with 1 deck and the first game dealer takes : '5' and player takes '5 7' so the total score is 12 for player.

In this case, first i am trying to check all possible probabilities for player's stand decision.

If player stands :

My remain cards in deck like this : Structure of deck(K,V) K : card number, V: count of card

{1: 4, 2: 4, 3: 4, 4: 4, 5: 2, 6: 4, 7: 3, 8: 4, 9: 4, 10: 16}

Now, dealer should pass the number 17. Some examples can be like this :

5(base card) + 1(11) + 1 = 17  (possibility of this hand : 4/49 * 3/48)
5(base card) + 1(11) + 2 = 18  (possibility of this hand : 4/49 * 4/48)
......
5 (base card) + 10 + 1 + 1 = 17 (possibility of this hand : 16/49 * 4/48 * 3/48)

My question is, how can i calculate all this possibilities and calculate the final possibility of if player decision is standing. I cannot figure out how can i coded these combination of numbers.

EDIT :

I found out this code which calculate the possible combinations. It is similar what I look like. I need to change this for my problem, I hope I can do it.

def subset_sum(numbers, target, partial=[]): s = sum(partial)

# check if the partial sum is equals to target
if s == target: 
    print "sum(%s)=%s" % (partial, target)
if s >= target:
    return  # if we reach the number why bother to continue

for i in range(len(numbers)):
    n = numbers[i]
    remaining = numbers[i+1:]
    subset_sum(remaining, target, partial + [n]) 

if name == "main": subset_sum([3,9,8,4,5,7,10],15)

#Outputs:
#sum([3, 8, 4])=15
#sum([3, 5, 7])=15
#sum([8, 7])=15
#sum([5, 10])=15

解决方案

This game is not really a situation for minimax.

In minimax, two players make moves which are determined from a known position, and take into account the move of the other player in determining their best moves.

Since this example has two players, the Player (who does not actually move in the sense that he changes the state of the board except to decide whether to stand or not) and the Dealer (who only makes moves randomly), in an unknown board state with random options, minimax specifically cannot be used.

In this case, an algorithm that would work fairly well would be to start with the 5 and the added 7:

base = 5
cards = [7]

Using the following formula:

if sum(cards) + base < 16:
  hit()
else:
  if evalStand() > minStandChance:
    hit()

it is not necessary to calculate the card tree while true, since the player needs to get another card anyway.

After that, getting a probability of standing after that:

def evalStand():
  hand = base + sum(cards)
  sums = []
  for cardValue, count in cards.items():
    for i in range(count):
      sums.append(cardValue + hand)
  return len([i for i in sums if i <= 21])/float(len(sums))

Simply filtering out the ratio of possible hands that will still get the player <= 21. A commonly used strategy in this game is to creep up on 21. This emulates it. If the probability of standing after the next round is less than, say, 0.5, the player can stop getting cards.

Again, this situation is not good for minimax, but this should be a good alternate solution.

Edit:

As @NickLarsen has pointed out, minStandChance represents a heuristic. There is not a variable that is 100% accurate, but can be adjusted according to how much risk you want the AI to play with. (closer to 0 is risky, closer to 1 is conservative).

这篇关于二十一点极小algortihm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆