Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

from Move import Move 

 

class Piece(object): 

def __init__(self, x, y, vertical): 

""" 

Initialize piece class 

 

@type x: integer 

@param x: x coordinate 

@type y: integer 

@param y: y coordinate 

@type vertical: boolean 

@param vertical: marks whether this piece can move vertically or not 

""" 

super(Piece, self).__init__() 

 

if type(x) != int or type(y) != int or (vertical != None and type(vertical) != bool): 

raise AttributeError("Incorrect types given for class Piece") 

 

self.x = x 

self.y = y 

self.isVertical = vertical 

 

def move(self, move): 

""" 

Move the piece if the given move is valid 

 

@type move: Move 

@param move: Move that will change the location of the piece 

""" 

if type(move) != Move: 

raise AttributeError("Incorrect type given to move a piece") 

 

if not move.isValid(): 

raise AttributeError("Move given is not valid and can't be used") 

 

if self.isVertical: 

if move.up == 0: 

raise AttributeError("Horizontal move given for piece that can only move vertically") 

elif move.right == 0: 

raise AttributeError("Vertical move given for piece that can only move horizontally") 

 

self.x += move.right 

self.y += move.up 

 

def copy(self): 

""" 

Create a copy of self. 

 

@rtype: Piece 

@return: Copy of this piece 

""" 

return Piece(self.x, self.y, self.isVertical)