diff --git a/test/load-bot.constants.ts b/test/load-bot.constants.ts index 376e1fd..48a406f 100644 --- a/test/load-bot.constants.ts +++ b/test/load-bot.constants.ts @@ -12,11 +12,14 @@ export const MOVE_TICK_MS = GAME_CONFIG.PLAYER_POSITION_UPDATE_MS; export const BOT_SPEED = GAME_CONFIG.PLAYER_SPEED; export const BOT_RADIUS = GAME_CONFIG.PLAYER_RADIUS; +export const BOMB_COOLDOWN_MS = GAME_CONFIG.BOMB_COOLDOWN_MS; +export const BOMB_FUSE_MS = GAME_CONFIG.BOMB_FUSE_MS; export const START_DELAY_MS = 800; export const MAX_X = GAME_CONFIG.GRID_COLS; export const MAX_Y = GAME_CONFIG.GRID_ROWS; export const BOT_CAN_MOVE = true; -export const ROOM_ID = "03"; +export const BOT_CAN_PLACE_BOMB = true; +export const ROOM_ID = "12"; export const START_GAME = true; export const SOCKET_PATH = NETWORK_CONFIG.SOCKET_IO_PATH; export const SOCKET_TRANSPORTS = [...NETWORK_CONFIG.SOCKET_TRANSPORTS]; diff --git a/test/load-bot.ts b/test/load-bot.ts index aaa57b9..df8930e 100644 --- a/test/load-bot.ts +++ b/test/load-bot.ts @@ -2,6 +2,7 @@ import { BOTS, BOT_CAN_MOVE, + BOT_CAN_PLACE_BOMB, DURATION_MS, JOIN_DELAY_MS, MAX_X, @@ -9,6 +10,8 @@ MOVE_TICK_MS, BOT_SPEED, BOT_RADIUS, + BOMB_COOLDOWN_MS, + BOMB_FUSE_MS, ROOM_ID, SOCKET_PATH, SOCKET_TRANSPORTS, @@ -38,6 +41,10 @@ y: number; }; +type GameStartPayload = { + startTime: number; +}; + // 実行後の簡易サマリ用カウンタ。 const stats: Stats = { connected: 0, @@ -69,6 +76,9 @@ moveTickMs: MOVE_TICK_MS, botSpeed: BOT_SPEED, botRadius: BOT_RADIUS, + bombCooldownMs: BOMB_COOLDOWN_MS, + bombFuseMs: BOMB_FUSE_MS, + botCanPlaceBomb: BOT_CAN_PLACE_BOMB, maxX: MAX_X, maxY: MAX_Y, }); @@ -115,6 +125,10 @@ let dirX = 1; let dirY = 0; let gameStarted = false; + let readySent = false; + let gameStartTimeMs: number | null = null; + let lastBombPlacedElapsedMs = Number.NEGATIVE_INFINITY; + let bombRequestSerial = 0; const updateDirection = () => { const angle = Math.random() * Math.PI * 2; @@ -149,6 +163,40 @@ socket.emit("move", { x: posX, y: posY }); counters.moveSent += 1; + + tryPlaceBomb(); + }; + + const getElapsedMs = (): number | null => { + if (gameStartTimeMs === null) { + return null; + } + + return Math.max(0, Date.now() - gameStartTimeMs); + }; + + const tryPlaceBomb = () => { + if (!BOT_CAN_PLACE_BOMB || !gameStarted) { + return; + } + + const elapsedMs = getElapsedMs(); + if (elapsedMs === null) { + return; + } + + if (elapsedMs - lastBombPlacedElapsedMs < BOMB_COOLDOWN_MS) { + return; + } + + bombRequestSerial += 1; + socket.emit("place-bomb", { + requestId: `${index}-${bombRequestSerial}`, + x: posX, + y: posY, + explodeAtElapsedMs: elapsedMs + BOMB_FUSE_MS, + }); + lastBombPlacedElapsedMs = elapsedMs; }; socket.on("connect", () => { @@ -166,10 +214,23 @@ } }); - socket.on("game-start", () => { + socket.on("game-start", (payload?: GameStartPayload) => { counters.gameStarts += 1; gameStarted = true; - socket.emit("ready-for-game"); + if ( + payload && + typeof payload.startTime === "number" && + Number.isFinite(payload.startTime) + ) { + gameStartTimeMs = payload.startTime; + } else if (gameStartTimeMs === null) { + gameStartTimeMs = Date.now(); + } + + if (!readySent) { + socket.emit("ready-for-game"); + readySent = true; + } }); socket.on("current_players", (players: CurrentPlayer[]) => {