From 23637eb5470c79c7f4a5ef47053766c24851fe1f Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Thu, 21 Aug 2025 11:34:27 +0000 Subject: [PATCH] Update Bulgarian Solitaire Modify the Bulgarian Solitaire component to send double-clicked boxes to the last-used column. --- src/components/BulgarianSolitaire.tsx | 30 ++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/components/BulgarianSolitaire.tsx b/src/components/BulgarianSolitaire.tsx index 15571df..4dc5770 100644 --- a/src/components/BulgarianSolitaire.tsx +++ b/src/components/BulgarianSolitaire.tsx @@ -23,6 +23,7 @@ const BulgarianSolitaire: React.FC = ({ showSocialShare const [isComplete, setIsComplete] = useState(false); const [highlightedBoxes, setHighlightedBoxes] = useState>(new Set()); const [isAnimating, setIsAnimating] = useState(false); + const [lastUsedColumn, setLastUsedColumn] = useState(null); const totalBoxes = (n * (n + 1)) / 2; @@ -72,6 +73,8 @@ const BulgarianSolitaire: React.FC = ({ showSocialShare b.id === draggedBox ? { ...b, columnIndex } : b )); + // Track last used column + setLastUsedColumn(columnIndex); setDraggedBox(null); }; @@ -99,15 +102,28 @@ const BulgarianSolitaire: React.FC = ({ showSocialShare const box = boxes.find(b => b.id === boxId); if (!box || box.columnIndex === null) return; - // Remove from column + // Remove from current column setColumns(prev => prev.map((col, idx) => idx === box.columnIndex ? col.filter(id => id !== boxId) : col )); - // Return to container - setBoxes(prev => prev.map(b => - b.id === boxId ? { ...b, columnIndex: null } : b - )); + // Move to last used column or container if no last used column + if (lastUsedColumn !== null && lastUsedColumn !== box.columnIndex) { + // Add to last used column + setColumns(prev => prev.map((col, idx) => + idx === lastUsedColumn ? [...col, boxId] : col + )); + + // Update box location + setBoxes(prev => prev.map(b => + b.id === boxId ? { ...b, columnIndex: lastUsedColumn } : b + )); + } else { + // Return to container if no last used column or same as current + setBoxes(prev => prev.map(b => + b.id === boxId ? { ...b, columnIndex: null } : b + )); + } }; const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); @@ -309,7 +325,7 @@ const BulgarianSolitaire: React.FC = ({ showSocialShare ? 'bg-red-500 text-white shadow-lg scale-110' : 'bg-primary text-primary-foreground hover:bg-primary/80' } ${isAnimating && highlightedBoxes.has(boxId) ? 'animate-pulse' : ''}`} - title="Drag to move or double-click to return to container" + title="Drag to move or double-click to move to last-used column" > ))} @@ -347,7 +363,7 @@ const BulgarianSolitaire: React.FC = ({ showSocialShare
  • Choose a value for n (2-6) using the slider
  • Drag the {totalBoxes} boxes from the container into any of the columns
  • Drag boxes between columns to rearrange them as needed
  • -
  • Drag boxes back to the container or double-click any box in a column to return it
  • +
  • Drag boxes back to the container or double-click any box in a column to move it to the last-used column
  • Once all boxes are placed in columns, click "Play" to start the simulation
  • Watch as the algorithm takes one box from each non-empty column to form a new column
  • The process continues until reaching the triangular configuration: columns of sizes 1, 2, 3, ..., n