this.A4 = new field('fieldA4', 'white', 'A', '4', null, board);
this.B4 = new field('fieldA4', 'black', 'B', '4', null, board);
this.C4 = new field('fieldC4', 'white', 'C', '4', null, board);
this.D4 = new field('fieldD4', 'black', 'D', '4', null, board);
this.E4 = new field('fieldE4', 'white', 'E', '4', null, board);
this.F4 = new field('fieldF4', 'black', 'F', '4', null, board);
this.G4 = new field('fieldG4', 'white', 'G', '4', null, board);
this.H4 = new field('fieldH4', 'black', 'H', '4', null, board);
this.A5 = new field('fieldA5', 'black', 'A', '5', null, board);
this.B5 = new field('fieldB5', 'white', 'B', '5', null, board);
this.C5 = new field('fieldC5', 'black', 'C', '5', null, board);
this.D5 = new field('fieldD5', 'white', 'D', '5', null, board);
this.E5 = new field('fieldE5', 'black', 'E', '5', null, board);
this.F5 = new field('fieldF5', 'white', 'F', '5', null, board);
this.G5 = new field('fieldG5', 'black', 'G', '5', null, board);
this.H5 = new field('fieldH5', 'white', 'H', '5', null, board);
this.A6 = new field('fieldA6', 'white', 'A', '6', null, board);
this.B6 = new field('fieldB6', 'black', 'B', '6', null, board);
this.C6 = new field('fieldC6', 'white', 'C', '6', null, board);
this.D6 = new field('fieldD6', 'black', 'D', '6', null, board);
this.E6 = new field('fieldE6', 'white', 'E', '6', null, board);
this.F6 = new field('fieldF6', 'black', 'F', '6', null, board);
this.G6 = new field('fieldG6', 'white', 'G', '6', null, board);
this.H6 = new field('fieldH6', 'black', 'H', '6', null, board);
this.A7 = new field('fieldA7', 'black', 'A', '7', null, board);
this.B7 = new field('fieldB7', 'white', 'B', '7', null, board);
this.C7 = new field('fieldC7', 'black', 'C', '7', null, board);
this.D7 = new field('fieldD7', 'white', 'D', '7', null, board);
this.E7 = new field('fieldE7', 'black', 'E', '7', null, board);
this.F7 = new field('fieldF7', 'white', 'F', '7', null, board);
this.G7 = new field('fieldG7', 'black', 'G', '7', null, board);
this.H7 = new field('fieldH7', 'white', 'H', '7', null, board);
this.A8 = new field('fieldA8', 'white', 'A', '8', null, board);
this.B8 = new field('fieldB8', 'black', 'B', '8', null, board);
this.C8 = new field('fieldC8', 'white', 'C', '8', null, board);
this.D8 = new field('fieldD8', 'black', 'D', '8', null, board);
this.E8 = new field('fieldE8', 'white', 'E', '8', null, board);
this.F8 = new field('fieldF8', 'black', 'F', '8', null, board);
this.G8 = new field('fieldG8', 'white', 'G', '8', null, board);
this.H8 = new field('fieldH8', 'black', 'H', '8', null, board);
}
function board() {
this.moves = new move_collection(this);
this.figures = new figure_collection(this);
this.fields = new field_collection(this);
this.init = init;
this.last_move = null;
// Обновляет позицию
this.refresh_moves = function() {
// Ajax запрос к серверу
new Ajax.Request(moves_url, {
method: 'get',
onSuccess: function(transport) {
all_moves = transport.responseText;
trace('ajax: ' + all_moves);
}
});
trace('call => parse_moves(' + all_moves + ')')
function existsWhite(move) {
return getWhiteMove(move) != "******";
}
function existsBlack(move) {
return getBlackMove(move) != "******";
}
function getWhiteMove(move) {
return move.substring(0,6);
}
function getWhiteTime(move) {
return move.substring(13, 19);
}
function getBlackMove(move) {
return move.substring(6,12);
}
function getBlackTime(move) {
return move.substring(20, 26);
}
function getFrom(color, move) {
}
function getTo(color, move) {
}
function isShortCastling(color, move) {
}
function isLongCastling(color, move) {
}
moves_split = all_moves.split('|');
moves_strip = new Array();
for(i = 0; i < moves_split.length; i++) {
if(moves_split[i] != "") {
moves_strip.push(moves_split[i]);
trace('split: ' + moves_split[i]);
}
}
var number = moves_strip.length;
trace('number = ' + number);
var current_move = this.moves.get_current_move();
trace('current_move = ' + current_move);
var current_number = current_move != null ? current_move.number : 0;
trace('current_number = ' + current_number);
if(number == current_number) {
if((current_move.color == 'white') && existsBlack(moves_strip[number - 1])) {
var move_annotation = getBlackMove(moves_strip[number - 1]);
var move_time = getBlackTime(moves_strip[number - 1]);
var fieldFrom = getFrom('black', move_annotation);
var fieldTo = getTo('black', move_annotation);
var move = new move(number, 'black', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('black', move_annotation), isLongCastling('black', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
}
if(number > current_number){
for(iMove = current_move; iMove < number; iMove++) {
var move_annotation = getWhiteMove(moves_strip[number - 1]);
if(existsWhite(move_annotation)) {
var move_time = getWhiteTime(moves_strip[number - 1]);
var fieldFrom = getFrom('white', move_annotation);
var fieldTo = getTo('white', move_annotation);
var move = new move(iMove + 1, 'white', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('white', move_annotation), isLongCastling('white', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
move_annotation = getBlackMove(moves_strip[number - 1]);
if(existsBlack(move_annotation)) {
var move_time = getBlackTime(moves_strip[number - 1]);
var fieldFrom = getFrom('black', move_annotation);
var fieldTo = getTo('black', move_annotation);
var move = new move(iMove + 1, 'black', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('black', move_annotation), isLongCastling('black', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
}
}
}
this.refresh_figures = refresh_figures;
this.go_begin = go_begin;
this.go_end = go_end;
this.go_next = go_next;
this.go_preview = go_preview;
this.go_custom = go_custom;
this.repaint = function() {
}
// Парсит данные пришедшие от сервера
this.parse_moves = function() {
var moves = this.all_moves;
trace('call => parse_moves(' + moves + ')')
function existsWhite(move) {
return getWhiteMove(move) != "******";
}
function existsBlack(move) {
return getBlackMove(move) != "******";
}
function getWhiteMove(move) {
return move.substring(0,6);
}
function getWhiteTime(move) {
return move.substring(13, 19);
}
function getBlackMove(move) {
return move.substring(6,12);
}
function getBlackTime(move) {
return move.substring(20, 26);
}
function getFrom(color, move) {
}
function getTo(color, move) {
}
function isShortCastling(color, move) {
}
function isLongCastling(color, move) {
}
moves_split = moves.split('|');
moves_strip = new Array();
for(i = 0; i < moves_split.length; i++) {
if(moves_split[i] != null) {
moves_strip.push(moves_split[i]);
}
}
var number = moves_strip.length;
var current_move = this.moves.get_current_move;
var current_number = current_move != null ? current_move.number : 0;
if(number == current_number) {
if((current_move.color == 'white') && existsBlack(moves_strip[number - 1])) {
var move_annotation = getBlackMove(moves_strip[number - 1]);
var move_time = getBlackTime(moves_strip[number - 1]);
var fieldFrom = getFrom('black', move_annotation);
var fieldTo = getTo('black', move_annotation);
var move = new move(number, 'black', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('black', move_annotation), isLongCastling('black', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
}
if(number > current_number){
for(iMove = current_move; iMove < number; iMove++) {
var move_annotation = getWhiteMove(moves_strip[number - 1]);
if(existsWhite(move_annotation)) {
var move_time = getWhiteTime(moves_strip[number - 1]);
var fieldFrom = getFrom('white', move_annotation);
var fieldTo = getTo('white', move_annotation);
var move = new move(iMove + 1, 'white', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('white', move_annotation), isLongCastling('white', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
move_annotation = getBlackMove(moves_strip[number - 1]);
if(existsBlack(move_annotation)) {
var move_time = getBlackTime(moves_strip[number - 1]);
var fieldFrom = getFrom('black', move_annotation);
var fieldTo = getTo('black', move_annotation);
var move = new move(iMove + 1, 'black', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('black', move_annotation), isLongCastling('black', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
}
}
}
// Настройки
this.all_moves = "";
this.moves_delay = 3;
this.moves_url = '/main/game_moves/1';
this.figures_delay = 2;
}
// Инициализация доски
function init() {
trace('call => init()');
// Расставляем шахматы в начальную позицию
// белые пешки
this.figures.wpA.set_field(this.fields.A2);
this.figures.wpB.set_field(this.fields.B2);
this.figures.wpC.set_field(this.fields.C2);
this.figures.wpD.set_field(this.fields.D2);
this.figures.wpE.set_field(this.fields.E2);
this.figures.wpF.set_field(this.fields.F2);
this.figures.wpG.set_field(this.fields.G2);
this.figures.wpH.set_field(this.fields.H2);
// белые фигуры
this.figures.wrA.set_field(this.fields.A1);
this.figures.wrH.set_field(this.fields.H1);
this.figures.whB.set_field(this.fields.B1);
this.figures.whG.set_field(this.fields.G1);
this.figures.wbC.set_field(this.fields.C1);
this.figures.wbF.set_field(this.fields.F1);
this.figures.wq.set_field(this.fields.D1);
this.figures.wk.set_field(this.fields.E1);
// черные пешки
this.figures.bpA.set_field(this.fields.A7);
this.figures.bpB.set_field(this.fields.B7);
this.figures.bpC.set_field(this.fields.C7);
this.figures.bpD.set_field(this.fields.D7);
this.figures.bpE.set_field(this.fields.E7);
this.figures.bpF.set_field(this.fields.F7);
this.figures.bpG.set_field(this.fields.G7);
this.figures.bpH.set_field(this.fields.H7);
// черные фигуры
this.figures.brA.set_field(this.fields.A8);
this.figures.brH.set_field(this.fields.H8);
this.figures.bhB.set_field(this.fields.B8);
this.figures.bhG.set_field(this.fields.G8);
this.figures.bbC.set_field(this.fields.C8);
this.figures.bbF.set_field(this.fields.F8);
this.figures.bq.set_field(this.fields.D8);
this.figures.bk.set_field(this.fields.E8);
// Создаем Ajax опрашиватель сервера
new PeriodicalExecuter(this.refresh_moves, this.moves_delay);
new PeriodicalExecuter(this.refresh_figures, this.figures_delay);
}
// Перерисовка позиции (делает один ход)
function refresh_figures() {
//trace('call => refresh_figures');
if(this.exists_move) {
this.current_move = this.moves.get_current_move();
this.current_move.forward();
}
}
// Перейти к началу
function go_begin() {
}
// Перейти к концу
function go_end() {
}
// Следующий ход
function go_next() {
}
// Предыдущий ход
function go_preview() {
}
// Перейти к произвольному ходу
function go_custom(number, color) {
}
// сделать ход
function do_move(from_field, to_field) {
}
// Возвращает поле
function get_field(vertical, horizontal) {
}
// Установить фигуру на поле
function set_field(field_to_set) {
this.last_field = field_to_set;
field_to_set.figure = this;
field_to_set.repaint();
}
// Возвращает ход по номеру и цвету
function get_move(number, color) {
}
// Возвращает текуший ход
function get_current_move() {
returnthis.current_move;
}
// Возвращает true если есть ход который нужно совершить
function exists_move() {
}
function repaint() {
$(this.id).innerHTML = '';
if(this.figure != null) {
$(this.id).appendChild(this.figure.img);
}
}
function reload() {
this.img.src = images + this.color[0] + this.type[0] + '.gif';
//trace('reload figure [' + this.id + '].src = \"' + this.img.src + '\"');
}
// Ход вперед !! предыдущую фигуру удалить
functionforward(){
if(this.to_field.figure != null) {
}
this.figure.do_move(this.from_field, this.to_field);
}
// Ход назад
function backward() {
this.figure.do_move(this.to_field, this.from_field);
this.alive_figure.set_field(this.to_field);
}
function trace(message) {
$("debug").innerHTML += message + '<br />';
}
window.onload=function() {
// Запуск
var main_board = new board();
main_board.init();
// setBeginingPosition();
// refreshGame();
// new PeriodicalExecuter(refreshGame, periodicalDelay);
// new PeriodicalExecuter(refreshBoard, 1);
}
Приложение Г
Листинг программы-регистратора шахматных партий
rdgtChess.java
---
public class rdgtChess implements Runnable
static boolean debug = false;
String comport = "COM1";
public static void main(String[] args) {
rdgtChess t;
if(args.length > 0)
t = new rdgtChess(args[0]);
else
t = new rdgtChess();
}
public rdgtChess() {
(new Thread(this)).start();
}
public rdgtChess(String comport) {
this.comport = comport;
(new Thread(this)).start();
}
// Destructor
public void finalize()
{
rdgtMysql.disconnect();
}