chessboard-engine
Advanced tools
Comparing version 0.0.6 to 0.0.7
34
main.js
@@ -17,3 +17,3 @@ "use strict"; | ||
checkUnused: function(move, way, valid) { | ||
var fromField = getField(move.from) | ||
var fromField = getPiece(move.from) | ||
if (fromField.moves <= 0 && way.length - 1 <= 2) { | ||
@@ -29,4 +29,4 @@ return { | ||
farmerHits: function(move, way, valid) { | ||
var fromField = getField(move.from) | ||
var toField = getField(move.to) | ||
var fromField = getPiece(move.from) | ||
var toField = getPiece(move.to) | ||
var diff = getDiff(fromField, move.to) | ||
@@ -57,3 +57,3 @@ if (toField.color) { | ||
} | ||
function getField(field) { | ||
function getPiece(field) { | ||
var row = field.substring(0, 1).toLowerCase() | ||
@@ -86,4 +86,4 @@ var line = parseInt(field.substring(1)) | ||
move.test = move.test == undefined ? false : move.test | ||
var from = getField(move.from) | ||
var to = getField(move.to) | ||
var from = getPiece(move.from) | ||
var to = getPiece(move.to) | ||
if (from === "empty" || from === "invalid" || to === "invalid") return (to === "invalid" ? to : from).firstCharToUpperCase() + " field!"; | ||
@@ -173,3 +173,3 @@ var result = { | ||
function getWay(from, to) { | ||
var fromField = getField(from) | ||
var fromField = getPiece(from) | ||
var diff = getDiff(fromField, to) | ||
@@ -200,3 +200,3 @@ var ratio = [Math.abs(diff[1]) / Math.abs(diff[0]), Math.abs(diff[0]) / Math.abs(diff[1])] | ||
var way = getWay(move.from, move.to) | ||
var fromField = getField(move.from) | ||
var fromField = getPiece(move.from) | ||
var rules = gameInstance.rules[fromField.type] | ||
@@ -208,3 +208,3 @@ var isValid = { | ||
max: (rules.max >= (way.way.length - 1) ? true : (rules.max != false ? false : true)), | ||
target: getField(move.to).color === fromField.color ? false : true | ||
target: getPiece(move.to).color === fromField.color ? false : true | ||
} | ||
@@ -231,3 +231,3 @@ if (rules.special) { | ||
var coords = way.way[i] | ||
if (i > 0 && i < way.way.length - 1) obstacles += getField(Object.keys(gameInstance.board)[coords[0]] + (gameInstance.board[Object.keys(gameInstance.board)[coords[0]]].length - coords[1])) === "empty" ? 0 : (rules.jump != true ? 1 : 0) | ||
if (i > 0 && i < way.way.length - 1) obstacles += getPiece(Object.keys(gameInstance.board)[coords[0]] + (gameInstance.board[Object.keys(gameInstance.board)[coords[0]]].length - coords[1])) === "empty" ? 0 : (rules.jump != true ? 1 : 0) | ||
} | ||
@@ -240,4 +240,10 @@ return obstacles | ||
} | ||
function getFieldRelation(field, relation) { | ||
field = getField(field) | ||
function getFieldRelation(fieldName, relation) { | ||
var field = getPiece(fieldName) | ||
if (field === "empty") { | ||
field = { | ||
row: fieldName.substring(0, 1).toLowerCase(), | ||
line: parseInt(fieldName.substring(1)) | ||
} | ||
} | ||
var targets = [] | ||
@@ -254,3 +260,3 @@ var rows = Object.keys(gameInstance.board) | ||
} | ||
if (getField(move.from) !== "empty") { | ||
if (getPiece(move.from) !== "empty") { | ||
var valid = rulesValid(move) | ||
@@ -262,3 +268,3 @@ if (valid.success) { | ||
} | ||
result[relation == "targets" ? "hit" : "attacker"] = relation == "targets" ? (getField(move.to) === "empty" ? false : getField(move.to)) : getField(move.from) | ||
result[relation == "targets" ? "hit" : "attacker"] = relation == "targets" ? (getPiece(move.to) === "empty" ? false : getPiece(move.to)) : getPiece(move.from) | ||
targets.push(result) | ||
@@ -265,0 +271,0 @@ } |
{ | ||
"name": "chessboard-engine", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Chessboard controller", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -22,3 +22,3 @@ # Chessboard | ||
This returns the general chess instance containing the Game() prototype and objects containing board, pieces and rules. | ||
This three objects are loaded from external files and may be used by the Game() prototype to get a board, pieces or rules. | ||
These three objects are loaded from external files and may be used by the Game() prototype to get a board, pieces or rules. | ||
@@ -25,0 +25,0 @@ Before we see how the module works in general, let#s have a look at the structure of these three objects. |
3
155311
20
548