Skip to content

Commit 036fb5e

Browse files
committed
ref: inline
1 parent 92a758a commit 036fb5e

File tree

2 files changed

+57
-73
lines changed

2 files changed

+57
-73
lines changed

webzebra/src/game.ts

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,9 @@
1-
import {EvaluatedMove} from "./message";
2-
31
export type Circle = {
42
cx: number,
53
cy: number,
64
r: number,
75
color: string
86
}
9-
export type Eval = {
10-
x: number,
11-
y: number,
12-
color: string,
13-
text: string
14-
}
15-
16-
export function boardData(board: number[], clickedMove: number | undefined, evaluatedMoves: EvaluatedMove[]) {
17-
let evals_ = []
18-
const fieldSize = 100
19-
const arr = [] as Circle[]
20-
for (let i = 1; i <= 8; i++) {
21-
for (let j = 1; j <= 8; j++) {
22-
let color;
23-
let move = 10 * i + j;
24-
25-
switch (board[move]) {
26-
case 0 :
27-
color = 'black'
28-
break;
29-
30-
case 2 :
31-
color = 'white'
32-
break;
33-
34-
default : {
35-
if (clickedMove === move) {
36-
// todo take into account side to move
37-
color = 'rgba(127, 127, 127, 0.5)'
38-
break
39-
}
40-
const eval_ = evaluatedMoves.find((eval_: EvaluatedMove) => eval_.move === move)
41-
if (!eval_) {
42-
continue
43-
}
44-
45-
if (eval_.best) {
46-
color = '#00FFFF'
47-
} else {
48-
color = '#FFFF00'
49-
}
50-
const text = eval_.eval_s
51-
evals_.push({
52-
x: (j - 1) * fieldSize + 0.2 * fieldSize,
53-
y: (i - 1) * fieldSize + 0.65 * fieldSize,
54-
color,
55-
text
56-
})
57-
continue
58-
}
59-
}
60-
61-
const pieceSize = 80
62-
arr.push({
63-
cx: (j - 1) * fieldSize + 0.5 * fieldSize,
64-
cy: (i - 1) * fieldSize + 0.5 * fieldSize,
65-
r: pieceSize / 2,
66-
color
67-
})
68-
}
69-
}
70-
return {
71-
circles: arr,
72-
evals: evals_
73-
}
74-
}
757

768
export const scoreFromCircles = (circles: Circle[]) => {
779
return {

webzebra/src/main.ts

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import './index.css'
22
import {EvaluatedMove, Message, MessageType, SkillSetting} from "./message";
33
import {createStopToken, stop} from "./stopToken";
4-
import {boardData, scoreFromCircles} from "./game";
4+
import {Circle, scoreFromCircles} from "./game";
55

66
interface ZWorker extends Worker {
77
postMessage(message: Message): void
@@ -136,10 +136,63 @@ document.getElementById('board')?.addEventListener('click', (e) => {
136136
})
137137

138138
function render() {
139-
const svgData_ = boardData(board, clickedMove, evals);
139+
let evals_ = []
140+
const fieldSize = 100
141+
const arr = [] as Circle[]
142+
for (let i = 1; i <= 8; i++) {
143+
for (let j = 1; j <= 8; j++) {
144+
let color;
145+
let move = 10 * i + j;
146+
147+
switch (board[move]) {
148+
case 0 :
149+
color = 'black'
150+
break;
151+
152+
case 2 :
153+
color = 'white'
154+
break;
155+
156+
default : {
157+
if (clickedMove === move) {
158+
// todo take into account side to move
159+
color = 'rgba(127, 127, 127, 0.5)'
160+
break
161+
}
162+
const eval_ = evals.find((eval_: EvaluatedMove) => eval_.move === move)
163+
if (!eval_) {
164+
continue
165+
}
166+
167+
if (eval_.best) {
168+
color = '#00FFFF'
169+
} else {
170+
color = '#FFFF00'
171+
}
172+
const text = eval_.eval_s
173+
evals_.push({
174+
x: (j - 1) * fieldSize + 0.2 * fieldSize,
175+
y: (i - 1) * fieldSize + 0.65 * fieldSize,
176+
color,
177+
text
178+
})
179+
continue
180+
}
181+
}
182+
183+
const pieceSize = 80
184+
arr.push({
185+
cx: (j - 1) * fieldSize + 0.5 * fieldSize,
186+
cy: (i - 1) * fieldSize + 0.5 * fieldSize,
187+
r: pieceSize / 2,
188+
color
189+
})
190+
}
191+
}
192+
193+
const circles = arr
194+
const score = scoreFromCircles(circles)
140195

141-
const score = scoreFromCircles(svgData_.circles)
142-
const circles = svgData_.circles;
143196
const circlesHtml = circles.map(circle => {
144197
return `<circle r="${circle.r}" cx="${circle.cx}" cy="${circle.cy}" style="fill: ${circle.color}"></circle>`
145198
}).join('')
@@ -148,7 +201,6 @@ function render() {
148201
document.getElementById('score-black')!.innerText = '' + score.black
149202
document.getElementById('score-white')!.innerText = '' + score.white
150203

151-
const evals_ = svgData_.evals;
152204
const evalsHtml = evals_.map(eval_ => {
153205
return `<text x="${eval_.x}" y="${eval_.y}" style="fill: ${eval_.color}; font-size: 50px">${eval_.text}</text>`
154206
}).join('')

0 commit comments

Comments
 (0)