ターンベースの戦略ゲーム (RISK など) で AI を動作させようとしています。私はAIプログラミングに少し慣れていませんが、私の問題は間違ったパラメーターまたは何かを渡しているだけかもしれません.問題; 回答をいただければ幸いです。問題は、どこかで (おそらく 'newBoard' の受け渡しで) 'newBoard' が大きな整数値に上書きされることだと思います。
##sectors array takes this form: [['Canada',[300,200],'',0,[1,2,12]],['Greenland',[600,120],'',0,[0,7]],['USA',[360,300],'',0,[0,3]],['Central America',[360,410],'',0,[2,4]],['South America',[480,510],'',0,[3,5]],['Brazil',[560,580],'',0,[4,6,15]],['Argentina',[490,700],'',0,[5]],['West Europe',[760,260],'',0,[1,8,9,15]],['East Europe',[875,260],'',0,[7,9,10,11,13]],['Scandanavia',[870,170],'',0,[7,8,10]],['West Russia',[970,220],'',0,[8,9,11,13]],['Central Russia',[1160,210],'',0,[10,12,13,19]],['Far East',[1350,220],'',0,[0,11,19]],['Central Asia',[1030,320],'',0,[8,10,11,14,18]],['Middle East',[970,380],'',0,[13,16]],['North Africa',[760,400],'',0,[5,7,16]],['Central Africa',[880,470],'',0,[15,14,17]],['South Africa',[880,610],'',0,[16,18]],['India',[1125,390],'',0,[13,17,19]],['East Asia',[1225,360],'',0,[11,12,13,18,20]],['Indonesia',[1290,510],'',0,[19,21]],['Australia',[1360,640],'',0,[20]]]
各サブリストのデータは次のとおりです: 名前、画面上の位置 (ここでは重要ではありません)、それを制御するプレーヤー (ランダム化)、人口、接続先の他のセクター
class Node(object):
def populateChildren(self,player,board):
print("start conditions: ",player,board)
newBoard=board
start=randomStart(board, player)
if self.depth>-1:
##[base case]
for i in board[start][4]:
newBoard[i][3]=(board[start][3]-board[i][3])
newBoard[start][3]=1
self.children.append(Node((self.depth)-1,-self.player,newBoard,self.treeVal(newBoard)))
else:
print("RECURSION END")
def treeVal(self,board):
if checkWin(board)==True:
return maxsize*self.player
elif checkWin:
return maxsize*-self.player
return 0
def __init__(self,depth,player,newBoard,value=0):
self.depth=depth
self.player=player
self.value=value
self.children=[]
self.populateChildren(player,newBoard)
def minMax(node,depth,player):
if depth==0 or abs(node.value)==maxsize:
return node.value
bestValue=maxsize*-playerNum
for i in range(0,5):
child=node.children[i]
value=MinMax(child,depth-1,-playerNum)
if abs(maxsize*playerNum-value)<abs(maxsize*playerNum-bestValue):
bestValue=value
return bestValue
def AIMove(Node,sectors):
newBoard=sectors
currentPlayer=-1
depth=10
looks=0
while looks<6:
Node.player=-1
node=Node(depth,currentPlayer,newBoard,value=0)
bestChoice=-100
bestValue=currentPlayer*maxsize
for i in range(len(node.children)):
child=node.children[i]
value=MinMax(child,depth,currentPlayer)
if (abs(currentPlayer*maxsize-value)<=abs(currentPlayer*maxsize-bestValue)):
bestValue=value
bestChoice=i
bestChoice+=1
looks+=1
抜けているものがある場合は、スレッドに必要な情報を追加して更新させていただきます。よろしくお願いいたします。