Jan-04-2018, 01:59 PM
Quote:My board is stored as a 2d array, so the function will use that.Your board is a list of strings; that's different than a 2-d array. I may sound like a pedantic ass, but it's important to be precise when talking about code. It also explains why you have to calculate the position with this
pos=(4*x)-2
.Putting that aside, when someone adds a checker start with the position of the new checker and see if it makes a vertical, horizontal, or diagonal line. I would break the code up into individual functions for each check:
def check_for_win(board, starting_pos): if check_vertical(board, start_pos): return True if check_horizontal(board, starting_pos): return True if check_diagonal(board, starting_pos): return True return FalseYou could, of course, combine those with an
or
but I think this is easier to read. Each check_* function then just has a loop that changes the appropriate index to check of the counter is the same as the one in starting_pos.