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)
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)
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
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()
def getPawnsFromBar(self): pawns = Pawns() for pawn in self.pawns: if pawn.fieldId in (0, 25): pawns.append(pawn) return pawns
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
def getFieldsByPawns(self, pawns: Pawns): ids = pawns.getFieldIds() return self.getFieldsByIds(ids)
def __init__(self, id): self.id = id self.pawns = Pawns()