Created
November 7, 2013 15:53
-
-
Save mwhooker/7356899 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| from collections import namedtuple | |
| attack_vectors = ('melee', 'range', 'air') | |
| target_type = ('ground', 'air') | |
| dmg_type = ('single', 'area') | |
| Unit = namedtuple('Unit', ('hp', 'length', 'count', 'impl')) | |
| Defender = namedtuple('Defender', ('vector', 'target', 'range_', 'dps')) | |
| Resource = namedtuple('Resource', ('capacity', 'production')) | |
| Storage = namedtuple('Storage', ('capacity')) | |
| points = Unit(660, 3, 10, Resource(50000, 1900)), | |
| storage = { | |
| 'point': Unit(1650, 3, 4, Storage(100000)), | |
| 'townhall': Unit(2400, 4, 1, Storage(2000)) | |
| } | |
| defense_structures = { | |
| 'airground': Unit(550, 3, 3, Defender(target_type, 'single', range(11), 25)), | |
| 'splash': Unit(450, 3, 1, Defender('ground', 'area', range(4, 12), 5)), | |
| 'ground': Unit(550, 3, 3, Defender('ground', 'single', range(10), 19)), | |
| 'air': Unit(800, 3, 1, Defender('air', 'single', range(11), 80)), | |
| 'static': Unit(700, 1, 100, Defender('ground', 'single', range(1), 0)) | |
| } | |
| class Grid(object): | |
| def __init__(self, length): | |
| self.grid = [[None for i in range(length)] for i in range(length)] | |
| self.length = length | |
| def print_grid(self): | |
| for row in self.grid: | |
| for cell in row: | |
| if cell is None: | |
| cell = ' ' | |
| print "[%s] " % str(cell)[0], | |
| print '' | |
| def fill(self, unit, x, y): | |
| assert self.length - (x + unit.length) >= 0 | |
| assert self.length - (y + unit.length) >= 0 | |
| for i in xrange(unit.length): | |
| for j in xrange(unit.length): | |
| self.grid[x+i][y+j] = unit | |
| @property | |
| def center(self): | |
| return int(math.floor(self.length/2)) | |
| def fill_assets(grid): | |
| grid.fill(storage['townhall'], grid.center, grid.center) | |
| def fill_defense(grid): | |
| """goal is to provide an optimal value:defense ratio""" | |
| pass | |
| if __name__ == '__main__': | |
| g = Grid(25) | |
| fill_resources(g) | |
| g.print_grid() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment