Giter Club home page Giter Club logo

influence's Introduction

@sabaki/influence Build Status

Simple static heuristics for estimating influence maps on Go positions.

Installation

Use npm to install:

$ npm install @sabaki/influence

Then require it as follows:

const influence = require('@sabaki/influence');

API

Board Data

The board arrangement is represented by an array of arrays. Each of those subarrays represent one row, all containing the same number of integers. -1 denotes a white stone, 1 a black stone, and 0 represents an empty vertex

Example

[[ 0,  0,  1,  0, -1, -1,  1,  0, 0],
 [ 1,  0,  1, -1, -1,  1,  1,  1, 0],
 [ 0,  0,  1, -1,  0,  1, -1, -1, 0],
 [ 1,  1,  1, -1, -1, -1,  1, -1, 0],
 [ 1, -1,  1,  1, -1,  1,  1,  1, 0],
 [-1, -1, -1, -1, -1,  1,  0,  0, 0],
 [ 0, -1, -1,  0, -1,  1,  1,  1, 1],
 [ 0,  0,  0,  0,  0, -1, -1, -1, 1],
 [ 0,  0,  0,  0,  0,  0,  0, -1, 0]]

influence.map(data[, options])

  • data - Board data
  • options <Object> (optional)
    • discrete <Boolean> (optional) - Default: false

    • maxDistance <Number> (optional) - Default: 6

      Only assigns a non-zero number to a vertex if its Manhattan distance to a stone of corresponding color is less or equal to maxDistance.

    • minRadiance <Number> (optional) - Default: 2

      Only assigns a non-zero number to a vertex if the vertex has radiance in its corresponding color greater or equal to minRadiance.

Returns an array of arrays of the same size as data. Each entry is a number between -1 and 1 inclusive. A negative number corresponds to white influence whereas a positive number denotes black influence.

This map does not take dead stones into account, i.e. it will assume all stones specified in data are alive. To get better results, remove dead stones first, either manually or with the deadstones module.

If discrete is set to true, the map will only contain -1, 0, or 1 as values.

influence.areaMap(data)

Returns an array of arrays of the same size as data. Each entry is either -1, 0, or 1, corresponding to white area, neutral area, and black area.

influence.nearestNeighborMap(data, sign)

Returns an array of arrays of the same size as data. Each entry is an non-negative integer which denotes the Manhattan distance to the nearest stone with the color given by sign. -1 denotes white and 1 corresponds to black.

influence.radianceMap(data, sign[, options])

  • data - Board data
  • sign -1 | 1
  • options <Object> (optional)
    • p1 <Number> (optional) - Default: 6
    • p2 <Number> (optional) - Default: 1.5
    • p3 <Number> (optional) - Default: 2

Returns an array of arrays of the same size as data. Each entry is a non-negative number which encodes how many stones of the color corresponding to sign is in its vicinity. -1 corresponds to white stones whereas 1 denotes black stones. Each chain of the color corresponding to sign emits radiance which diminishes over distance, adds up with the radiance of other chains, and reflects at the board edge.

p1, p2, and p3 are parameters, controlling how strong the radiance is initially and how it diminishes.

Build Demo

Make sure you have Node.js v12 and npm installed. First, clone this repository via Git, then install all dependencies with npm:

$ git clone https://github.com/SabakiHQ/influence
$ cd influence
$ npm install

Use the build-demo script to build the demo project:

$ npm run build-demo

You can use the watch-demo command for development:

$ npm run watch-demo

Open demo/index.html in your browser to run demo.

influence's People

Contributors

dependabot[bot] avatar tdkr avatar yishn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

influence's Issues

Question about castRadiance function

if (d >= p1 || data[n[1]] && data[n[1]][n[0]] == null && data[n[1]][n[0]] === -sign || n in visited)
    continue

A question about above code, isn't 'data[n[1]] && data[n[1]][n[0]] == null && data[n[1]][n[0]] === -sign' always return false?

this SGF White in right-bottom is Dead

(;GM[1]AP[StoneBase:SGFParser.3.0.1]SZ[19]HA[0]KM[7.5]EV[第5届春兰杯第一轮]PB[王立诚]BR[九段]PW[宋泰坤]WR[六段]RE[白胜5又1/4子]DT[2003-12-29]PC[**北京]SO[http://weiqi.tom.com]US[棋圣道场]C[http://weiqi.tom.com
棋圣道场-->大赛直播]
;B[pd];W[dd];B[qp];W[dq];B[oq];W[qj];B[dn];W[co];B[cf];W[ch];B[ef];W[fc];B[di];W[ce];B[bf];W[dh];B[eh];W[ci];B[dj];W[cj];B[dk];W[cl];B[dl];W[cm];B[ed];W[ec];B[cc];W[ee];B[df];W[fh];B[cd];W[eg];B[ge];W[hd];B[ei];W[dm];B[fg];W[kc];B[eq];W[ep];B[fq];W[dr];B[ql];W[qf];B[mc];W[qc];B[jc];W[jd];B[kb];W[kd];B[ib];W[ic];B[jb];W[hb];B[ie];W[id];B[qd];W[pc];B[od];W[nb];B[nc];W[mb];B[lb];W[oc];B[lc];W[rd];B[re];W[rc];B[pf];W[pg];B[og];W[of];B[nf];W[pe];B[oe];W[qe];B[ph];W[qh];B[pf];W[qg];B[kf];W[he];B[hf];W[me]C[至此中午休息,13:00继续];B[lg];W[gf];B[hg];W[jf];B[jg];W[jp];B[em];W[go];B[fo];W[fp];B[gp];W[hp];B[cn];W[bn];B[dp];W[gq];B[eo];W[cp];B[gp];W[fp];B[cq];W[do];B[ep];W[en];B[fn];W[cr];B[lq];W[hm];B[ko];W[km];B[gr];W[pq];B[op];W[jo];B[kn];W[jn];B[lm];W[kl];B[ll];W[hr];B[gp];W[hq];B[pk];W[qq];B[rp];W[pp];B[qn];W[mq];B[lr];W[mr];B[nr];W[or];B[pr];W[lp];B[kp];W[kq];B[mp];W[mo];B[lo];W[np];B[lp];W[oo];B[os];W[nq];B[ms];W[or];B[oq];W[of];B[ld];W[ng];B[pf];W[fm];B[el];W[of];B[gd];W[gc];B[pf];W[mn];B[ln];W[of];B[oh];W[le];B[pf];W[qo];B[ro];W[of];B[ke];W[mf];B[pf];W[pn];B[qm];W[of];B[je];W[hc];B[pf];W[om];B[nn];W[of];B[ob];W[pb];B[pf];W[ok];B[pj];W[of];B[oa];W[pa];B[pf];W[nm];B[mk];W[of];B[ma];W[na];B[pf];W[qr];B[sr];W[of];B[ob];W[la];B[pf];W[sq];B[rq];W[of];B[kk];W[ne];B[il];W[gn];B[fl];W[nh];B[ni];W[mi];B[nj];W[lh];B[jq];W[fr];B[er];W[gs];B[es];W[im];B[hl];W[ji];B[rj];W[ri];B[qk];W[pi];B[oi];W[qi];B[db];W[fe];B[ff];W[de];B[be];W[rk];B[rl];W[sj];B[mj];W[gm];B[dn];W[cn];B[li];W[en];B[ga];W[eb];B[dn];W[gl];B[gk];W[en];B[ea];W[ha];B[dn];W[op];B[or];W[en];B[ck];W[bk];B[dn];W[rr];B[ls];W[en];B[bq];W[br];B[dn];W[qs];B[ss];W[en];B[mh];W[dn];B[bh];W[bi];B[ah];W[mg];B[kh];W[ai];B[cg];W[dc];B[cb];W[fa];B[fb];W[gb];B[dg];W[bl];B[jr];W[fd];B[da];W[fa];B[iq];W[ip];B[gg];W[ge];B[jl];W[jm];B[sl];W[sk];B[is];W[ir];B[js];W[hs];)

demo

Demo page

We should provide a demo page where people can place stones and see how the influence changes.

falling at the first fence

this is an issue with me, rather than the software - as a non-programmer, i don't understand the meaning of the responses i got and don't know what to do about them. i was hoping it would add a View..influence feature or somesuch to Sabaki v 41 installed on my Fedora 28 machine, but this is what happened:

[d@localhost ~]$ npm install @sabaki/influence
npm WARN saveError ENOENT: no such file or directory, open '/home/d/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/d/package.json'
npm WARN d No description
npm WARN d No repository field.
npm WARN d No README data
npm WARN d No license field.

  • @sabaki/[email protected]
    added 1 package from 1 contributor and audited 1 package in 4.321s
    found 0 vulnerabilities

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.