Обеспечение всемирной трансляции спортивных шахматных соревнований с применением разработанного в ходе проекта законченного программного продукта
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
p>
case BBISHOP: s.append("b"); break;
case BKING: s.append("k"); break;
case BQUEEN: s.append("q"); break;
default: counter++; break;
}
}
if (counter != 0)
s.append(counter);
s.append("/");
counter = 0;
}
String outfen= s.toString().substring(0,s.toString().length()-1);
switch(b.board.address.intValue()){
case 3737:
case 3811:
case 2896:
case 3740:
case 3588:
case 2897:
default:
rotated=false; break;
}
if(rotated){
String newFen="";
=0;i--){"> for(int i=outfen.length()-1;i>=0;i--){
newFen += outfen.charAt(i);
}
outfen=newFen;
}
return outfen;
}
static void update_snapshot(rdgtSnapshot b)
{
if (conn != null)
{
String fen = snapshot2fen(b);
String turn;
if(rotated){
if(b.isWhiteTurn()) turn="Black";
else turn="White";
}
else{
if(b.isWhiteTurn()) turn="White";
else turn="Black";
}
String sql_command = "UPDATE "+update_table+" SET fen = "+fen+",wtime="+b.getTimeWhite()+",btime="+b.getTimeBlack()+",turn="+turn+" WHERE dgt_active like n% AND dgt_board = "+b.board.address;
execute(sql_command);
System.out.println(b.board.address+" "+fen+" "+b.getTimeWhite()+" "+b.getTimeBlack()+" "+turn.substring(0,1));
}
}
static void update_moves(String moves, String movestable, int board_id)
{
if (conn != null)
{
int t=0;
20)t=moves.length()-20;"> if(moves.length()>20) t=moves.length()-20;
System.out.println(board_id + " Moves: " + moves.substring(t));
String sql_command = "UPDATE games SET moves = "+moves+" WHERE dgt_active like %Moves% AND dgt_board = "+board_id;
execute(sql_command);
}
}
}
rdgtProtocol.java
---
class rdgtProtocol {
static int DGT_TO_BUSMODE = 0x4a;
static int DGT_BUS_SEND_CLK = 0x01 | 0x80;
static int DGT_BUS_SEND_BRD = 0x02 | 0x80;
static int DGT_BUS_SEND_CHANGES = 0x03 | 0x80;
static int DGT_BUS_REPEAT_CHANGES = 0x04 | 0x80;
static int DGT_BUS_SET_START_GAME = 0x05 | 0x80;
static int DGT_BUS_SEND_FROM_START = 0x06 | 0x80;
static int DGT_BUS_PING = 0x07 | 0x80;
static int DGT_BUS_END_BUSMODE = 0x08 | 0x80;
static int DGT_BUS_RESET = 0x09 | 0x80;
static int DGT_BUS_IGNORE_NEXT_BUS_PING = 0x0a | 0x80;
static int DGT_BUS_SEND_VERSION = 0x0b | 0x80;
static int DGT_BUS_BRD_DUMP = 0x03 | 0x80;
static int DGT_BUS_BWTIME = 0x04 | 0x80;
static int DGT_BUS_UPDATE = 0x05 | 0x80;
static int DGT_BUS_FROM_START = 0x06 | 0x80;
static int DGT_BUS_START_GAME_WRITTEN = 0x08 | 0x80;
static int DGT_BUS_VERSION = 0x09 | 0x80;
static boolean is_busmessage(int m) {
return (m== DGT_BUS_BRD_DUMP || m == DGT_BUS_BWTIME ||
m == DGT_BUS_UPDATE || m == DGT_BUS_FROM_START || m == DGT_BUS_PING ||
m == DGT_BUS_START_GAME_WRITTEN || m == DGT_BUS_VERSION);
}
static final int EMPTY = 0x00;
static final int WPAWN = 0x01;
static final int WROOK = 0x02;
static final int WKNIGHT = 0x03;
static final int WBISHOP = 0x04;
static final int WKING = 0x05;
static final int WQUEEN = 0x06;
static final int BPAWN = 0x07;
static final int BROOK = 0x08;
static final int BKNIGHT = 0x09;
static final int BBISHOP = 0x0a;
static final int BKING = 0x0b;
static final int BQUEEN = 0x0c;
boolean is_piece(int p) {
return (p==EMPTY || p==WPAWN || p==WROOK ||
p==WKNIGHT || p==WBISHOP || p==WKING ||
p==WQUEEN || p==BPAWN || p==BROOK ||
p==BKNIGHT || p==BBISHOP || p==BKING ||
p==BQUEEN);
}
static int EE_POWERUP = 0x6a;
static int EE_EOF = 0x6b;
static int EE_FOURROWS = 0x6c;
static int EE_EMPTYBOARD = 0x6d;
static int EE_DOWNLOADED = 0x6e;
static int EE_BEGINPOS = 0x6f;
static int EE_BEGINPOS_ROT = 0x7a;
static int EE_START_TAG = 0x7b;
static int EE_WATCHDOG_ACTION = 0x7c;
static int EE_NOP = 0x7f;
}
rdgtReceiver.java
---
class rdgtReceiver extends rdgtProtocol {
int messagetype;
int messagelen_msb;
int messagelen_lsb;
int[] data;
int useddata;
int state;
rdgtInterpreter interpreter;
public rdgtReceiver(rdgtInterpreter _interpreter) {
state = 0;
interpreter = _interpreter;
}
void receive(int[] d) {
char c[] = {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F};
StringBuffer x = new StringBuffer("Received: ");
for (int i=0; i<d.length; i=i+1) {
>4]).append(c[d[i]&0x0F]).append("");">x.append(c[d[i]>>4]).append(c[d[i] & 0x0F]).append(" ");
}
if (rdgtChess.debug) System.out.println(x.toString());
_receive (d, 0);
}
void _receive(int[] d, int start) {
if (start == d.length) return;
if (state == 0) { // Find a known messageid.
while (start<d.length) {
if (is_busmessage(d[start])) {
messagetype = d[start];
state = 1;
_receive(d,start+1);
return;
}
System.err.println("Did not understand 1 byte of incoming data.");
start = start + 1;
}
return;
}
if (state == 1) {
if ((d[start] & 0x80) > 0) {
System.err.println("Did not understand 2 bytes of incoming data.");
state = 0;
_receive(d, start);
return;
}
messagelen_msb = d[start];
state = 2;
start = start + 1;
}
if (start == d.length) return;
if (state == 2) {
0){System.err.println("Didnotunderstand3bytesofincomingdata.");">if ((d[start] & 0x80) > 0) {System.err.println("Did not understand 3 bytes of incoming data.");
state = 0;
_receive(d, start);
return;
}
messagelen_lsb = d[start];
state = 3;
start = start + 1;
int newlen = ((int)messagelen_msb * 0x80) + (int)messagelen_lsb;
if (newlen <5) {
System.out.println("Too small message length: " + Integer.toString(newlen));
state = 0;
_receive(d, start);
return;
}
data = new int[newlen];
data[0] = messagetype;
data[1] = messagelen_msb;
data[2] = messagelen_lsb;
useddata = 3;
}
if (start == d.length) return;
if (state == 3) {
while (start<d.length && useddata<data.length) {
data[useddata]=d[start];
start = start + 1;
useddata = useddata + 1;
}
if (useddata == data.length) {
interpreter.interpret(data);
start = start + 1;
data = null;
state = 0;}
}
_receive(d, start);
}
}
rdgtSender.java
---
class rdgtSender extends rdgtProtocol {
rdgtSerialport com;
public rdgtSender(rdgtSerialport _com) {
com = _com;
}
void send(int message, int address) {
String tmp = "Address:"+Integer.toString(address);
System.out.println();
if (message==DGT_TO_BUSMODE) System.out.println("Sending message: SWITCH TO BUSMODE "+tmp);
else if (message==DGT_BUS_SEND_BRD) System.out.println("Sending message: SEND BOARD "+tmp);
else if (message==DGT_BUS_SEND_CHANGES) System.out.println("Sending message: SEND CHANGES "+tmp);
else if (message==DGT_BUS_REPEAT_CHANGES) System.out.println("Sending message: REPEAT CHANGES "+tmp);
else if (message==DGT_BUS_PING) System.out.println("Sending message: PING "+tmp);
else if (message==DGT_BUS_IGNORE_NEXT_BUS_PING) System.out.println("Sending message: IGNORE NEXT PING "+tmp);
else System.out.println("Sending message: (some other message)");
byte x[] = new byte[4];
x[0] = (byte)message;
x[1] = (byte)((address>>7) & 0x7F);
x[2] = (byte)(address & 0x7F);
x[3] = (byte)(((int)x[0]+(int)x[1]+(int)x[2]) & 0x7F);
com.write(x);
}
}
&nb