fix: 代码审查问题修复 — rebuildBoard 参数修正 + 玩家座位号排序

This commit is contained in:
2026-06-23 11:28:27 +08:00
parent f85e23d545
commit 15bf6d0531
2 changed files with 6 additions and 2 deletions

View File

@@ -471,7 +471,7 @@ public class GameServiceImpl implements GameService {
.toList(); .toList();
// 从走棋记录重建棋盘 // 从走棋记录重建棋盘
boardState = GomokuGameService.rebuildBoard(moveEntities, room.getMaxPlayers()); boardState = GomokuGameService.rebuildBoard(moveEntities, GomokuGameService.BOARD_SIZE);
// currentTurn 由服务端运行时管理HTTP 快照中暂不返回 // currentTurn 由服务端运行时管理HTTP 快照中暂不返回
} }

View File

@@ -60,7 +60,11 @@ public class GomokuGameServiceImpl implements GomokuGameService {
int moveCount = moves.size(); int moveCount = moves.size();
// 判定当前玩家应该下哪一方(黑先白后) // 判定当前玩家应该下哪一方(黑先白后)
List<RoomPlayerEntity> players = roomPlayerRepository.findByRoomId(roomId); // 按座位号排序,确保黑方/白方分配与座位对应seat=1 为黑方先手)
List<RoomPlayerEntity> players = roomPlayerRepository.findByRoomId(roomId)
.stream()
.sorted(java.util.Comparator.comparingInt(RoomPlayerEntity::getSeatNumber))
.toList();
int playerIndex = -1; int playerIndex = -1;
for (int i = 0; i < players.size(); i++) { for (int i = 0; i < players.size(); i++) {
if (players.get(i).getUserId().equals(userId)) { if (players.get(i).getUserId().equals(userId)) {