예제 #1
0
 def __addPawnsToFieldIfField(self, field, pawns: Pawns, quantity: int):
     if not field:
         return
     for i in range(quantity):
         pawn = pawns.getPawnOutOfBoard()
         if pawn:
             field.addPawn(pawn)
예제 #2
0
 def setPawnsAtStartPositions(self, pawns: Pawns, player: Player):
     playerPawns = pawns.getPawnsForPlayer(player)
     for i in range(24):
         id = i + 1 if player.direction == 1 else 24 - i
         self.__addPawnsOnField(id, i, playerPawns, 1, 2)
         self.__addPawnsOnField(id, i, playerPawns, 12, 5)
         self.__addPawnsOnField(id, i, playerPawns, 17, 3)
         self.__addPawnsOnField(id, i, playerPawns, 19, 5)
예제 #3
0
class Field():
    id = None
    pawns = None

    def __init__(self, id):
        self.id = id
        self.pawns = Pawns()

    def addPawn(self, pawn: Pawn):
        pawn.fieldId = self.id
        self.pawns.append(pawn)

    def getPawnOnTop(self):
        return self.pawns.getLastPawnInList()

    def removePawnFromTop(self):
        self.pawns.pop()

    def accepts(self, pawn: Pawn) -> bool:
        color = GET_OPPOSITE_COLOR(pawn.color)
        return 2 > self.pawns.countPawnsInColor(color)

    def hasOnePawnToBeat(self, pawn: Pawn) -> bool:
        color = GET_OPPOSITE_COLOR(pawn.color)
        return self.pawns.countPawnsInColor(color) == 1
예제 #4
0
 def createInInitialState(self):
     self.dices = Dices()
     self.pawns = Pawns.createInitial()
     self.players = [Player.createWhitePlayer(), Player.createBlackPlayer()]
     self.fields = Fields()
     self.turn = self.players[0]
     self.winner = None
     self.moves = Moves()
     self.moveCountPerPlayer = 0
     self.fields.setInitialState()
     for player in self.players:
         self.fields.setPawnsAtStartPositions(self.pawns, player)
         player.pawns = self.pawns.getPawnsForPlayer(player)
     self.dices.roll()
     self.getMoves()
예제 #5
0
 def getPawnsFromBar(self):
     pawns = Pawns()
     for pawn in self.pawns:
         if pawn.fieldId in (0, 25):
             pawns.append(pawn)
     return pawns
예제 #6
0
 def __init__(self, direction, color, home):
     self.direction = direction
     self.color = color
     self.home = home
     self.pawns = Pawns()
     self.bar = 0 if direction == 1 else 25
예제 #7
0
 def getFieldsByPawns(self, pawns: Pawns):
     ids = pawns.getFieldIds()
     return self.getFieldsByIds(ids)
예제 #8
0
 def __init__(self, id):
     self.id = id
     self.pawns = Pawns()