Advertisement
Guest User

Untitled

a guest
Oct 11th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. def evaluate(board, w = defaultWeights):
  2.     # Extract height and width and create a board that is more
  3.     # suitable for evaluation
  4.     height = len(board) - 1
  5.     width = len(board[0])
  6.     evalboard = copy.copy(list(reversed(board[0:height])))
  7.  
  8.     # Remove full rows
  9.     clearedRows = 0
  10.     while True:
  11.         for h in range(height):
  12.             if 0 not in evalboard[h]:
  13.                 del evalboard[h]
  14.                 evalboard = copy.copy(evalboard + [[0]*width])
  15.                 clearedRows += 1
  16.                 break
  17.         else:
  18.             break
  19.  
  20.     # Extract height of each column
  21.     evalboard = [list(r) for r in evalboard]
  22.     columnHeight = [0]*width
  23.     for c in range(width):
  24.         # Works if I add the assert!!!
  25.         #assert height == 20
  26.         h = height-1
  27.         while h > 0:
  28.             if evalboard[h][c] != 0:
  29.                 break
  30.             h -= 1
  31.         # Set to h + 1 since we convert from zero-index to one-index
  32.         columnHeight[c] = h + 1
  33.     # Get the max height as well
  34.     print(evalboard)
  35.     print('columnh', columnHeight, 'height', height, 'width', width)
  36.     maxHeight = max(columnHeight)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement