From 78528fbe8d1452405302824bb01710491f40824d Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Thu, 18 Dec 2025 09:02:39 +0000 Subject: [PATCH] Changes --- src/components/RentDivisionPuzzle.tsx | 124 ++++++++++++++++++-------- 1 file changed, 89 insertions(+), 35 deletions(-) diff --git a/src/components/RentDivisionPuzzle.tsx b/src/components/RentDivisionPuzzle.tsx index 8981580..0df46c9 100644 --- a/src/components/RentDivisionPuzzle.tsx +++ b/src/components/RentDivisionPuzzle.tsx @@ -2,6 +2,7 @@ import { useState, useMemo } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; +import { Slider } from "@/components/ui/slider"; import { Select, SelectContent, @@ -9,9 +10,10 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; -import { RefreshCw } from "lucide-react"; +import { RefreshCw, User, UserRound, Users, UserCheck } from "lucide-react"; const AGENTS = ["Alice", "Bob", "Charlie", "Dana"]; +const AGENT_ICONS = [User, UserRound, Users, UserCheck]; const ROOM_COLORS = [ "hsl(142, 70%, 45%)", // green "hsl(0, 70%, 50%)", // red @@ -31,13 +33,17 @@ const RentDivisionPuzzle = ({ onComplete }: RentDivisionPuzzleProps) => { ) ); + // Total rent (controlled by slider) + const [totalRent, setTotalRent] = useState(20); + // Rents for each room const [rents, setRents] = useState([5, 5, 5, 5]); // Allocation: assignment[agent] = room index (-1 = unassigned) const [assignment, setAssignment] = useState([-1, -1, -1, -1]); - const totalRent = useMemo(() => rents.reduce((a, b) => a + b, 0), [rents]); + const currentTotal = useMemo(() => rents.reduce((a, b) => a + b, 0), [rents]); + const rentDiff = totalRent - currentTotal; // Compute U-matrix: utility[agent][room] = valuation - rent const utilities = useMemo(() => { @@ -120,10 +126,25 @@ const RentDivisionPuzzle = ({ onComplete }: RentDivisionPuzzleProps) => { const resetAll = () => { randomizeValuations(); + setTotalRent(20); setRents([5, 5, 5, 5]); setAssignment([-1, -1, -1, -1]); }; + const handleTotalRentChange = (value: number[]) => { + const newTotal = value[0]; + setTotalRent(newTotal); + // Distribute evenly + const base = Math.floor(newTotal / 4); + const remainder = newTotal % 4; + setRents([ + base + (remainder > 0 ? 1 : 0), + base + (remainder > 1 ? 1 : 0), + base + (remainder > 2 ? 1 : 0), + base, + ]); + }; + const getAgentColor = (agentIdx: number) => { const room = assignment[agentIdx]; return room === -1 ? "hsl(0, 0%, 60%)" : ROOM_COLORS[room]; @@ -147,42 +168,75 @@ const RentDivisionPuzzle = ({ onComplete }: RentDivisionPuzzleProps) => { Agents & Rooms - -
+ + {/* Total Rent Slider */} +
+
+ Total Rent + ${totalRent} +
+ + {rentDiff !== 0 && ( +

0 ? 'text-amber-600' : 'text-destructive'}`}> + {rentDiff > 0 ? `+$${rentDiff} unallocated` : `-$${Math.abs(rentDiff)} over budget`} +

+ )} +
+ +
{/* Agents Column */}
Agents
- {AGENTS.map((name, idx) => ( -
-
- {name.slice(0, 2)} + {AGENTS.map((name, idx) => { + const Icon = AGENT_ICONS[idx]; + return ( +
+ + {name} + +
+ +
+
- -
- ))} + ); + })}
{/* Rooms Column */} @@ -193,7 +247,7 @@ const RentDivisionPuzzle = ({ onComplete }: RentDivisionPuzzleProps) => { {[0, 1, 2, 3].map((roomIdx) => (
{ type="number" value={rents[roomIdx]} onChange={(e) => handleRentChange(roomIdx, e.target.value)} - className="w-14 h-8 text-xs text-center" + className="w-12 h-8 text-xs text-center" min={0} max={99} /> @@ -215,7 +269,7 @@ const RentDivisionPuzzle = ({ onComplete }: RentDivisionPuzzleProps) => {
))}
- Total: ${totalRent} + Sum: ${currentTotal}