Min Max Itrative Algorithm

 Min Max Algorithm

This is backtracking algorithm by nature but I try to make this algorithm using iterative manner using python. We mostly use this Min Max algorithm in games. This is scratch code using Numpy


import numpy as np
import math
arr=np.array([-1,8,-3,-1,2,1,-3,4])
k=0
def MinMax(temp1,minmax,h):
    for j in range(0,h):
        k=0
        for i in range(0,len(temp1)-1,2):
            if(minmax==1):
                temp1[k]=max(temp1[i],temp1[i+1])
                k=k+1
            else:
                temp1[k]=min(temp1[i],temp1[i+1])
                k=k+1
        if minmax==1:
            minmax=0
        else:
            minmax=1
    return temp1[0]
print(MinMax(arr,1,3))


Comments