Add "Random Start" to Bulgarian Solitaire

Added a "Random Start" option to the Bulgarian Solitaire game, allowing players to begin with a randomized initial setup.
-edited src/components/BulgarianSolitaire.tsx
This commit is contained in:
gpt-engineer-app[bot] 2025-08-22 09:59:30 +00:00
parent 7ab27088a6
commit 6e6c8b5a42

View file

@ -285,6 +285,25 @@ const BulgarianSolitaire: React.FC<BulgarianSolitaireProps> = ({ showSocialShare
setIsAnimating(false);
};
const randomStart = () => {
// Reset first
reset();
// Randomly distribute all boxes into columns
const newBoxes: Box[] = [];
const newColumns = Array.from({ length: totalBoxes }, () => []);
for (let i = 0; i < totalBoxes; i++) {
// Pick a random column index (ensure we use at least some columns)
const columnIndex = Math.floor(Math.random() * Math.min(totalBoxes, 8)); // Limit to 8 columns for better visualization
newBoxes.push({ id: i, columnIndex });
newColumns[columnIndex].push(i);
}
setBoxes(newBoxes);
setColumns(newColumns);
};
const containerBoxes = boxes.filter(box => box.columnIndex === null);
const handleBackgroundClick = () => {
@ -321,6 +340,9 @@ const BulgarianSolitaire: React.FC<BulgarianSolitaireProps> = ({ showSocialShare
<Button onClick={reset} variant="outline" disabled={isPlaying}>
Reset
</Button>
<Button onClick={randomStart} variant="default" disabled={isPlaying}>
Random Start
</Button>
</div>
{/* Container */}