Personal tools

Eth1winter pygame test

From Eth0Wiki

Revision as of 19:46, 17 January 2009 by Elmer (talk | contribs) (New page: <pre> 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 l...)
(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