I have some values in my outerscope that I cannot access inside of my compvals function. How would I access these?
def compvals(comp_hits, values):
comp_hits = values
comptest(comp_hits, values)
return
I have some values in my outerscope that I cannot access inside of my compvals function. How would I access these?
def compvals(comp_hits, values):
comp_hits = values
comptest(comp_hits, values)
return
I have spent a while trying to piece this together. I cannot find anywhere in your code where anything is appended to comp_hits, maybe you could go to where you think something like comp_hits.append() might be and verify that it is there. It may be that this is being printed rather than saved. I think you should try to rewrite this code using this as a rough draft. Try doing these things this time around:
1) Try structuring the code so that your functions return something. You do not have to return something, but structuring your code in this way will make it easier to debug.
2) Try to refrain from using functions with long strands of ifs, elifs, and if-breaks. You should be able to find something logically equivalent but simpler. It looks like it may work, but the logic is hard to debug in case it does not.
3) Do not call the function you are defining inside itself. I think you were trying to have it restart from the top, in the case of compshot(), if the random generated number generated a previously used position. You could get around a situation like this by using a while loop (not tested).
while gen == True:
row = random.randint(1,5)
column = chr(random.randint(65,69))
pos = column+str(row)
column = ord(column)-65
if pos not in already:
gen = False
4) Try to break functions into smaller ones.
5) Try to have a hierarchical structure in your helper functions. So for example, test() and pick() should not call the other and vice versa.
6) Save the board to a dictionary or data frame and manipulate it that way. It looks like you may be recalculating the board each time. I could be wrong. In general, it is good to avoid this because then if there is a problem updating the board you know right where to look!
This time when you write each function, you can pass in a few test cases to see if it works as expected. Hopefully, you will be able to append 'X' on the next time around. Sorry I could not be more help.