Skip to content

Commit 86d4e0d

Browse files
committed
feat: support up to 30 players
1 parent 7b0c194 commit 86d4e0d

4 files changed

Lines changed: 114 additions & 62 deletions

File tree

src/config/GameConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface Vec2 { x: number; y: number; }
2323
export const GameConfig = {
2424
TOTAL_TICKS: 256,
2525

26+
MAX_PLAYERS: 30,
27+
2628
CANVAS: {
2729
BOX_SIZE: 20,
2830
ROWS: 30,

src/factories/EntityFactory.ts

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
APIDecisionStrategy,
1010
PlayerDecisionStrategy,
1111
} from "../strategies/SnakeDecisionStrategies";
12-
import { simpleAIAlgorithm, greedyAIAlgorithm } from "../ai/SnakeAI";
1312
import { GameState } from "../types/GameState";
1413
import { ParameterizedAIDecisionStrategy } from "../strategies/ChasingDecisionStrategy";
1514
import { advancedAIAlgorithm } from "../ai/AdvancedSnakeAI";
@@ -52,10 +51,35 @@ export class EntityFactory {
5251
// First color is reserved for the primary/player snake
5352
const snakeColors = [
5453
GameConfig.COLORS.PLAYER,
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'
54+
"#e6194B",
55+
"#3cb44b",
56+
"#4363d8",
57+
"#f58231",
58+
"#911eb4",
59+
"#46f0f0",
60+
"#f032e6",
61+
"#bcf60c",
62+
"#fabebe",
63+
"#008080",
64+
"#e6beff",
65+
"#9A6324",
66+
"#fffac8",
67+
"#800000",
68+
"#aaffc3",
69+
"#808000",
70+
"#ffd8b1",
71+
"#000075",
72+
"#808080",
73+
"#ffe119",
74+
"#469990",
75+
"#dcbeff",
76+
"#a9a9a9",
77+
"#66c2a5",
78+
"#ff7f00",
79+
"#6a3d9a",
80+
"#b15928",
81+
"#17becf",
82+
"#8da0cb",
5983
];
6084

6185
if (!selectedUsers || selectedUsers.length === 0) {
@@ -68,14 +92,14 @@ export class EntityFactory {
6892
const angle = index * angleStep;
6993
const colorIndex = index % snakeColors.length;
7094
const snake = this.createApiControlledSnake(
71-
radius,
72-
angle,
73-
snakeColors[colorIndex],
74-
clock,
75-
coordinator,
76-
gameSessionId,
77-
user,
78-
);
95+
radius,
96+
angle,
97+
snakeColors[colorIndex],
98+
clock,
99+
coordinator,
100+
gameSessionId,
101+
user
102+
);
79103
// 为本局分配从1开始的编号,存入元数据
80104
snake.setMetadata({ matchNumber: index + 1 });
81105
snakes.push(snake);
@@ -94,7 +118,7 @@ export class EntityFactory {
94118
clock: GameClock,
95119
coordinator: DecisionRequestCoordinator,
96120
gameSessionId: string,
97-
userData?: Player,
121+
userData?: Player
98122
): Snake {
99123
const { x, y } = this.calculatePosition(radius, angle);
100124
const direction = this.getInitialDirection(x, y);

0 commit comments

Comments
 (0)