0

I'm trying to figure what the values of xcoord_orig and ycoord_orig are when the last conditional statement is true i.e. when board[xcoordT][ycoordT] == computer. I feel that as I have it right now, I'm simply printing their values if the conditional statement is true. But what I really want are the values of xcoord_orig and ycoord_orig under the first loop at the point where the last conditional statement is true. I'm not sure if this is clear but I thought I would ask.

for num in range(8):
 for i in range(len(valid_list)):
 xcoord_orig = valid_list[i][0]
 ycoord_orig = valid_list[i][1]
 xcoord1 = valid_list[i][0] + num_list[num]
 ycoord1 = valid_list[i][1] + num_list2[num]
 if 0 <= xcoord1 <= 7 and 0 <= ycoord1 <= 7:
 piece = board[xcoord1][ycoord1]
 if piece == player:
 move_list = []
 for i in range(2,8):
 xcoordT = xcoord_orig
 ycoordT = ycoord_orig - i
 print(xcoord_orig, ycoord_orig)
 if board[xcoordT][ycoordT] == computer:
 move_list.append([xcoordT, ycoordT])
 print(xcoord_orig, ycoord_orig)
AJ.
28.3k19 gold badges88 silver badges98 bronze badges
asked May 17, 2011 at 21:33
1
  • So did you want the actual values in separate variables? I'm a bit confused mate. Commented May 17, 2011 at 21:49

1 Answer 1

2

This

for i in range(len(valid_list)):
 ... 
 for i in range(2,8):

Is epic fail. It can't be correct.

answered May 17, 2011 at 22:20
4
  • you mean reusing i or something else? Commented May 17, 2011 at 22:46
  • @seekingjannah: You can't reuse variables randomly. Variables have meaning which you should be able to state clearly, completely and precisely. And the meaning of a variable in a given scope cannot ever change. i can't mean two different things in the two loops. That's just impossible to make sense of. Commented May 17, 2011 at 22:49
  • Thanks for pointing out the reusing variables error. I changed it but it still doesn't fix my problem :(. In fact, it doesn't seem to make any difference at all. Commented May 17, 2011 at 23:06
  • 1
    I'm not saying reusing variables is a smart idea, but since the inner for block doesn't reference the outer value of i, and there is no code in the outer block after the inner one, it doesn't matter in this case. Commented Aug 8, 2014 at 21:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.