From 8115d268245c2de771d204555a0785957f4eed8e Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Mon, 8 Dec 2025 10:00:39 +0000 Subject: [PATCH] Changes --- src/components/DominoRetilingPuzzle.tsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/DominoRetilingPuzzle.tsx b/src/components/DominoRetilingPuzzle.tsx index 4ded952..68e7368 100644 --- a/src/components/DominoRetilingPuzzle.tsx +++ b/src/components/DominoRetilingPuzzle.tsx @@ -161,17 +161,26 @@ const DominoRetilingPuzzle: React.FC = ({ showSocialS const handleCellHover = (row: number, col: number) => { if (selectedDomino === null) return; - // Check which placements are valid for this cell - const canH = canPlaceDomino(row, col, true, selectedDomino); - const canV = canPlaceDomino(row, col, false, selectedDomino); + // Check all possible placements where this cell could be part of a domino + // A domino can be placed with this cell as the first cell, or as the second cell + + // Horizontal placements: domino at (row, col) or (row, col-1) + const canH_start = canPlaceDomino(row, col, true, selectedDomino); + const canH_end = col > 0 && canPlaceDomino(row, col - 1, true, selectedDomino); + + // Vertical placements: domino at (row, col) or (row-1, col) + const canV_start = canPlaceDomino(row, col, false, selectedDomino); + const canV_end = row > 0 && canPlaceDomino(row - 1, col, false, selectedDomino); - if (canH && canV) { - // Prefer horizontal + // Prioritize: horizontal starting here, horizontal ending here, vertical starting here, vertical ending here + if (canH_start) { setHoverPlacement({ row, col, isHorizontal: true }); - } else if (canH) { - setHoverPlacement({ row, col, isHorizontal: true }); - } else if (canV) { + } else if (canH_end) { + setHoverPlacement({ row, col: col - 1, isHorizontal: true }); + } else if (canV_start) { setHoverPlacement({ row, col, isHorizontal: false }); + } else if (canV_end) { + setHoverPlacement({ row: row - 1, col, isHorizontal: false }); } else { setHoverPlacement(null); }