Skip to content

Commit

Permalink
warn low policy moves (kaorahi/lizzie#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaorahi committed Nov 18, 2023
1 parent c9a6377 commit 6c62f99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/draw_goban.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ function draw_branches(h, xy, radius, g) {

// ref. https://github.com/featurecat/lizzie/issues/671#issuecomment-586090067
function draw_loss(h, xy, radius, g) {
draw_low_policy(h, xy, radius, g)
const {gain, punished} = h, NOTHING = []
const [color, size, draw, min_width] = !truep(gain) ? NOTHING :
(gain <= big_blunder_threshold) ? [RED, 1, rev_triangle_around, 0.7] :
Expand All @@ -746,6 +747,17 @@ function draw_loss(h, xy, radius, g) {
draw(xy, radius * size - line_width, g)
}

function draw_low_policy(h, xy, radius, g) {
const very_low_policy = 0.01, low_policy = 0.1, very_high_policy = 0.7
const {policy, max_policy} = h; if (!max_policy) {return}
const draw = (line_width) => {
g.strokeStyle = '#888'; g.lineWidth = line_width
square_around(xy, radius * 0.7 - line_width, g)
}
max_policy > very_high_policy && policy < low_policy ? draw(3) :
policy < very_low_policy ? draw(1) : null
}

function draw_shadow_maybe(h, xy, radius, cheap_shadow_p, g) {
if (!h.stone) {return}
const {stone_image, style} = stone_style_for(h)
Expand Down
4 changes: 4 additions & 0 deletions src/powered_goban.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ function winrate_from_game(engine_id) {
merge(cur, {gain})
s <= game.move_count && merge_to_stone_at(cur, {gain})
record_punished(gain)
const {suggest} = prev; if (!suggest) {return}
const max_policy = Math.max(...suggest.map(h => h.prior))
const policy = (suggest.find(h => h.move === cur.move) || {}).prior || 0.0
merge_to_stone_at(cur, {policy, max_policy})
}
const record_punished = gain => {
const prev_gain = (prev || {}).gain
Expand Down
3 changes: 3 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ E.handicap_komi = -0.5
E.default_gorule = 'chinese'
E.blunder_threshold = -2
E.big_blunder_threshold = -5
E.blunder_very_low_policy = 0.01
E.blunder_low_policy = 0.1
E.blunder_high_policy = 0.7
E.black_to_play_p = (forced, bturn) => forced ? (forced === 'black') : bturn

// seq(3) = [ 0, 1, 2 ], seq(3, 5) = [ 5, 6, 7 ], seq(-2) = []
Expand Down

0 comments on commit 6c62f99

Please sign in to comment.