Socket
Socket
Sign inDemoInstall

chessboard-engine

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

default/pieces.json

16

export.js

@@ -31,4 +31,4 @@ "use strict";

for (var a = 0; a < rows.length; a++) {
var currFigure = gameInstance.figures[gameInstance.board[rows[a]][i]]
line += " " + (typeof gameInstance.board[rows[a]][i] == "number" ? ((currFigure.color == "black" ? "\x1b[30m" : "\x1b[97m") + shorts[currFigure.type]) : "\x1b[30m⊚") + " "
var currpiece = gameInstance.pieces[gameInstance.board[rows[a]][i]]
line += " " + (typeof gameInstance.board[rows[a]][i] == "number" ? ((currpiece.color == "black" ? "\x1b[30m" : "\x1b[97m") + shorts[currpiece.type]) : "\x1b[30m⊚") + " "
}

@@ -52,3 +52,3 @@ boardStr += line + "\x1b[30m\x1b[49m\n\x1b[" + bgColorNumber + "m " + (type === "text" ? " " : "") + "|" + ((i + 1) >= rows.length ? (seperateLine + (type === "text" ? "________" : "")) : linePlainStr) + "\x1b[49m\n"

var iconPath = __dirname + "/default/svg/";
var figures = {
var pieces = {
white: {

@@ -76,12 +76,12 @@ farmer: fs.readFileSync(iconPath + "farmer-white.svg", "utf8"),

for (var i = 0; i < gameInstance.board[row].length; i++) {
var figureId = gameInstance.board[row][i];
var pieceId = gameInstance.board[row][i];
var coords = [Object.keys(gameInstance.board).indexOf(row), i];
if (typeof figureId == "number") {
var figureContext = '<svg xmlns="http://www.w3.org/2000/svg" width="' + (fieldSize[0] * size) + 'px" height="' + (fieldSize[1] * size) + 'px" x="' + (coords[0] * fieldSize[1] + (fieldSize[0] / 2 - (fieldSize[0] * size / 2))) + 'px" y="' + (i * fieldSize[0] + (fieldSize[1] / 2 - (fieldSize[1] * size / 2))) + 'px">\n\n' + figures[gameInstance.figures[figureId].color][gameInstance.figures[figureId].type] + '\n\n</svg>';
if (typeof pieceId == "number") {
var pieceContext = '<svg xmlns="http://www.w3.org/2000/svg" width="' + (fieldSize[0] * size) + 'px" height="' + (fieldSize[1] * size) + 'px" x="' + (coords[0] * fieldSize[1] + (fieldSize[0] / 2 - (fieldSize[0] * size / 2))) + 'px" y="' + (i * fieldSize[0] + (fieldSize[1] / 2 - (fieldSize[1] * size / 2))) + 'px">\n\n' + pieces[gameInstance.pieces[pieceId].color][gameInstance.pieces[pieceId].type] + '\n\n</svg>';
}
else {
var figureContext = "!!!";
var pieceContext = "!!!";
}
fields += ' <rect x="' + (coords[0] * fieldSize[1]) + '" y="' + (i * fieldSize[0]) + '" width="' + fieldSize[0] + 'px" height="' + fieldSize[1] + 'px" class="field ' + (((coords[0] + coords[1]) % 2) == 0 ? "white" : "black") + '" data-coords="' + coords[0] + ',' + coords[1] + '" data-field="' + row + (gameInstance.board[row].length - i) + '"/>\n';
fields += ' ' + figureContext + '\n';
fields += ' ' + pieceContext + '\n';

@@ -88,0 +88,0 @@ }

@@ -5,3 +5,3 @@ "use strict";

board: JSON.parse(fs.readFileSync(__dirname + "/default/board.json", "utf8")),
figures: JSON.parse(fs.readFileSync(__dirname + "/default/figures.json", "utf8")),
pieces: JSON.parse(fs.readFileSync(__dirname + "/default/pieces.json", "utf8")),
rules: JSON.parse(fs.readFileSync(__dirname + "/default/rules.json", "utf8")),

@@ -11,5 +11,5 @@ Game: function() {

this.board = module.exports.board
this.figures = module.exports.figures
this.figures.forEach(function(figure) {
figure.moves = figure.moves != undefined ? figure.moves : 0
this.pieces = module.exports.pieces
this.pieces.forEach(function(piece) {
piece.moves = piece.moves != undefined ? piece.moves : 0
});

@@ -61,12 +61,12 @@ this.rules = module.exports.rules

try {
var figureId = gameInstance.board[row][gameInstance.board[row].length - line]
var pieceId = gameInstance.board[row][gameInstance.board[row].length - line]
} catch (e) {
return "invalid"
}
if (figureId == undefined) return "invalid"
var figure = figureId === false ? "empty" : ({
type: gameInstance.figures[figureId].type,
color: gameInstance.figures[figureId].color,
moves: gameInstance.figures[figureId].moves,
id: figureId,
if (pieceId == undefined) return "invalid"
var piece = pieceId === false ? "empty" : ({
type: gameInstance.pieces[pieceId].type,
color: gameInstance.pieces[pieceId].color,
moves: gameInstance.pieces[pieceId].moves,
id: pieceId,
row: row,

@@ -76,8 +76,8 @@ line: line,

})
return figure
return piece
}
function setField(field, figureId) {
function setField(field, pieceId) {
var row = field.substring(0, 1).toLowerCase()
var line = parseInt(field.substring(1))
gameInstance.board[row][gameInstance.board[row].length - line] = figureId
gameInstance.board[row][gameInstance.board[row].length - line] = pieceId
}

@@ -118,3 +118,3 @@ this.move = function(move) {

setField(move.from, false)
gameInstance.figures[from.id].moves++
gameInstance.pieces[from.id].moves++
}

@@ -147,5 +147,5 @@ result.move.from = move.from

var line = parseInt(to.substring(1))
var figureCoords = from.coords
var pieceCoords = from.coords
var targetCoords = getCoords(row, line)
var diff = [targetCoords[0] - figureCoords[0], targetCoords[1] - figureCoords[1]]
var diff = [targetCoords[0] - pieceCoords[0], targetCoords[1] - pieceCoords[1]]
return diff

@@ -152,0 +152,0 @@ }

{
"name": "chessboard-engine",
"version": "0.0.3",
"version": "0.0.4",
"description": "Chessboard controller",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc