Обеспечение всемирной трансляции спортивных шахматных соревнований с применением разработанного в ходе проекта законченного программного продукта
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
ling = false;
self.forward = function() {
if(self.is_short_castling || self.is_long_castling) {
self.field_from[0].delete_figure();
self.field_from[1].delete_figure();
self.field_to[0].set_figure(self.figure[0]);
self.field_to[1].set_figure(self.figure[1]);
} else {
self.field_from.delete_figure();
self.field_to.set_figure(self.figure);
}
}
return self;
}
};
var Chess = {
version: "2.0",
refresh_delay: 2, // интервал времени между обновлениями позиции в секундах
repaint_delay: 0.5, // интервал времени между перерисовками позиции в секундах
moves: /main/game_moves/1,
createBoard: function() {
var board = Board.create();
board.init();
return board;
},
createField: function(vertical, horizontal) {
var self = Field.create(vertical, horizontal);
return self;
},
createFigure: function(color, type, vertical) {
var self = Figure.create(color, type, vertical);
return self;
},
createMove: function() {
var self = Move.create();
return self;
}
};
// Шахматная доска
var Board = {
create: function() {
function board() { }
var self = new board();
self.white_number = 0;
self.black_number = 0;
self.first_move = null;
self.current_move = null;
self.last_move = null;
// Могут быть состояния
// listen - следить за ходом партий, отображаются актуальные ходы
// custom - наблюдатель выбрал произвольную позицию в партии и навигирует по партии свободно
self.status = listen;
self.fields = new Array(64);
self.figures = new Array(32);
self.all_moves = ;
// Обновление позиции
self.refresh = function() {
function existsMove(color, annotation) {
var move = getMove(color, annotation);
var exists = move != "******" && move != "";
return exists;
}
function getMove(color, annotation) {
var m = annotation.substring(color == w ? 0 : 6, color == w ? 6 : 12);
return m;
}
function isCastling(color, type, annotation) {
var move = getMove(color, annotation);
var castling = (type == short ? move.substring(0, 3) == O-O : move.substring(0, 5) == O-O-O);
return castling;
}
function getField(is_short, is_long, target, color, annotation) {
if(is_short || is_long) {
if(color == w) {
if(is_short) {
return new Array(self.fields[target == from ? 4 : 6], self.fields[target == from ? 7 : 5]);
}
if(is_long) {
return new Array(self.fields[target == from ? 4 : 2], self.fields[target == from ? 0 : 3]);
}
}
if(color == b) {
if(is_short) {
return new Array(self.fields[target == from ? 60 : 62], self.fields[target == from ? 63 : 61]);
}
if(is_long) {
return new Array(self.fields[target == from ? 60 : 58], self.fields[target == from ? 56 : 59]);
}
}
}
var field = annotation.substring(color == w ? (target == from ? 1 : 4) : (target == from ? 7 : 10), color == w ? (target == from ? 3 : 6) : (target == from ? 9 : 12));
var v = field.substring(0, 1).toLowerCase();
var h = field.substring(1, 2).toLowerCase();
//log(getField: v + v + h: + h);
var iField = (parseInt(h) - 1) * 8;
//log(tmp + iField);
if(v == b) {
iField += 1;
}
if(v == c) {
iField += 2;
}
if(v == d) {
iField += 3;
}
if(v == e) {
iField += 4;
}
if(v == f) {
iField += 5;
}
if(v == g) {
iField += 6;
}
if(v == h) {
iField += 7;
}
//log(return + iField);
return self.fields[iField];
}
function getFigure(is_short, is_long, target, color, field) {
if(is_short || is_long) {
if(color == w) {
if(is_short) {
return new Array(self.figures[0], self.figures[7]);
}
if(is_long) {
return new Array(self.figures[0], self.figures[6]);
}
}
if(color == b) {
if(is_short) {
return new Array(self.figures[16], self.figures[23]);
}
if(is_long) {
return new Array(self.figures[16], self.figures[22]);
}
}
}
if(target == alive) {
return field.last_figure;
}
if(target == dead) {
return field.last_figure;
}
}
// Запрашиваем обновление позиции
new Ajax.Request(Chess.moves, {
method: get,
onSuccess: function(transport) {
self.all_moves = transport.responseText;
}
});
// Анализируем ходы партии
var splits = self.all_moves.split(|);
var moves = new Array();
for(i = 0; i < splits.length; i++) {
if(splits[i] != null) {
moves.push(splits[i
}
}
// Количество полученных ходов
var number = moves.length;
var current_number = self.last_move == null ? 1 : self.last_move.number;
if(number == current_number && self.last_move != null && self.last_move.color == w) {
var move_annotation = moves[number - 1];
if(move_annotation != && existsMove(b, moves[number - 1])) {
var move = Chess.createMove();
move.is_short_castling = isCastling(b, short, move_annotation);
move.is_long_castling = isCastling(b, long, move_annotation);
move.field_from = getField(move.is_short_castling, move.is_long_castling, from , b, move_annotation);
move.field_to = getField(move.is_short_castling, move.is_long_castling, to, b, move_annotation);
move.figure = getFigure(move.is_short_castling, move.is_long_castling, alive, b, move.field_from);
move.figure_dead = getFigure(false, false, dead, b, move.field_to);
move.number = self.last_move != null ? (b == w ? (self.last_move.number + 1) : self.last_move.number) : 1;
move.color = b;
move.field_from.last_figure = null;
move.field_to.last_figure = move.figure;
move.prev = self.last_move;
if(self.last_move != null) {
self.last_move.next = move;
}
self.last_move = move;
self.changes = true;
}
}
if(number > current_number) {
var c = [w, b];
for(var iMove = current_number; iMove <= number; iMove++) {
for(var ic = 0; ic < c.length; ic++) {
var move_annotation = moves[iMove - 1];
if(existsMove(c[ic], move_annotation)) {
var move = Chess.createMove();
if(self.first_move == null) {
self.first_move = move;
}
move.is_short_castling = isCastling(c[ic], short, move_annotation);
move.is_long_castling = isCastling(c[ic], long, move_annotation);
move.field_from = getField(move.is_short_castling, move.is_long_castling, from , c[ic], move_annotation);
move.field_to = getField(move.is_short_castling, move.is_long_castling, to, c[ic], move_annotation);
move.figure = getFigure(move.is_short_castling, move.is_long_castling, alive, c[ic], move.field_from);
move.figure_dead = getFigure(move.is_short_castling, move.is_long_castling, dead, c[ic], move.field_to);
move.number = self.last_move != null ? (c[ic] == w ? (self.last_move.number + 1) : self.last_move.number) : 1;
move.color = c[ic];
var ff = move.field_from;
var ft = move.field_to;
var fg = move.figure;
if(fg == null) {
continue;
}
move.field_from.last_figure = null;
move.field_to.last_figure = move.figure;
move.prev = self.last_move;