Пример #1
0
    def apply(self, board: Board):
        if getRelativePointLocation(self.color, self.start) > self.die:
            raise IllegalMoveException("Move cannot be made given the die value " + str(self.die))
        elif getRelativePointLocation(self.color, self.start) < self.die:
            if board.farthestBack(self.color) != self.start:
                raise IllegalMoveException(
                    "You must move the farthest back piece off that you can with die " + str(self.die))

        scratch = board.__deepcopy__()

        # VALID MOVEMENT
        scratch.removeFromLocation(self.color, self.start)
        scratch.moveOff(self.color)

        return scratch
Пример #2
0
 def __init__(self, color: str, die: int, start: int):
     self.color = color
     self.die = die
     self.start = start
     self.end = None
     if not (1 <= self.start <= 24):
         raise IllegalMoveException("Invalid location")
Пример #3
0
 def __init__(self, color: str, start: int, end: int):
     self.color = color
     self.start = start
     self.end = end
     self.hit = False
     if (not (1 <= self.start <= 24)) or (not (1 <= self.end <= 24)):
         raise IllegalMoveException("Invalid location")
Пример #4
0
 def removeFromLocation(self, color, location):
     if self.colorAt(location) != color:
         raise IllegalMoveException(
             "Unexpected error - no pieces at location " + str(location) +
             " of color " + color)
     if color == BLACK:
         self.pointsContent[location] -= 1
         if self.pointsContent[location] == 0:
             self.blackCheckers.remove(location)
     elif color == WHITE:
         self.pointsContent[location] += 1
         if self.pointsContent[location] == 0:
             self.whiteCheckers.remove(location)
Пример #5
0
 def moveToLocation(self, color, location):
     if self.colorAt(location) == getOtherColor(color):
         raise IllegalMoveException(
             "Unexpected error - other color pieces at location " +
             str(location) + " of color " + getOtherColor(color))
     if color == BLACK:
         self.pointsContent[location] += 1
         if self.pointsContent[location] == 1:
             self.blackCheckers.add(location)
     elif color == WHITE:
         self.pointsContent[location] -= 1
         if self.pointsContent[location] == -1:
             self.whiteCheckers.add(location)
Пример #6
0
    def apply(self, board: Board):
        if board.numAt(getOtherColor(self.color), self.end) > 1:
            raise IllegalMoveException("Other player occupies the location " + str(self.end))

        scratch = board.__deepcopy__()

        # VALID MOVEMENT, check if hit
        if scratch.numAt(getOtherColor(self.color), self.end) == 1:
            scratch.removeFromLocation(getOtherColor(self.color), self.end)
            scratch.moveToBar(getOtherColor(self.color))
            self.hit = True

        scratch.moveFromBar(self.color)
        scratch.moveToLocation(self.color, self.end)

        return scratch
Пример #7
0
 def __init__(self, color: str, end: int):
     self.color = color
     self.end = end
     self.hit = False
     if not (1 <= self.end <= 24):
         raise IllegalMoveException("Invalid location")