Beispiel #1
0
 def getFencePlacingImpactOnPaths(self, fencePlacing: FencePlacing):
     global TRACE
     TRACE["Board.getFencePlacingImpactOnPaths"] += 1
     stateBefore = {}
     for player in self.game.players:
         path = Path.BreadthFirstSearch(self,
                                        player.pawn.coord,
                                        player.endPositions,
                                        ignorePawns=True)
         if path is None:
             print("Player %s is already blocked!" % (player.name))
             return None
         stateBefore[player.name] = len(path.moves)
     fence = Fence(self, None)
     fence.coord, fence.direction = fencePlacing.coord, fencePlacing.direction
     self.fences.append(fence)
     self.updateStoredValidPawnMovesIgnoringPawnsAfterFencePlacing(
         fencePlacing.coord, fencePlacing.direction)
     impact = {}
     for player in self.game.players:
         path = Path.BreadthFirstSearch(self,
                                        player.pawn.coord,
                                        player.endPositions,
                                        ignorePawns=True)
         if path is None:
             #print("Fence placing will block player %s" % (player.name))
             self.fences.pop()
             self.updateStoredValidPawnMovesIgnoringPawnsAfterFencePlacing(
                 fencePlacing.coord, fencePlacing.direction)
             raise PlayerPathObstructedException(player, fencePlacing)
         impact[player.name] = len(path.moves) - stateBefore[player.name]
     self.fences.pop()
     self.updateStoredValidPawnMovesIgnoringPawnsAfterFencePlacing(
         fencePlacing.coord, fencePlacing.direction)
     return impact
Beispiel #2
0
 def Fence_Distance(self, fencePlacing):
     global TRACE
     TRACE["Board.isFencePlacingBlocking"] += 1
     fence = Fence(self, None)
     fence.coord, fence.direction = fencePlacing.coord, fencePlacing.direction
     self.fences.append(fence)
     self.updateStoredValidPawnMovesIgnoringPawnsAfterFencePlacing(fencePlacing.coord, fencePlacing.direction)
     isBlocking = False
     n = 0
     for player in self.game.players:
         #print("Can player %s reach one of his goals with %s? " % (player.name, fencePlacing), end="")
         path = Path.BreadthFirstSearch(self, player.pawn.coord, player.endPositions, ignorePawns = True)
         if path is None:
             #print("NO")
             isBlocking = True
             break
         elif n == 0:
             p1 = Path.length(path)
             n = n + 1
         else:
             p2 = Path.length(path)
         #print("YES, through %s" % path)
     self.fences.pop()
     self.updateStoredValidPawnMovesIgnoringPawnsAfterFencePlacing(fencePlacing.coord, fencePlacing.direction)
     if isBlocking == True:
         return(-100)
     return(p2 - p1)
Beispiel #3
0
 def isValidFencePlacing(self, coord, direction):
     global TRACE
     TRACE["Board.isValidFencePlacing"] += 1
     checkedFence = Fence(self, None)
     checkedFence.coord = coord
     checkedFence.direction = direction
     if not self.isAtTopEdge(coord) and not self.isAtRightEdge(coord) and direction == Fence.DIRECTION.HORIZONTAL and not self.hasFenceAtTop(coord) and not self.hasFenceAtTop(coord.right()):
         crossingFenceCoord = coord.top().right()
         for fence in self.fences:
             if fence.coord == crossingFenceCoord and fence.direction == Fence.DIRECTION.VERTICAL:
                 self.fences.pop()
                 return False
         self.fences.append(checkedFence)
         for player in self.game.players:
             if Path.BreadthFirstSearch(self, player.pawn.coord, player.endPositions) is None:
                 self.fences.pop()
                 return False
         self.fences.pop()
         return True
     if not self.isAtLeftEdge(coord) and not self.isAtBottomEdge(coord) and direction == Fence.DIRECTION.VERTICAL and not self.hasFenceAtLeft(coord) and not self.hasFenceAtLeft(coord.bottom()):
         crossingFenceCoord = coord.bottom().left()
         for fence in self.fences:
             if fence.coord == crossingFenceCoord and fence.direction == Fence.DIRECTION.HORIZONTAL:
                 self.fences.pop()
                 return False
         self.fences.append(checkedFence)
         for player in self.game.players:
             if Path.BreadthFirstSearch(self, player.pawn.coord, player.endPositions) is None:
                 self.fences.pop()
                 return False
         self.fences.pop()
         return True
     return False
Beispiel #4
0
 def hideValidFencePlacings(self, player, validPlacings=None):
     if not INTERFACE:
         return
     if validPlacings is None:
         validPlacings = self.storedValidFencePlacings  #self.validFencePlacings()
     for validPlacing in validPlacings:
         possibleFence = Fence(self, player)
         possibleFence.coord, possibleFence.direction = validPlacing.coord, validPlacing.direction
         possibleFence.draw(Color.WHITE.value)
         del possibleFence