def get_dir(state, max_depth):
#Possible directions and their corresponding scores so far
paths = {'w':1,'a':1,'s':1,'d':1}
#Rate each direction
for dir in paths:
#Takes a game state and a direction as input and returns
#a list of all possible states that could occur from moving in that direction
children = successors(state, dir)
if children:
children = [children[0][:10], children[1][:10]]
#Weight the probability of the each state depending on if a 2 on or a 4 was spawned
weights = {0:.9,1:.1}
for section in weights:
for board in children[section]:
#PROBLEM HERE
paths[dir] += rank_branch(board, max_depth, (weights[section]*(1/(num_empty(board)))))
else:
paths[dir] = False
我正在使用上面的函數來選擇一個方向在2048年移動。我試圖衡量每個狀態的啓發式排名的概率,我們將能夠達到該狀態。Miscalculating遞歸狀態概率
要做到這一點,在每一層我乘以一個瓦片產生的概率與它上面的數字(.9代表at和.1代表一個4)乘以它可能產生的地方的數量(空的瓷磚)。
我給這家代碼:
weights[section]*(1/(num_empty(board))))
當我打印出來的概率變量,它總是要高。它不斷地認爲我們能夠達到某個特定狀態的機率比真正的大?
這是在Python 2.x中,有沒有機會? – jonrsharpe
是的,但我從__future__ –
導入了部門,然後可以將其縮減爲[最小示例](http://stackoverflow.com/help/mcve),其中包含輸入以及預期和實際輸出?就目前而言,目前尚不清楚爲什麼你認爲存在問題,因此很難幫助你找到問題。 – jonrsharpe