view scripts/partition_helper @ 362:cc8be536a7fc

Add ability to play uncurated levels via the command line.
author Simon Cross <hodgestar@gmail.com>
date Sat, 17 Sep 2011 00:03:46 +0200
parents 46565a047ac0
children 20b424c5c1ef
line wrap: on
line source

#!/usr/bin/env python


def partition(total, parts, sepwidth=1):
    seps = parts - 1
    space = total - 2 - sepwidth * seps
    return float(space) / parts


def find_partitions(num, sepwidth):
    partitions = []
    for i in range(2, num):
        size = partition(num, i, sepwidth)
        if size > 0 and int(size) == size:
            partitions.append((i, size))
    return partitions


if __name__ == "__main__":
    height = ["FLOOR HEIGHT: PARTS x PART HEIGHT"]
    for sepwidth in range(1, 28):
        partitions = find_partitions(30, sepwidth)
        if partitions:
            height.append("%s: %s" % (sepwidth,
            " ".join([" %dx%d" % (i, size) for (i, size) in partitions])))

    width = ["COLUMN WIDTH: PARTS x PART WIDTH"]
    for sepwidth in range(1, 38):
        partitions = find_partitions(40, sepwidth)
        if partitions:
            width.append("%s: %s" % (sepwidth,
            " ".join([" %dx%d" % (i, size) for (i, size) in partitions])))

    height.extend([""] * 6)
    height = [l.ljust(50) for l in height]
    pairs = zip(height, width)
    print "\n".join(["%s %s" % p for p in pairs])