Skip to content

Commit e6e490d

Browse files
committed
update ai
1 parent 7566271 commit e6e490d

7 files changed

Lines changed: 178 additions & 38 deletions

File tree

src/App.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
:promotion-pending="promotionPending" :promotion-style="promotionStyle" :is-draw="isDraw"
1212
:has-resigned="hasResigned" :timeout-winner="timeoutWinner" :coordinate-label-mode="coordinateLabelMode"
1313
:is-flipped="isFlipped"
14+
:premove="premove"
15+
:last-move="lastMove"
1416
:get-overlay-texture="getOverlayTexture"
1517
:get-piece-image="getPieceImage"
1618
:get-square-label="getSquareLabel"
@@ -28,6 +30,7 @@
2830
:is-game-over="isGameOver" :is-flipped="isFlipped" :board="board" :player-color="playerColor"
2931
:white-time-seconds="whiteTimeSeconds"
3032
:black-time-seconds="blackTimeSeconds" :active-color="currentTurn" :clock-test-id="'sidebar-chess-clock'"
33+
:game-mode="gameMode"
3134
v-model:is-sound-enabled="isSoundEnabled" v-model:coordinate-label-mode="coordinateLabelMode"
3235
@toggle-flip="isFlipped = !isFlipped" :has-game-started="hasGameStarted" @undo="handleUndo"
3336
@draw="handleDrawOffer" @resign="handleResign" @restart="handleRestart" @back-to-setup="handleBackToSetup" />
@@ -81,6 +84,7 @@ const {
8184
showSetup,
8285
playerColor,
8386
isClockEnabled,
87+
gameMode,
8488
board,
8589
currentTurn,
8690
selectedSquare,
@@ -103,6 +107,7 @@ const {
103107
isDragging,
104108
dragStartSquare,
105109
mousePos,
110+
premove,
106111
handleMouseDown,
107112
handleUndo,
108113
handleResign,

src/components/BoardPanel.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
:src="isWhiteSquare(actualRow(displayRow - 1), actualCol(displayCol - 1)) ? './texture/board/board_white.png' : './texture/board/board_black.png'"
1515
alt="" />
1616

17-
<img v-if="getOverlayTexture(board, selectedSquare, possibleMoves, isDragging, hoverSquare, actualRow(displayRow - 1), actualCol(displayCol - 1))"
17+
<img v-if="getOverlayTexture(board, selectedSquare, possibleMoves, isDragging, hoverSquare, actualRow(displayRow - 1), actualCol(displayCol - 1), premove, lastMove)"
1818
class="square-background overlay" draggable="false"
19-
:src="getOverlayTexture(board, selectedSquare, possibleMoves, isDragging, hoverSquare, actualRow(displayRow - 1), actualCol(displayCol - 1))!" alt="" />
19+
:src="getOverlayTexture(board, selectedSquare, possibleMoves, isDragging, hoverSquare, actualRow(displayRow - 1), actualCol(displayCol - 1), premove, lastMove)!" alt="" />
2020

2121
<img v-if="board[actualRow(displayRow - 1)]?.[actualCol(displayCol - 1)]" class="piece"
2222
draggable="false" :class="{
@@ -86,6 +86,8 @@ const props = defineProps<{
8686
timeoutWinner: Color | null
8787
coordinateLabelMode: 'off' | 'inside' | 'outside'
8888
isFlipped: boolean
89+
premove?: { from: { row: number; col: number }; to: { row: number; col: number } } | null
90+
lastMove?: { from: { row: number; col: number }; to: { row: number; col: number } } | null
8991
getOverlayTexture: (
9092
board: Board,
9193
selectedSquare: { row: number; col: number } | null,
@@ -94,6 +96,8 @@ const props = defineProps<{
9496
hoverSquare: { row: number; col: number } | null,
9597
row: number,
9698
col: number,
99+
premove?: { from: { row: number; col: number }; to: { row: number; col: number } } | null,
100+
lastMove?: { from: { row: number; col: number }; to: { row: number; col: number } } | null,
97101
) => string | null
98102
getPieceImage: (
99103
piece: Piece,

src/components/GameSetup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<section v-if="screen === 'home'" class="home-panel">
55
<div class="logo-section">
66
<!-- 修改处:将文字标题替换为图片 Logo -->
7-
<img src="/texture/logo.png" alt="Chess Dragon" class="logo-img" />
7+
<img src="./texture/logo.png" alt="Chess Dragon" class="logo-img" />
88
</div>
99
<div class="home-buttons">
1010
<button class="btn btn-home" @click="startSetup('ai')">人机对战</button>

src/components/Promotion.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class="promote-btn"
88
@click="$emit('select', p)"
99
>
10-
<img :src="`./texture/promotion/promotion_${p}_${color}.png`" :alt="p" draggable="false" />
10+
<img :src="`./texture/promotion/promotion_${p}_${color}.png`" :alt="p" />
1111
</button>
1212
</div>
1313
</template>

src/components/Sidebar.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
type="button"
4141
class="btn"
4242
:class="isClaimableDraw ? 'btn-success' : 'btn-primary'"
43-
:disabled="isGameActionDisabled"
43+
:disabled="isDrawOfferDisabled"
4444
@click="handleDrawClick"
4545
>
46-
{{ isClaimableDraw ? '宣告和棋' : '申请和棋' }}
46+
{{ isClaimableDraw ? '宣告和棋' : '提议和棋' }}
4747
</button>
4848
<button type="button" class="btn btn-danger" :disabled="isGameActionDisabled" @click="handleResignClick">
4949
认输
@@ -87,6 +87,7 @@ interface Props {
8787
activeColor?: Color | null
8888
clockTestId?: string
8989
hasGameStarted?: boolean
90+
gameMode?: 'ai' | 'human' | 'remote'
9091
}
9192
9293
interface MovePair {
@@ -111,6 +112,7 @@ const props = withDefaults(defineProps<Props>(), {
111112
activeColor: null,
112113
clockTestId: 'sidebar-chess-clock',
113114
hasGameStarted: false,
115+
gameMode: 'human',
114116
})
115117
116118
const emit = defineEmits<{
@@ -138,6 +140,16 @@ const isGameActionDisabled = computed(() => {
138140
return !props.hasGameStarted || props.isGameOver || !!props.gameStatus
139141
})
140142
143+
// AI 对战时禁用"提议和棋",但"宣告和棋"仍可用
144+
const isDrawOfferDisabled = computed(() => {
145+
if (isGameActionDisabled.value) return true
146+
// "宣告和棋"(满足条件时)总是可用
147+
if (isClaimableDraw.value) return false
148+
// "提议和棋"在 AI 模式下禁用
149+
if (props.gameMode === 'ai') return true
150+
return false
151+
})
152+
141153
const isClaimableDraw = computed(() => {
142154
return props.halfmoveClock >= 100 || props.positionCount >= 3
143155
})
@@ -206,8 +218,8 @@ const copyPGN = async () => {
206218
const handleDrawClick = () => {
207219
if (isClaimableDraw.value) {
208220
emit('draw')
209-
} else {
210-
confirmMessage.value = '确定要向对手申请和棋吗'
221+
} else if (props.gameMode !== 'ai') {
222+
confirmMessage.value = '确定要向对手提议和棋吗'
211223
pendingAction.value = 'draw'
212224
showConfirmModal.value = true
213225
}

src/composables/useBoardDisplay.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function useBoardDisplay() {
2323
return `${8 - getActualRow(displayRow - 1)}`
2424
}
2525

26-
// --- Overlay 纹理:用于高亮选中格子与合法走法 ---
26+
// --- Overlay 纹理:用于高亮选中格子、合法走法、premove、上一步移动 ---
2727
const getOverlayTexture = (
2828
board: Board,
2929
selectedSquare: { row: number; col: number } | null,
@@ -32,7 +32,33 @@ export function useBoardDisplay() {
3232
hoverSquare: { row: number; col: number } | null,
3333
row: number,
3434
col: number,
35+
premove?: { from: { row: number; col: number }; to: { row: number; col: number } } | null,
36+
lastMove?: { from: { row: number; col: number }; to: { row: number; col: number } } | null,
3537
): string | null => {
38+
// 上一步移动的高亮(起始格和目标格),优先于其他高亮
39+
if (lastMove) {
40+
if (
41+
(lastMove.from.row === row && lastMove.from.col === col) ||
42+
(lastMove.to.row === row && lastMove.to.col === col)
43+
) {
44+
return './texture/board/board_hover.png'
45+
}
46+
}
47+
48+
// Premove 高亮 - 目标格
49+
if (premove && premove.to.row === row && premove.to.col === col) {
50+
const targetPiece = board[row]?.[col] ?? null
51+
if (targetPiece !== null) {
52+
return './texture/board/board_premove_capture.png'
53+
}
54+
return './texture/board/board_premove_placeable.png'
55+
}
56+
57+
// Premove 高亮 - 起始格
58+
if (premove && premove.from.row === row && premove.from.col === col) {
59+
return './texture/board/board_premove_hover.png'
60+
}
61+
3662
if (selectedSquare?.row === row && selectedSquare?.col === col) {
3763
return './texture/board/board_hover.png'
3864
}

0 commit comments

Comments
 (0)