Created
November 8, 2016 22:59
-
-
Save simmsb/3fd4b26d18140367591295a28b6e9dd2 to your computer and use it in GitHub Desktop.
rewriting aqa 2015 code
This file contains 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
class pieces(object): | |
piece_dict = {} | |
def piece(func): | |
def predicate(): | |
piece_dict[func.__name__] = func | |
return predicate | |
return func | |
class vec2d(object): | |
def __init__(self, x, y): | |
self.x = x | |
self.y = y | |
def __add__(self, vec): | |
try: | |
return vec2d( | |
self.x + vec.x, | |
self.y + vec.y) | |
except: | |
raise ValueError("cannot add non type vec2d to vec2d") | |
def __sub__(self, vec): | |
try: | |
return vec2d( | |
self.x - vec.x, | |
self.y - vec.y) | |
except: | |
raise ValueError("cannot add non type vec2d to vec2d") | |
def __eq__(self, vec): | |
return self.x == vec.x and self.y == vec.y | |
def __str__(self): | |
return "x: {0.x}, y: {0.y}".format(self) | |
class piece(object): | |
def __init__(self, x, y, name, owner): | |
self.location = vec2d(x,y) | |
self.name = name | |
self.owner = owner | |
def get_loc(self): | |
return self.location | |
def get_loc_xy(self): | |
return self.location.x, self.location.y | |
def test_location(self, location): | |
if self.location == location: | |
return self # return self if at location | |
def check_self_locations(self, *location): | |
return not all(map(lambda x: self.location == x, locations)) | |
class somepiece(piece): | |
def __init__(self, x, y, owner): | |
super().__init__(x, y, "somepiece", owner) | |
def check_move(self, *otherPieces): | |
# +1y -1y +1x -1x if any of own class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment