Javascript:engine xx.js

From MediaWiki for e-dama.net
Revision as of 13:18, 7 April 2012 by Čedomir Igaly (talk | contribs) (Created page with "File: '''engine_xx.js''' or '''engine_xx.min.js''' (minimized version with same functionality, smaller in size) where 'xx' should be one of: {| |20 |International draughts |-...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

File: engine_xx.js or engine_xx.min.js (minimized version with same functionality, smaller in size) where 'xx' should be one of:

20 International draughts
21 English draughts (checkers)
22 Italian draughts
23 American pool draughts
24 Spanish draughts
25 Russian draughts
26 Brazilian draughts
27 Canadian draughts
28 Portuguese draughts
29 Czech draughts
30 Turkish draughts
31 Thai draughts
40 Frisian draughts
41 Russian draughts 10x8
125 Croda
126 Armenian draughts
127 German draughts

Use: draughts_engine(xx) will return engine as javascript object with following members:

gameType number game type as defined in previous table
rows number number of rows on board
columns number number of columns on board
squares number number of squares used for playing
piecesPerSide number pieces on each side in initiali position
firstMoveWhite boolean true if white plays first move
immediatePromotion boolean true if man reaching the promotion row during the capture should be immediately promoted to king (Russian draughts)
turkishCapture boolean true if pieces are removed during the capture, not after end of complete capturing move (Turkish and Armenian draughts)
captureSeparator string character used to separate squares in capturing move (usually 'x' or ':')
encodeSquare function(x), x - number, returns string function that maps square number (zero for leftmost active square in topmost row) to used notation (numeric ar alphanumeric)
decodeSquare function(x), x - string, returns number function that maps used notation to square number (zero for leftmost active square in topmost row)
initialPosition function (), returns array of numbers function that returns initial position on board. Returned position is array of numbers, each numbers is for piece occupying one square:

1 - white man 2 - white king -1 - black man -2 - black king 0 - empty square

packPosition function(position), position - array of numbers, returns string function that packs position as array of numbers to string
unpackPosition function(packed), packed - string, returns array of numbers function that unpacks position packed to string with packPosition function
validMoves function(position, whiteMove), position - array of numbers or string, whiteMove boolean, returns array of move objects function for selecting all valid moves in specified position (can be array or string as result of packPosition function) with selected player on move.

TODO : Define returned objects

findMove function(move, validMovesList), move - string, validMovesList - array of move objects, returns move object function that is locating move represented as string in current notation in list of valid moves and returns corresponding move object.
makeMove function(move, position, whiteMove), move - move object or string, position array of numbers, whiteMove boolean, returns object. function that is making desired move (can be move object or string) in specified position (array of numbers) with selected player on move.

Returned object members: move - move object, position - position after move is played, changed - array of squares (numbers) changed during the move.

advanceMove function(game), game - object: num - number (move number), whiteMove - boolean functon that is changing side that is on the move (black to white and vice versa) and incrementing move number if needed.
checkForPromotion function(piece, square), piece - number, square - number, returns boolean check is man has reached promotion row
mapping function() function for mapping square number (starting from zero to number of squares minus one) to row, column, and square colour and vice versa. It can be called with two or three arguments.

When called with two arguments (square number and boolean saying if board is positioned upside-down) returns object: row - number, row number, zero for topmost row; column - number, column number, zefo for leftmost row; black - boolean, true if square is black.

When called with three arguments (row and column numbers, and boolean saying if board is positioned upside-down) returns object: active - boolean, true for active square (i.e. square that is used for playing); black - boolean, true if square is black; number - number, square number (zero based), only for active sqaures.