47755 (588501), страница 15
Текст из файла (страница 15)
});
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() {
return this.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 + '\"');
}
// Ход вперед !! предыдущую фигуру удалить
function forward(){
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 + '
';
}
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();
}
// This is the main loop. It samples all boards and tries at regular intervals
// to find new boards and to mark non-answering boards as, well, non-answering.
Это головная часть. Она опрашивает все доски с регулярным интервалом времени,
чтобы найти новые доски и отметить неотвечающие доски как неотвечающие
public void run() {
rdgtController c = new rdgtController();
if (c.connect(comport) == false) return;
System.out.println(rdgtMysql.connect());
int i = 0;
while (true) {
if ((i==0) || (c.db.count_alive()==0)) {
while (c.find_all_boards()==0) {} c.dump_all_active_boards();
i = 15;
} else {
try {Thread.sleep(1000);} catch(Throwable t) {}}
c.poll_all_active_boards();
i--;















