I have a 2d list with random values [[#$%$],[$#$%],[#@$$],[#$%@]] This is displayed to user as:
# $ % $
$ # $ %
# @ $ $
# $ % @
The user enters a row number (0-3) and a column number (0-3). How would I check how many consecutive matching characters there are from that point. Matches can be vertical or horizontal from the selected point. must have 2 of the same character in a row to be considered a match.
For example if the user enters row 2 column 2 it would "pick" the bracketed value (it doesn't actually show this part):
# $ % $
$ # $ %
# @($)$
# $ % @
and then look for matching symbols horizontally or vertically from it. In this case it should make score =2 because there is 1 dollar sign above and 1 dollar sign to the right of the user point. After matching the 3 symbols, those symbols should be changed from '$' to 'x' Please help. This is what I have so far
#checking matches right
count=0
for i in range(col, len(board)):
if(board[row][i] == board[row][col]):
count+=1
#checking matches left
for i in range(col, -1, -1):
if(board[row][i] == board[row][col]):
count+=1
#checking matches up
for i in range(row, -1, -1):
if board[i][col] == board[row][col]:
count+=1
#checking matches down
for i in range(row, len(board)):
if(board[i][col] == board[row][col]):
count+= 1
return count