Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailkov committed Dec 12, 2015
1 parent 7985cd6 commit 5bc805f
Showing 1 changed file with 43 additions and 61 deletions.
104 changes: 43 additions & 61 deletions share/goodie/chess960/chess960.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,57 @@ DDH.chess960 = DDH.chess960 || {};

(function(DDH) {
"use strict";
DDH.chess960.build = function(ops) {
// Global Variables Declaration
var squares, started;
var scheme = [];
var letters = ["H", "G", "F", "E", "D", "C", "B", "A"];
var position = ops.data.position;

for (var i = 0; i < position.length; i++) {
scheme[7 - i] = position.substring(i, i + 1);
}

// This function creates and prints on page chess board
function start() {
var nsquare = 63;
var squaresid = combination();
squares.each(function(index) {
$(this).attr("id", squaresid[nsquare--]);
});
drawPawns();
drawPieces();
}
// Global Variables Declaration
var squares, started;
var scheme = [];
var letters = ["H", "G", "F", "E", "D", "C", "B", "A"];
var obj = { "R" : 14, "N" : 16, "B" : 15, "Q" : 13, "K" : 12 };

// This function creates and prints on page chess board
function start() {
var nsquare = 63;
var squaresid = combination();
squares.each(function(index) {
$(this).attr("id", squaresid[nsquare--]);
});
drawPawns();
drawPieces();
}

// This function creates the names of the squares e.g "A1" "B1" ...
function combination() {
var combinations = [];
for (var i = 1; i < 9; i++) {
for (var t = 0; t < letters.length; t++) {
combinations[(i - 1) * 8 + t] = letters[t] + i;
}
// This function creates the names of the squares e.g "A1" "B1" ...
function combination() {
var combinations = [];
for (var i = 1; i < 9; i++) {
for (var t = 0; t < letters.length; t++) {
combinations[(i - 1) * 8 + t] = letters[t] + i;
}
return combinations;
}
}
return combinations;
}

function drawPawns() {
for (var i = 0; i < 8; i++) {
$("#" + letters[i] + "7 span").html("&#9823;");
$("#" + letters[i] + "2 span").html("&#9817;");
}
function drawPawns() {
for (var i = 0; i < 8; i++) {
$("#" + letters[i] + "7 span").html("&#9823;");
$("#" + letters[i] + "2 span").html("&#9817;");
}
}

function drawPieces() {
var codepiece;
for (var i = 0; i < 8; i++) {
codepiece = getCodePiece(i);
$("#" + letters[i] + "8 span").html("&#98" + (codepiece + 6) + ";");
$("#" + letters[i] + "1 span").html("&#98" + codepiece + ";");
}
function drawPieces() {
var codepiece;
for (var i = 0; i < 8; i++) {
codepiece = obj[ scheme[i] ];
$("#" + letters[i] + "8 span").html("&#98" + (codepiece + 6) + ";");
$("#" + letters[i] + "1 span").html("&#98" + codepiece + ";");
}
}

DDH.chess960.build = function(ops) {

function getCodePiece(i) {
var code;
switch (scheme[i]) {
case "R":
code = 14;
break;
case "N":
code = 16;
break;
case "B":
code = 15;
break;
case "Q":
code = 13;
break;
case "K":
code = 12;
break;
}
return code;
var position = ops.data.position;

for (var i = 0; i < position.length; i++) {
scheme[7 - i] = position.substring(i, i + 1);
}

return {
Expand Down

0 comments on commit 5bc805f

Please sign in to comment.