File tree Expand file tree Collapse file tree
src/main/java/wagemaker/uk/fence Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -230,15 +230,15 @@ private Rectangle detectRectangularPattern(Point newPos) {
230230 return null ;
231231 }
232232
233- // Get all current fence positions including the new position
234- Set < Point > allPositions = new HashSet <>( placedFences . keySet ());
235- allPositions . add (newPos );
233+ // Only consider pieces connected to the new position
234+ // This ensures that separate fence holdings don't interfere with each other
235+ Set < Point > connectedPositions = findConnectedPieces (newPos );
236236
237237 // Find bounding rectangle
238- int minX = allPositions .stream ().mapToInt (p -> p .x ).min ().orElse (0 );
239- int maxX = allPositions .stream ().mapToInt (p -> p .x ).max ().orElse (0 );
240- int minY = allPositions .stream ().mapToInt (p -> p .y ).min ().orElse (0 );
241- int maxY = allPositions .stream ().mapToInt (p -> p .y ).max ().orElse (0 );
238+ int minX = connectedPositions .stream ().mapToInt (p -> p .x ).min ().orElse (0 );
239+ int maxX = connectedPositions .stream ().mapToInt (p -> p .x ).max ().orElse (0 );
240+ int minY = connectedPositions .stream ().mapToInt (p -> p .y ).min ().orElse (0 );
241+ int maxY = connectedPositions .stream ().mapToInt (p -> p .y ).max ().orElse (0 );
242242
243243 int width = maxX - minX + 1 ;
244244 int height = maxY - minY + 1 ;
You can’t perform that action at this time.
0 commit comments