Personal tools

Eth1winter pygame example

From Eth0Wiki

Revision as of 20:10, 31 January 2009 by Elmer (talk | contribs) (So I named these things wrong... and I fixed it)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
def AreaMax(input_field):
  field_strings = input_field.splitlines()
  field_strings.reverse()
  field = []
  for line in field_strings:
    field.append([int(number) for number in line.split()])
  max_score = 0
  max_coord = ()
  for y_coord in range(1, 14):
    for x_coord in range(1, 14):
      score = AreaScore(field, x_coord, y_coord)
      if score > max_score:
        max_score = score
        max_coord = (x_coord + 1, y_coord + 1)
  return max_score, max_coord

def AreaScore(field, x_coord, y_coord):
  neighbours = [(x_coord + x, y_coord + y) for x in range(-1, 2)
                for y in range (-1, 2) if not x == y == 0]
  values = [field[y][x] for x, y in neighbours]
  score = 0
  for value in values:
    if value % 2 == 1:
      score = score - value
    else:
      score = score + value
  return score