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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
<html>
|
3 |
+
<head>
|
4 |
+
<title>Go Game</title>
|
5 |
+
<style>
|
6 |
+
.board {
|
7 |
+
display: grid;
|
8 |
+
grid-template-columns: repeat(19, 30px);
|
9 |
+
grid-template-rows: repeat(19, 30px);
|
10 |
+
gap: 1px;
|
11 |
+
background-color: #dcb35c;
|
12 |
+
border: 2px solid #000;
|
13 |
+
width: fit-content;
|
14 |
+
margin: 20px auto;
|
15 |
+
}
|
16 |
+
|
17 |
+
.intersection {
|
18 |
+
width: 30px;
|
19 |
+
height: 30px;
|
20 |
+
position: relative;
|
21 |
+
cursor: pointer;
|
22 |
+
}
|
23 |
+
|
24 |
+
.intersection::before {
|
25 |
+
content: '';
|
26 |
+
position: absolute;
|
27 |
+
left: 0;
|
28 |
+
top: 50%;
|
29 |
+
width: 100%;
|
30 |
+
height: 1px;
|
31 |
+
background: #000;
|
32 |
+
z-index: 1;
|
33 |
+
}
|
34 |
+
|
35 |
+
.intersection::after {
|
36 |
+
content: '';
|
37 |
+
position: absolute;
|
38 |
+
top: 0;
|
39 |
+
left: 50%;
|
40 |
+
height: 100%;
|
41 |
+
width: 1px;
|
42 |
+
background: #000;
|
43 |
+
z-index: 1;
|
44 |
+
}
|
45 |
+
|
46 |
+
.star-point::before {
|
47 |
+
content: '';
|
48 |
+
position: absolute;
|
49 |
+
width: 6px;
|
50 |
+
height: 6px;
|
51 |
+
background: #000;
|
52 |
+
border-radius: 50%;
|
53 |
+
top: 50%;
|
54 |
+
left: 50%;
|
55 |
+
transform: translate(-50%, -50%);
|
56 |
+
z-index: 2;
|
57 |
+
}
|
58 |
+
|
59 |
+
.stone {
|
60 |
+
width: 28px;
|
61 |
+
height: 28px;
|
62 |
+
border-radius: 50%;
|
63 |
+
position: absolute;
|
64 |
+
top: 1px;
|
65 |
+
left: 1px;
|
66 |
+
z-index: 3;
|
67 |
+
transition: 0.2s ease;
|
68 |
+
}
|
69 |
+
|
70 |
+
.black {
|
71 |
+
background: #000;
|
72 |
+
box-shadow: inset -2px -2px 8px rgba(255,255,255,0.2);
|
73 |
+
}
|
74 |
+
|
75 |
+
.white {
|
76 |
+
background: #fff;
|
77 |
+
box-shadow: inset -2px -2px 8px rgba(0,0,0,0.2);
|
78 |
+
}
|
79 |
+
|
80 |
+
.controls {
|
81 |
+
text-align: center;
|
82 |
+
margin: 20px;
|
83 |
+
}
|
84 |
+
|
85 |
+
button {
|
86 |
+
padding: 8px 16px;
|
87 |
+
margin: 0 5px;
|
88 |
+
font-size: 16px;
|
89 |
+
border: none;
|
90 |
+
border-radius: 4px;
|
91 |
+
background: #4CAF50;
|
92 |
+
color: white;
|
93 |
+
cursor: pointer;
|
94 |
+
transition: 0.3s;
|
95 |
+
}
|
96 |
+
|
97 |
+
button:hover {
|
98 |
+
background: #45a049;
|
99 |
+
}
|
100 |
+
|
101 |
+
.game-info {
|
102 |
+
text-align: center;
|
103 |
+
margin: 20px;
|
104 |
+
font-size: 18px;
|
105 |
+
}
|
106 |
+
|
107 |
+
.game-info div {
|
108 |
+
margin: 10px 0;
|
109 |
+
}
|
110 |
+
|
111 |
+
.game-container {
|
112 |
+
max-width: 800px;
|
113 |
+
margin: 0 auto;
|
114 |
+
padding: 20px;
|
115 |
+
background: #f5f5f5;
|
116 |
+
border-radius: 10px;
|
117 |
+
box-shadow: 0 0 20px rgba(0,0,0,0.1);
|
118 |
+
}
|
119 |
+
|
120 |
+
.mode-select {
|
121 |
+
text-align: center;
|
122 |
+
margin-bottom: 20px;
|
123 |
+
}
|
124 |
+
|
125 |
+
select {
|
126 |
+
padding: 8px;
|
127 |
+
font-size: 16px;
|
128 |
+
border-radius: 4px;
|
129 |
+
}
|
130 |
+
</style>
|
131 |
+
</head>
|
132 |
+
<body>
|
133 |
+
<div class="game-container">
|
134 |
+
<div class="mode-select">
|
135 |
+
<select id="gameMode">
|
136 |
+
<option value="pvp">Player vs Player</option>
|
137 |
+
<option value="ai">Player vs AI</option>
|
138 |
+
</select>
|
139 |
+
<select id="difficulty">
|
140 |
+
<option value="easy">Easy</option>
|
141 |
+
<option value="hard">Hard</option>
|
142 |
+
</select>
|
143 |
+
</div>
|
144 |
+
|
145 |
+
<div id="board" class="board">
|
146 |
+
<!-- Board will be generated by JavaScript -->
|
147 |
+
</div>
|
148 |
+
|
149 |
+
<div class="game-info">
|
150 |
+
<div>Current Player: <span id="currentPlayer">Black</span></div>
|
151 |
+
<div>Black Captures: <span id="blackCaptures">0</span></div>
|
152 |
+
<div>White Captures: <span id="whiteCaptures">0</span></div>
|
153 |
+
</div>
|
154 |
+
|
155 |
+
<div class="controls">
|
156 |
+
<button id="passBtn">Pass</button>
|
157 |
+
<button id="resetBtn">Reset</button>
|
158 |
+
</div>
|
159 |
+
</div>
|
160 |
+
|
161 |
+
<script>
|
162 |
+
class GoGame {
|
163 |
+
constructor() {
|
164 |
+
this.size = 19;
|
165 |
+
this.board = Array(this.size).fill().map(() => Array(this.size).fill(null));
|
166 |
+
this.currentPlayer = 'black';
|
167 |
+
this.captures = { black: 0, white: 0 };
|
168 |
+
this.lastMove = null;
|
169 |
+
this.gameMode = 'pvp';
|
170 |
+
this.difficulty = 'easy';
|
171 |
+
this.initialize();
|
172 |
+
}
|
173 |
+
|
174 |
+
initialize() {
|
175 |
+
const boardElement = document.getElementById('board');
|
176 |
+
boardElement.innerHTML = '';
|
177 |
+
|
178 |
+
for (let i = 0; i < this.size; i++) {
|
179 |
+
for (let j = 0; j < this.size; j++) {
|
180 |
+
const intersection = document.createElement('div');
|
181 |
+
intersection.className = 'intersection';
|
182 |
+
intersection.dataset.row = i;
|
183 |
+
intersection.dataset.col = j;
|
184 |
+
|
185 |
+
if (this.isStarPoint(i, j)) {
|
186 |
+
intersection.classList.add('star-point');
|
187 |
+
}
|
188 |
+
|
189 |
+
intersection.addEventListener('click', (e) => this.handleMove(e));
|
190 |
+
boardElement.appendChild(intersection);
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
document.getElementById('passBtn').addEventListener('click', () => this.pass());
|
195 |
+
document.getElementById('resetBtn').addEventListener('click', () => this.reset());
|
196 |
+
document.getElementById('gameMode').addEventListener('change', (e) => {
|
197 |
+
this.gameMode = e.target.value;
|
198 |
+
this.reset();
|
199 |
+
});
|
200 |
+
document.getElementById('difficulty').addEventListener('change', (e) => {
|
201 |
+
this.difficulty = e.target.value;
|
202 |
+
});
|
203 |
+
|
204 |
+
this.updateDisplay();
|
205 |
+
}
|
206 |
+
|
207 |
+
isStarPoint(row, col) {
|
208 |
+
const starPoints = [
|
209 |
+
[3, 3], [3, 9], [3, 15],
|
210 |
+
[9, 3], [9, 9], [9, 15],
|
211 |
+
[15, 3], [15, 9], [15, 15]
|
212 |
+
];
|
213 |
+
return starPoints.some(point => point[0] === row && point[1] === col);
|
214 |
+
}
|
215 |
+
|
216 |
+
handleMove(e) {
|
217 |
+
const row = parseInt(e.target.dataset.row);
|
218 |
+
const col = parseInt(e.target.dataset.col);
|
219 |
+
|
220 |
+
if (this.isValidMove(row, col)) {
|
221 |
+
this.placeStone(row, col);
|
222 |
+
|
223 |
+
if (this.gameMode === 'ai' && this.currentPlayer === 'white') {
|
224 |
+
setTimeout(() => this.makeAIMove(), 500);
|
225 |
+
}
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
isValidMove(row, col) {
|
230 |
+
if (this.board[row][col] !== null) return false;
|
231 |
+
|
232 |
+
this.board[row][col] = this.currentPlayer;
|
233 |
+
const captures = this.checkCaptures(row, col);
|
234 |
+
const suicide = this.isSuicideMove(row, col);
|
235 |
+
|
236 |
+
this.board[row][col] = null;
|
237 |
+
|
238 |
+
return !suicide || captures.length > 0;
|
239 |
+
}
|
240 |
+
|
241 |
+
placeStone(row, col) {
|
242 |
+
this.board[row][col] = this.currentPlayer;
|
243 |
+
this.renderStone(row, col);
|
244 |
+
|
245 |
+
const captures = this.checkCaptures(row, col);
|
246 |
+
this.removeCaptures(captures);
|
247 |
+
|
248 |
+
this.lastMove = [row, col];
|
249 |
+
this.currentPlayer = this.currentPlayer === 'black' ? 'white' : 'black';
|
250 |
+
this.updateDisplay();
|
251 |
+
}
|
252 |
+
|
253 |
+
renderStone(row, col) {
|
254 |
+
const intersection = document.querySelector(`[data-row="${row}"][data-col="${col}"]`);
|
255 |
+
const stone = document.createElement('div');
|
256 |
+
stone.className = `stone ${this.currentPlayer}`;
|
257 |
+
intersection.appendChild(stone);
|
258 |
+
}
|
259 |
+
|
260 |
+
makeStrategicMove() {
|
261 |
+
let bestMove = null;
|
262 |
+
let bestScore = -Infinity;
|
263 |
+
|
264 |
+
for (let row = 0; row < this.size; row++) {
|
265 |
+
for (let col = 0; col < this.size; col++) {
|
266 |
+
if (this.isValidMove(row, col)) {
|
267 |
+
const score = this.evaluateMove(row, col);
|
268 |
+
if (score > bestScore) {
|
269 |
+
bestScore = score;
|
270 |
+
bestMove = [row, col];
|
271 |
+
}
|
272 |
+
}
|
273 |
+
}
|
274 |
+
}
|
275 |
+
|
276 |
+
if (bestMove) {
|
277 |
+
this.placeStone(...bestMove);
|
278 |
+
} else {
|
279 |
+
this.pass();
|
280 |
+
}
|
281 |
+
}
|
282 |
+
|
283 |
+
evaluateMove(row, col) {
|
284 |
+
let score = 0;
|
285 |
+
|
286 |
+
this.board[row][col] = this.currentPlayer;
|
287 |
+
|
288 |
+
const captures = this.checkCaptures(row, col);
|
289 |
+
score += captures.length * 10;
|
290 |
+
|
291 |
+
const group = this.getGroup(row, col);
|
292 |
+
const liberties = this.getGroupLiberties(group);
|
293 |
+
score += liberties.length;
|
294 |
+
|
295 |
+
if (this.isStarPoint(row, col)) {
|
296 |
+
score += 5;
|
297 |
+
}
|
298 |
+
|
299 |
+
const neighbors = this.getNeighbors(row, col);
|
300 |
+
for (const [nRow, nCol] of neighbors) {
|
301 |
+
if (this.board[nRow][nCol] === this.currentPlayer) {
|
302 |
+
score += 3;
|
303 |
+
}
|
304 |
+
}
|
305 |
+
|
306 |
+
this.board[row][col] = null;
|
307 |
+
return score;
|
308 |
+
}
|
309 |
+
|
310 |
+
getGroupLiberties(group) {
|
311 |
+
const liberties = new Set();
|
312 |
+
for (const [row, col] of group) {
|
313 |
+
const neighbors = this.getNeighbors(row, col);
|
314 |
+
for (const [nRow, nCol] of neighbors) {
|
315 |
+
if (this.board[nRow][nCol] === null) {
|
316 |
+
liberties.add(`${nRow},${nCol}`);
|
317 |
+
}
|
318 |
+
}
|
319 |
+
}
|
320 |
+
return Array.from(liberties);
|
321 |
+
}
|
322 |
+
|
323 |
+
makeAIMove() {
|
324 |
+
if (this.difficulty === 'easy') {
|
325 |
+
this.makeRandomMove();
|
326 |
+
} else {
|
327 |
+
this.makeStrategicMove();
|
328 |
+
}
|
329 |
+
}
|
330 |
+
|
331 |
+
pass() {
|
332 |
+
this.currentPlayer = this.currentPlayer === 'black' ? 'white' : 'black';
|
333 |
+
this.updateDisplay();
|
334 |
+
|
335 |
+
if (this.gameMode === 'ai' && this.currentPlayer === 'white') {
|
336 |
+
setTimeout(() => this.makeAIMove(), 500);
|
337 |
+
}
|
338 |
+
}
|
339 |
+
|
340 |
+
reset() {
|
341 |
+
this.board = Array(this.size).fill().map(() => Array(this.size).fill(null));
|
342 |
+
this.currentPlayer = 'black';
|
343 |
+
this.captures = { black: 0, white: 0 };
|
344 |
+
this.lastMove = null;
|
345 |
+
this.initialize();
|
346 |
+
}
|
347 |
+
|
348 |
+
updateDisplay() {
|
349 |
+
document.getElementById('currentPlayer').textContent =
|
350 |
+
this.currentPlayer.charAt(0).toUpperCase() + this.currentPlayer.slice(1);
|
351 |
+
document.getElementById('blackCaptures').textContent = this.captures.black;
|
352 |
+
document.getElementById('whiteCaptures').textContent = this.captures.white;
|
353 |
+
}
|
354 |
+
}
|
355 |
+
|
356 |
+
new GoGame();
|
357 |
+
</script>
|
358 |
+
</body>
|
359 |
</html>
|
360 |
+
|