Actual version of WGo player
Information text about WGo
Constant for black color.
Constant for white color.
Directory of WGo.js file.
True if current browser is Opera.
True if current browser is Webkit browser.
True if current browser is Firefox.
True if current browser is IE.
Language of the WGo. Default is en. You can change this variable, but WGo.i18n[WGo.lang] should exist.
Object with terms. Its structure is like this: {en: {key1: term1, ... , keyN: termN}}. All output texts should be saved in this object in order to be translated. If you want to add support of your language you can extend this object.
If set true users will see all errors, otherwise they stay hidden. Actually it does nothing in standalone WGo.js, however WGo.js Player use this constant. Default: true.
Helper function for class inheritance.
Helper function for deep copy of simple JSON-like objects.
Escapes html tags in text. To avoid XSS.
Function for output. It returns appropriate term in currently active language.
$ in target term will be replaced by arguments. First $ is replaced with arg1, second $ with arg2 etc.
WGo.i18n[WGo.lang][key] is checked, then WGo.i18n.en[key]. If both variables are undefined it returns argument key.
WGo.Board is a class that produces HTML5 canvas go board. Through its interface you can add and remove objects like stones on the board.
Board consists of 3 canvas layers. Bottom layer contains a grid, second layer is for stone's shadows and finally the topmost layer is for stones and other objects. However you can add your own layer for your own purposes, just extend Board.CanvasLayer class.
Constructor - creates instance of WGo.Board class.
{key1: value1, ..., keyN: valueN}. All configurations are optional. Possible configurations are:
WGo.Board.DrawHandlers.NORMAL){top: number, right: number, bottom: number, left: number}WGo.DIR+"wood1.jpg")Font used in board drawings.
Line width use in some objects (eg circle marker).
Draw handler used for stones.
Final size of star points in pixels is computed according to field size, however it is multiplied with this constant.
Final size of stones (and other common objects) in pixels is computed according to field size, however it is multiplied with this constant. It shouldn't be greater than 1.
Final size of shadows in pixels is computed according to field size, however it is multiplied with this constant. It shouldn't be greater than 1.
Size of stone radius in pixels. It shouldn't be changed.
Main HTML element of the board. You shouldn't change it, however you can alter it - for example change style.
Initialization method, it is called in constructor. You shouldn't call it, but you can alter it.
Sets new width of board and redraws it, height is computed to keep correct aspect ratio.
Sets new height of board and redraws it, width is computed to keep correct aspect ratio.
Sets both dimensions, aspect ratio is not kept.
Sets section of the board to be displayed.
{top: number, right: number, bottom: number, left: number}Sets size of the board. Most common values are 19, 13 and 9. All objects on the board's fields will be removed.
Returns currently visible section of the board.
Object Section of the board.
Redraws board and every object on it.
Returns absolute coordinates of column.
number X coordinate in pixels.
Returns absolute coordinates of row.
number Y coordinate in pixels.
Adds layer to the board. It is meant to be only for canvas layers.
Removes layer from the board.
Adds object on given coordinates of the board. Object should occupy only one board's field, otherwise they won't be properly painted. This method is meant for stones and markers.
{x: number, y: number, type: WGo.Board.DrawHandler|string|undefined}. X and Y coordinates are required, you must use relative coordinates. Object's type can be WGo.Board.DrawHandler or name of predefined handler, in that case WGo.Board.DrawHandlers[name] must be valid handler. If you omit object's type, default stone handler will be used. Object can have additional paarmeters which are passed to draw handler.Adding a black stone with label.
board.addObject([
{x: 3, y: 3, c: WGo.B},
{x: 3, y: 3, type: "LB", text: "A"}
]);
Removes object from the board.
Remove all objects on given coordinates.
Remove all objects on the board. This method won't remove custom objects.
Adds custom object on the board.
Removes custom object from the board.
Adds event listener to the board. It should be mouse event listener. It is attached to board's main HTML element.
callback(x, y, event) where x and y are relative board's coordinates of mouse pointer and event is original event object.Removes event listener from the board.
Get current board state (all objects on the board). It actually returns deep copy of the state.
Object State object of the board. It is composed of two objects: {objects: Array, custom: Array}, in variable objects they are stored normal objects, in array custom they are stored custom objects.
Restores state from board's state object and redraws board.
board.getState(). It may contain only one component (objects or custom), in that case the omitted component won't be affected.
This class creates HTML5 canvas element.
Constructor - creates instance of WGo.Board.CanvasLayer class.
HTML canvas element of the layer. You shouldn't change it, however you can work with it.
Canvas context used for drawing.
Sets dimensions of the canvas.
Draws something on the canvas. This method is called by board at the beginnig of drawing. CanvasLayer itself draw nothing.
Clears the canvas.
This canvas layer serves for board's grid. It makes sure the grid is properly painted.
This canvas layer serves for stone's shadows. It assures correct transformation of shadows.
Actually this is not a class but interface. Objects that implement this interface can be used for painting on any board's layer.
DrawHandler object has this structure: {stone: DrawObject, shadow: DrawObject, grid: DrawObject}. All properties are optional. Property 'stone' is for painting on stone layer, property 'shadow' is for painting on shadow layer and finally property 'grid' is for painting on grid layer.
DrawObject defines the drawing, it has this interface: {draw: Function, clear: Function}.
DrawHandler of default stone.
var stone = {
// draw handler for stone layer
stone: {
// drawing function - args object contain info about drawing object, board is main board object
// this function is called from canvas2D context
draw: function(args, board) {
var xr = board.getX(args.x),
yr = board.getY(args.y),
sr = board.stoneRadius,
radgrad;
// set stone texture
if(args.c == WGo.W) {
radgrad = this.createRadialGradient(xr-2*sr/5,yr-2*sr/5,2,xr-sr/5,yr-sr/5,4*sr/5);
radgrad.addColorStop(0, '#fff');
radgrad.addColorStop(1, '#d4d4d4');
}
else {
radgrad = this.createRadialGradient(xr-2*sr/5,yr-2*sr/5,1,xr-sr/5,yr-sr/5,4*sr/5);
radgrad.addColorStop(0, '#666');
radgrad.addColorStop(1, '#000');
}
// paint stone
this.beginPath();
this.fillStyle = radgrad;
this.arc(xr-0.5, yr-0.5, sr-0.5, 0, 2*Math.PI, true);
this.fill();
}
},
// adding shadow handler
shadow: {
draw: function(args, board) {
var xr = board.getX(args.x),
yr = board.getY(args.y),
sr = board.stoneRadius;
this.beginPath();
this.fillStyle = 'rgba(32,32,32,0.5)';
this.arc(xr-0.5, yr-0.5, sr-0.5, 0, 2*Math.PI, true);
this.fill();
}
}
};
Static object with predefined draw handlers. It contains these items:
Simple helper class for storing game's position. Class was initially created for storing stone's colors: WGo.W|WGo.B|0, however it can be used for storing any values.
Constructor - creates an empty position.
Size of the position. It cannot be changed.
Returns specified field of position.
Sets new value of specified field of position.
Clears the whole position by filling each field with 0.
Creates shallow copy of the position.
This class implements game logic. It basically analyses and saves given moves and returns captured stones. WGo.Game also stores every position from the beginning, so it has ability to check repeating positions and it can effectively restore old positions.
Constructor - creates an Game's class instance.
Size of the game. It cannot be changed.
Defines how to handle repeated position. More info in the constructor.
What color should be played next.
Returns current position - the position on the top of the stack.
Plays a move. It also creates a new position and puts it on the top of the stack.
{x: number, y: number}. If move is invalid method returns error code:
Plays a pass. It also clones a position and puts it on the top of the stack.
Checks validity of given move
Checks if given coordinates lie on the board
Adds stone into the current position. If field isn't empty, stone won't be added. It can be used for setting of position.
Removes stone from the current position. It can be used for setting of position.
Sets stone in the current position. It can be used for setting of position.
Returns stone on given position.
Adds given position on the top of the stack.
position.capCount = {black: number, white: number}, so if you are creating your own position you should add this property to the position object.
Removes position from the top of the stack.
Removes all positions.
Returns actual number of captured stones of given player.
number Count of captured stones.
Validate actual position. Position is tested from 0:0 to size-1:size-1 field by field. If there are some moves, that should be captured, they will be removed. You can use this, after insertion of more stones.
Array Array of removed stones in form: {x: number, y: number}.