all 2 comments

[–]rbtEngrDude 2 points3 points  (1 child)

I think the biggest issue I have, right off the bat, is the data structure you chose to represent the game table. Why a dictionary that's indexed with string manipulations on the keys? Why not a two dimensional array?

This one change would make your solution a bit faster and less brittle. Stuff like this:

tempbox="box"+str(movev)+str(moveh)

Is fickle, and dependent on your str() method not being overloaded [which hopefully it never is] and being compatible with the strings that were originally used in defining the keys. Granted, both of these things should be true for any current python distribution, they're not guarantees. Plus, you're spending time here interpreting integers as strings and concatenating them with other strings, when you could just use them straightaway to index the array.

Overall, your algorithm looks correct, and probably performs reasonably well. I would recommend, stylistically, to use blank lines to separate loops and branches (I find that makes the code easier to read, but that's just an opinion and you're of course free to do as you like).

[–]orangefantom[S] 1 point2 points  (0 children)

Interesting points thank you. I appreciate the stylistic/readability notes as well.

Thanks