Spaces:
Running
Running
Update index.html
Browse files- index.html +30 -15
index.html
CHANGED
@@ -78,7 +78,7 @@
|
|
78 |
.square.valid-move::after {
|
79 |
content: '•';
|
80 |
position: absolute;
|
81 |
-
color:
|
82 |
font-size: 2em;
|
83 |
}
|
84 |
|
@@ -125,7 +125,6 @@
|
|
125 |
<div class="status-panel">
|
126 |
<h3>Position Analysis</h3>
|
127 |
<p id="status">White to move</p>
|
128 |
-
<p id="evaluation">Evaluation: 0.0</p>
|
129 |
</div>
|
130 |
<button onclick="resetBoard()">Reset Board</button>
|
131 |
</div>
|
@@ -137,6 +136,7 @@
|
|
137 |
this.board = this.createInitialBoard();
|
138 |
this.currentPlayer = 'white';
|
139 |
this.selectedPiece = null;
|
|
|
140 |
this.initializeBoard();
|
141 |
}
|
142 |
|
@@ -163,6 +163,7 @@
|
|
163 |
square.dataset.row = row;
|
164 |
square.dataset.col = col;
|
165 |
square.onclick = (e) => this.handleSquareClick(e);
|
|
|
166 |
if (this.board[row][col]) {
|
167 |
const piece = document.createElement('div');
|
168 |
piece.className = 'piece';
|
@@ -172,6 +173,7 @@
|
|
172 |
boardElement.appendChild(square);
|
173 |
}
|
174 |
}
|
|
|
175 |
}
|
176 |
|
177 |
handleSquareClick(event) {
|
@@ -190,24 +192,37 @@
|
|
190 |
}
|
191 |
|
192 |
selectPiece(row, col) {
|
193 |
-
document.querySelectorAll('.square').forEach(sq => sq.classList.remove('selected', 'valid-move', 'attack-move'));
|
194 |
-
document.querySelector(`[data-row="${row}"][data-col="${col}"]`).classList.add('selected');
|
195 |
this.selectedPiece = { row, col };
|
|
|
|
|
|
|
196 |
}
|
197 |
|
198 |
-
|
199 |
-
const
|
200 |
-
const
|
201 |
-
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
}
|
204 |
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
document.getElementById('status').textContent = `${this.currentPlayer} to move`;
|
210 |
-
this.initializeBoard();
|
211 |
}
|
212 |
}
|
213 |
|
|
|
78 |
.square.valid-move::after {
|
79 |
content: '•';
|
80 |
position: absolute;
|
81 |
+
color: var(--move-highlight);
|
82 |
font-size: 2em;
|
83 |
}
|
84 |
|
|
|
125 |
<div class="status-panel">
|
126 |
<h3>Position Analysis</h3>
|
127 |
<p id="status">White to move</p>
|
|
|
128 |
</div>
|
129 |
<button onclick="resetBoard()">Reset Board</button>
|
130 |
</div>
|
|
|
136 |
this.board = this.createInitialBoard();
|
137 |
this.currentPlayer = 'white';
|
138 |
this.selectedPiece = null;
|
139 |
+
this.validMoves = [];
|
140 |
this.initializeBoard();
|
141 |
}
|
142 |
|
|
|
163 |
square.dataset.row = row;
|
164 |
square.dataset.col = col;
|
165 |
square.onclick = (e) => this.handleSquareClick(e);
|
166 |
+
|
167 |
if (this.board[row][col]) {
|
168 |
const piece = document.createElement('div');
|
169 |
piece.className = 'piece';
|
|
|
173 |
boardElement.appendChild(square);
|
174 |
}
|
175 |
}
|
176 |
+
this.highlightValidMoves();
|
177 |
}
|
178 |
|
179 |
handleSquareClick(event) {
|
|
|
192 |
}
|
193 |
|
194 |
selectPiece(row, col) {
|
|
|
|
|
195 |
this.selectedPiece = { row, col };
|
196 |
+
this.validMoves = this.getValidMoves(row, col);
|
197 |
+
this.initializeBoard();
|
198 |
+
document.querySelector(`[data-row="${row}"][data-col="${col}"]`).classList.add('selected');
|
199 |
}
|
200 |
|
201 |
+
getValidMoves(row, col) {
|
202 |
+
const piece = this.board[row][col];
|
203 |
+
const moves = [];
|
204 |
+
const directions = {
|
205 |
+
'♖': [[-1,0], [1,0], [0,-1], [0,1]],
|
206 |
+
'♗': [[-1,-1], [-1,1], [1,-1], [1,1]],
|
207 |
+
'♕': [[-1,0], [1,0], [0,-1], [0,1], [-1,-1], [-1,1], [1,-1], [1,1]]
|
208 |
+
};
|
209 |
+
|
210 |
+
if (piece in directions) {
|
211 |
+
for (const [dx, dy] of directions[piece]) {
|
212 |
+
let r = row + dx, c = col + dy;
|
213 |
+
while (r >= 0 && r < 8 && c >= 0 && c < 8 && !this.board[r][c]) {
|
214 |
+
moves.push([r, c]);
|
215 |
+
r += dx; c += dy;
|
216 |
+
}
|
217 |
+
}
|
218 |
+
}
|
219 |
+
return moves;
|
220 |
}
|
221 |
|
222 |
+
highlightValidMoves() {
|
223 |
+
for (const [row, col] of this.validMoves) {
|
224 |
+
document.querySelector(`[data-row="${row}"][data-col="${col}"]`).classList.add('valid-move');
|
225 |
+
}
|
|
|
|
|
226 |
}
|
227 |
}
|
228 |
|