Class: Board

Board

new Board(width, heightopt)

Go board class for storing intersection states. Also has listeners that are notified on any changes to the board via setType() and setMark().
Parameters:
Name Type Attributes Description
width int The width of the board
height int <optional>
The height of the board
Source:

Methods

addListener(func)

Add listener to the board. Listeners are passed an event object with event type ('type' or 'mark'), coordinate and board members, and new and old values as newVal and oldVal. Event object should be considered read only.
Parameters:
Name Type Description
func function A listener callback.
Source:

clear()

Clear board.
Source:

each(func, i1opt, j1opt, i2opt, j2opt)

Simple iteration over all coordinates.
Parameters:
Name Type Attributes Description
func func The iterator method, which is called with the coordinate, type and mark parameters.
i1 int <optional>
Column start.
j1 int <optional>
Row start.
i2 int <optional>
Colunm end.
j2 int <optional>
Row end.
Source:

filter(c, t) → {Object}

Filter coordinates based on intersection type.
Parameters:
Name Type Description
c Object An array of Coordinates.
t Object A type filter (return only matching type).
Source:
Returns:
Object with attributes 'type' and 'mark', array or false.
Type
Object

getAdjacent(c) → {Array}

Get neighboring coordinates on board.
Parameters:
Name Type Description
c Coordinate The coordinate
Source:
Returns:
The array of adjacent coordinates of given type (may be an empty array)
Type
Array

getCoordinate(s)

Create coordinate from "J18" type of notation that depend from board size.
Parameters:
Name Type Description
s string The coordinate string.
Source:

getGroup(coord, overrideTypeopt) → {Object}

Search all intersections of similar type, return group and edge coordinates.
Parameters:
Name Type Attributes Description
coord Coordinate The coordinate from which to start search.
overrideType int <optional>
Treat current coordinate as this type.
Source:
Returns:
Two arrays of coordinates in members 'group' and 'neighbors'.
Type
Object

getMark(c) → {Object}

Get the intersection mark(s) at given coordinate(s).
Parameters:
Name Type Description
c Object A Coordinate or an Array of them.
Source:
Returns:
Mark or array of marks.
Type
Object

getRaw() → {Object}

Get a raw copy of board contents. Will not include any listeners!
Source:
Returns:
Board contents.
Type
Object

getType(c) → {Object}

Get the intersection type(s) at given coordinate(s).
Parameters:
Name Type Description
c Object A Coordinate or an Array of them.
Source:
Returns:
Type or array of types.
Type
Object

hasType(c, t) → {bool}

Check if coordinates contain given type.
Parameters:
Name Type Description
c Object An array of Coordinates.
t Object A type filter (return only matching type).
Source:
Returns:
True or false.
Type
bool

playMove(jboard, coord, stone, koopt) → {Object}

Calculate impact of a move on board. Returns a data structure outlining validness of move (success & errorMsg) and possible captures and ko coordinate.
Parameters:
Name Type Attributes Description
jboard Board Board to play the move on (stays unchanged).
coord Coordinate Coordinate to play or null for pass.
stone int Stone to play - BLACK or WHITE.
ko Coordinate <optional>
Coordinate of previous ko.
Source:
Returns:
Move result data structure.
Type
Object

removeListener(func)

Remove listener from the board.
Parameters:
Name Type Description
func function A listener callback.
Source:

setMark(c, m)

Set the intersection mark at given coordinate(s).
Parameters:
Name Type Description
c Object A Coordinate or Array of them.
m Object New mark, e.g. MARK.NONE, MARK.TRIANGLE, ...
Source:

setRaw(raw)

Set a raw copy of board contents. Will not change or call any listeners!
Parameters:
Name Type Description
raw Object Board contents.
Source:

setType(c, t)

Set the intersection type at given coordinate(s).
Parameters:
Name Type Description
c Object A Coordinate or Array of them.
t Object New type, e.g. CLEAR, BLACK, ...
Source:

toString(c) → {string}

Make a human readable "J18" type string representation of the coordinate.
Parameters:
Name Type Description
c Coordinate Coordinate.
Source:
Returns:
representation.
Type
string