Source

aichallenge-py / helpers.py

Full commit
# -*- coding: utf-8 -*-
#
#  helpers.py
#  aichallenge-py
#
#  Created by Lars Yencken on 2011-11-09.
#  Copyright 2011 Lars Yencken. All rights reserved.
#

"""
Helpers for debugging the bot.
"""

import Image
import numpy as np

def dump_grayscale_image(m, filename):
    rows, cols = m.shape
    im = Image.new('1', (cols, rows))
    for y, x in zip(*np.nonzero(m)):
        im.putpixel((x, y), 1)
    im.save(filename)