Subscribe Us

Responsive Advertisement

Advertisement

For a given game tree, write a program to implement a game-playing algorithm that determines the best possible move for a player using the Minimax algorithm. Assume that both players play optimally


def tree(dept,indx,val,height,who):
    if height==dept:
        return val[indx]
    if who:
        return max(
            tree(dept+1,indx*2,val,height,False),
            tree(dept+1,indx*2+1,val,height,False)

        )
    else:
        return min(
            tree(dept+1,indx*2,val,height,True),
            tree(dept+1,indx*2+1,val,height,True)

        )

val=[1,2,3,4,5,6,7,8]
print("minmax : ",tree(0,0,val,3,True))

Post a Comment

0 Comments