Skip to content

Commit 4ad8841

Browse files
committed
update
1 parent 525ad1d commit 4ad8841

8 files changed

Lines changed: 65 additions & 29 deletions

File tree

src/App.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const {
8585
} = useBoardDisplay()
8686
8787
// ---- pieceScale(由 BoardPanel 通过事件更新) ----
88-
const pieceScale = ref(1.5)
88+
const pieceScale = ref(2)
8989
9090
// ---- 游戏核心状态(含棋钟、拖拽、音效、走棋) ----
9191
const game = useGameState(isSoundEnabled, isFlipped)
@@ -157,6 +157,7 @@ onUnmounted(() => {
157157
align-items: center;
158158
box-sizing: border-box;
159159
padding: 20px;
160+
padding-top: 40px;
160161
font-family: 'Unifont', system-ui, -apple-system, sans-serif;
161162
color: var(--color-text-primary);
162163
gap: 1rem;

src/components/BoardPanel.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ watch(pieceScale, (val) => {
283283
cursor: grab;
284284
z-index: 10;
285285
transition: opacity 0.1s ease;
286+
will-change: transform;
287+
backface-visibility: hidden;
288+
-webkit-backface-visibility: hidden;
286289
}
287290
288291
.piece.dragging-hidden {

src/components/GameSetup.vue

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<div class="home-buttons">
1010
<button class="btn btn-home" @click="startSetup('ai')">人机对局</button>
1111
<button class="btn btn-home" @click="startSetup('human')">双人对局</button>
12-
<button class="btn btn-home btn-home--secondary" @click="handleRemote">远程对局</button>
12+
<button class="btn btn-home" :disabled=true @click="handleRemote">远程对局</button>
1313
</div>
1414
</section>
1515

@@ -341,26 +341,6 @@ const handleStart = () => {
341341
padding: 14px 0;
342342
font-size: 1.15rem;
343343
font-weight: 600;
344-
border: 2px solid var(--color-surface-border);
345-
background: var(--color-surface);
346-
color: var(--color-text-primary);
347-
cursor: pointer;
348-
transition: background-color 0.15s, color 0.15s;
349-
}
350-
351-
.btn-home:hover {
352-
background: var(--color-surface-border);
353-
color: var(--color-text-on-primary);
354-
}
355-
356-
.btn-home--secondary {
357-
border-color: var(--color-border-secondary);
358-
color: var(--color-text-muted);
359-
}
360-
361-
.btn-home--secondary:hover {
362-
background: var(--color-border-secondary);
363-
color: var(--color-text-on-primary);
364344
}
365345
366346
.setup-panel {

src/components/Sidebar.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
<span v-if="materialDiffText" class="material-diff-text">{{ materialDiffText }}</span>
99
<span v-else class="material-diff-text"></span>
1010
</div>
11-
<button type="button" class="btn flip-sidebar-btn" title="翻转棋盘" @click="$emit('toggle-flip')">
11+
<button type="button" class="btn btn-flip" title="翻转棋盘" @click="$emit('toggle-flip')">
1212
<span class="btn-icon" v-html="refreshSvg"></span>
13+
<span>翻转棋盘</span>
1314
</button>
1415
</div>
1516

@@ -538,6 +539,24 @@ const materialDiffText = computed(() => {
538539
width: auto;
539540
}
540541
542+
.btn-flip {
543+
display: inline-flex;
544+
align-items: center;
545+
justify-content: center;
546+
gap: 0.2rem;
547+
line-height: 1;
548+
padding: 0.4rem 0.6rem;
549+
}
550+
551+
.btn-flip .btn-icon {
552+
display: inline-flex;
553+
align-items: center;
554+
justify-content: center;
555+
width: 1rem;
556+
height: 1rem;
557+
flex-shrink: 0;
558+
}
559+
541560
.btn-icon :deep(svg) {
542561
width: 100%;
543562
height: 100%;

src/composables/useGameState.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,9 +1354,22 @@ export function useGameState(
13541354
cancelAIMove()
13551355
isAIThinking.value = true
13561356

1357+
// 获取 AI 方当前棋钟剩余时间(秒),转换为毫秒
1358+
const aiTimeRemainingSec = aiColor === 'white' ? whiteTimeSeconds.value : blackTimeSeconds.value
1359+
const aiTimeRemainingMs = aiTimeRemainingSec !== null ? aiTimeRemainingSec * 1000 : null
1360+
13571361
// 模拟 AI 思考延迟(让棋钟有时间走动)
1358-
// 基础延迟 500ms + 根据难度随机追加 0~difficulty*500ms
1359-
const baseDelay = 1000
1362+
// 基础延迟 1000ms + 根据难度随机追加,并根据剩余时间动态缩减
1363+
let baseDelay = 1000
1364+
if (aiTimeRemainingMs !== null) {
1365+
if (aiTimeRemainingMs < 10_000) {
1366+
baseDelay = 100 // 不足 10 秒:几乎立即响应
1367+
} else if (aiTimeRemainingMs < 30_000) {
1368+
baseDelay = 200 // 不足 30 秒:快速响应
1369+
} else if (aiTimeRemainingMs < 60_000) {
1370+
baseDelay = 500 // 不足 60 秒:较快响应
1371+
}
1372+
}
13601373
const randomExtra = Math.random() * (6 - aiDifficulty.value) * 500
13611374
const thinkDelay = baseDelay + randomExtra
13621375

@@ -1461,6 +1474,7 @@ export function useGameState(
14611474
difficulty: aiDifficulty.value,
14621475
style: aiStyle.value,
14631476
lastMove: plainLastMove,
1477+
aiTimeRemainingMs: aiTimeRemainingMs ?? undefined,
14641478
})
14651479
} catch (err) {
14661480
console.error('Failed to post message to AI Worker:', err)

src/models/engine/search.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export async function getBestAIMove(
3030
difficulty: AIDifficulty,
3131
style: AIStyle,
3232
lastMove: { from: Square; to: Square } | null,
33+
aiTimeRemainingMs?: number,
3334
): Promise<AIDetailedMove | null> {
34-
// 初始化搜索状态
35-
initSearchState(b, color, style, difficulty, lastMove)
35+
// 初始化搜索状态(传递 AI 方棋钟剩余时间,低时间时自动缩减搜索深度)
36+
initSearchState(b, color, style, difficulty, lastMove, aiTimeRemainingMs)
3637

3738
// 清空杀手走法
3839
for (let d = 0; d < MAX_DEPTH; d++) {

src/models/engine/searchState.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export let searchStartTime: number = 0
2222
export let searchTimeLimit: number = 0
2323
export let searchStopped: boolean = false
2424
export let searchNodes: number = 0
25+
export let searchAITimeRemainingMs: number | null = null
2526

2627
// Setter 函数——因为 let 导出的变量在其他模块中不可直接赋值
2728
export function setSearchHash(v: number): void { searchHash = v }
@@ -198,7 +199,7 @@ export function getCastlingRights(b: Board): CastlingRights {
198199
// ============================================================
199200
// 初始化搜索状态
200201
// ============================================================
201-
export function initSearchState(b: Board, color: Color, style: AIStyle, difficulty: number, lastMove: { from: { row: number; col: number }; to: { row: number; col: number } } | null): void {
202+
export function initSearchState(b: Board, color: Color, style: AIStyle, difficulty: number, lastMove: { from: { row: number; col: number }; to: { row: number; col: number } } | null, aiTimeRemainingMs?: number): void {
202203
board = b
203204
searchColor = color
204205
searchStyle = style
@@ -213,7 +214,22 @@ export function initSearchState(b: Board, color: Color, style: AIStyle, difficul
213214
4: 1000,
214215
5: 2500,
215216
}
216-
searchTimeLimit = timeLimitMap[difficulty] ?? 500
217+
const baseTimeLimit = timeLimitMap[difficulty] ?? 500
218+
219+
searchAITimeRemainingMs = aiTimeRemainingMs ?? null
220+
if (searchAITimeRemainingMs !== null) {
221+
if (searchAITimeRemainingMs < 10_000) {
222+
searchTimeLimit = Math.min(baseTimeLimit, 50)
223+
} else if (searchAITimeRemainingMs < 30_000) {
224+
searchTimeLimit = Math.max(30, baseTimeLimit * 0.25)
225+
} else if (searchAITimeRemainingMs < 60_000) {
226+
searchTimeLimit = Math.max(40, baseTimeLimit * 0.5)
227+
} else {
228+
searchTimeLimit = baseTimeLimit
229+
}
230+
} else {
231+
searchTimeLimit = baseTimeLimit
232+
}
217233

218234
// 初始化增量追踪(王位置和子力)
219235
const wk = findKing(b, 'white')

src/workers/ai-worker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface WorkerRequest {
1111
difficulty: number
1212
style: string
1313
lastMove: { from: Square; to: Square } | null
14+
aiTimeRemainingMs?: number
1415
}
1516

1617
interface WorkerResponse {
@@ -42,6 +43,7 @@ self.onmessage = async (e: MessageEvent<WorkerRequest>) => {
4243
difficulty as 1 | 2 | 3 | 4 | 5,
4344
style as 'balanced' | 'aggressive' | 'defensive' | 'unpredictable',
4445
lastMove,
46+
e.data.aiTimeRemainingMs,
4547
)
4648

4749
const response: WorkerResponse = {

0 commit comments

Comments
 (0)