May-22-2021, 12:05 AM
I was playing around with it. Look at line 56. Notice the indentation. That's wrong. Fix it.
Hint: add some print statements to your code. When I printed out the value, it was [n] where n was the last number I had typed. What happened to the others? Well, you wrote the wrong code.
To improve the user experience, I changed the input line to be
If you really want help, you have to tell us what values you typed in, so we can reproduce your experience. And it is worthwhile to explain what the purpose of the code is, so we know what it should do. It wouldn't hurt if you said "I expected the answer to be <answer value here>, but instead got an exception" so we know what was expected. You might indicate that the nodes form a tree structure, and explain how the index relates to the tree structure.
Hint: add some print statements to your code. When I printed out the value, it was [n] where n was the last number I had typed. What happened to the others? Well, you wrote the wrong code.
To improve the user experience, I changed the input line to be
y = int(input("Enter Leaf Value "+ str(i + 1) + "/" + str(x) + ": "))and I added this line just before your line 10 (the if depth == 3 line)
print("minmax(depth=", depth, ", nodeindex=", nodeIndex, ", ", maximizingPlayer, ", ", values, ", ", alpha, ", ", beta, ")" )I still get errors because I have no idea what the purpose of the code is, or what it is working on, but it is clear where your basic error is. Fix that (I did in mine). Here's my output:
Output:Enter total number of leaf nodes=4
Enter Leaf Value 1/4: 11
Enter Leaf Value 2/4: 12
Enter Leaf Value 3/4: 13
Enter Leaf Value 4/4: 14
minmax(depth= 0 , nodeindex= 0 , True , [11, 12, 13, 14] , -1000 , 1000 )
minmax(depth= 1 , nodeindex= 0 , False , [11, 12, 13, 14] , -1000 , 1000 )
minmax(depth= 2 , nodeindex= 0 , True , [11, 12, 13, 14] , -1000 , 1000 )
minmax(depth= 3 , nodeindex= 0 , False , [11, 12, 13, 14] , -1000 , 1000 )
minmax(depth= 3 , nodeindex= 1 , False , [11, 12, 13, 14] , 11 , 1000 )
minmax(depth= 2 , nodeindex= 1 , True , [11, 12, 13, 14] , -1000 , 12 )
minmax(depth= 3 , nodeindex= 2 , False , [11, 12, 13, 14] , -1000 , 12 )
minmax(depth= 1 , nodeindex= 1 , False , [11, 12, 13, 14] , 12 , 1000 )
minmax(depth= 2 , nodeindex= 2 , True , [11, 12, 13, 14] , 12 , 1000 )
minmax(depth= 3 , nodeindex= 4 , False , [11, 12, 13, 14] , 12 , 1000 )
The last printout shows a node index of 4, which is larger than any valid node index (1..3) of your array of values. If you really want help, you have to tell us what values you typed in, so we can reproduce your experience. And it is worthwhile to explain what the purpose of the code is, so we know what it should do. It wouldn't hurt if you said "I expected the answer to be <answer value here>, but instead got an exception" so we know what was expected. You might indicate that the nodes form a tree structure, and explain how the index relates to the tree structure.