Обеспечение всемирной трансляции спортивных шахматных соревнований с применением разработанного в ходе проекта законченного программного продукта
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
ls(rdgtFendiff other){
if(getPiece() != other.getPiece()) return false;
if(getSquare() != other.getSquare()) return false;
if(isAdded() != other.isAdded()) return false;
return true;
}
public rdgtFendiff() {
secured=false;
}
public rdgtFendiff(char piece, boolean added, int square){
set(piece,added,square);
}
public rdgtFendiff(int piece, int square){
if(piece<0){
this.piece = (char)(-piece);
added=false;
}
else {
this.piece=(char)piece;
added=true;
}
this.square=square;
}
public rdgtFendiff(int piece,int square, rdgtFenboard before, rdgtFenboard after){
this.before=before;
this.after=after;
if(piece<0){
this.piece = (char)(-piece);
added=false;
}
else {
this.piece=(char)piece;
added=true;
}
this.square=square;
}
public void set(char piece, boolean added, int square){
this.piece=piece;
this.added=added;
this.square=square;
}
public String toString() {
String output = ""+piece;
if(added) output += "@";
else output += "&";
output += (char)((square)%8+a) + "" + (8-square/8);
return output;
}
}
rdgtFenhax.java
---
public class rdgtFenhax {
static boolean debug=false;
static boolean rotated=false;
public rdgtFenhax(){
boards=new ArrayList();
moves=new movelist();
diffTable=new ArrayList();
result="?-?";
plyCount=0;
}
static String getMoves(boolean shortNotation, boolean nice) {
calcMoves();
return moves.getAll(shortNotation,nice);
}
static String getMoves(){
return getMoves(false,false);
}
static int getPlyCount(){
calcMoves();
return moves.size();
}
static void clear(){
boards.clear();
moves.clear();
diffTable.clear();
result="?-?";
}
static String getResult() { return result; }
static boolean add(String aFen){
rdgtFenboard f = new rdgtFenboard();
if(!f.setBoard(aFen))
return false;
boards.add(f);
=0){">if(aFen.indexOf("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")>=0){
clear();
boards.add(f);
}
=0&&aFen.indexOf("PPPPPPPP/RNBQ1BNR")>=0)||">if((aFen.indexOf("rnbq1bnr/pppppppp") >=0 && aFen.indexOf("PPPPPPPP/RNBQ1BNR") >= 0)||
=0&&aFen.indexOf("PPPPPPPP/RNBQ1BNR")>=0)||"> (aFen.indexOf("rnbqkbnr/pppppppp") >=0 && aFen.indexOf("PPPPPPPP/RNBQ1BNR") >= 0)||
=0&&aFen.indexOf("PPPPPPPP/RNBQKBNR")>=0)){"> (aFen.indexOf("rnbq1bnr/pppppppp") >=0 && aFen.indexOf("PPPPPPPP/RNBQKBNR") >= 0)){
int[] b=f.getBoard();
boolean black=false;
boolean white=false;
for(int i=16;i<=47;i++){
if(b[i] == k) black=true;
if(b[i] == K) white=true;
}
if(black && white) result="1/2-1/2";
else if(black) result="0-1";
else if(white) result="1-0";
}
=2){">if(boards.size()>=2){
rdgtFenboard last = (rdgtFenboard)boards.get(boards.size()-1);
rdgtFenboard nextlast = (rdgtFenboard)boards.get(boards.size()-2);
if(last.diffCount(nextlast) < 5){
rdgtFenboard m=nextlast.mask(last);
int[] mask = m.getBoard();
for(int i=0;i<64;i++){
if(mask[i] != . && mask[i]<0){
diffTable.add(new rdgtFendiff(mask[i],i,nextlast,last));
}
}
for(int i=0;i<64;i++){
if(mask[i] != . && mask[i]>0){
diffTable.add(new rdgtFendiff(mask[i],i,nextlast,last));
}
}
}
else {
clear();
boards.add(f);
}
}
return true;
}
static void calcMoves(){
moves.clear();
if(debug){
for(int i=0;i<diffTable.size();i++){
System.out.print(i + ":" + ((rdgtFendiff)diffTable.get(i)).toString() + " ");
}
System.out.print("\n");
}
int offset=0;
int length=diffTable.size();
while(offset<length){
int start=offset;
int end=-1;
boolean turn = isWhite( ((rdgtFendiff)diffTable.get(offset)).getPiece() );
int i=start;
while(end==-1){
rdgtFendiff test = (rdgtFendiff)diffTable.get(i);
if(turn != isWhite(test.getPiece()) && test.isAdded()){
end=i-1;
}
else{
i++;
if(i>=length)
end=length-1;
}
if(turn==isWhite(test.getPiece()) && test.isAdded()){
offset=i;
}
}
if(offset==start) offset++;
if(debug) System.out.print(start + "-"+end+" ");
movelist chunkMoves = new movelist(true,true);
for(int s=start;s<end;s++){
rdgtFendiff a = (rdgtFendiff)diffTable.get(s);
for(int e=s+1;e<=end;e++){
rdgtFendiff b = (rdgtFendiff)diffTable.get(e);
if(a.getPiece() == b.getPiece() && a.getSquare() != b.getSquare()){
if(!a.isAdded() && b.isAdded()){
String special="";
if(b.getPiece()==P && b.getSquare()/8==0){
for(int j=e+1;j<=end;j++){
rdgtFendiff prom = (rdgtFendiff)diffTable.get(j);
if(prom.isAdded() && prom.isWhite()){
if(a.getSquare()%8 != b.getSquare()%8)
special+=pos2xy(a.getSquare()).substring(0,1)+"x";
special+=pos2xy(b.getSquare())+"="+prom.getPiece();
b=prom;
}
}
}
if(b.getPiece()==p && b.getSquare()/8==7){
for(int j=e+1;j<=end;j++){
rdgtFendiff prom = (rdgtFendiff)diffTable.get(j);
if(prom.isAdded() && prom.isWhite()){
if(a.getSquare()%8 != b.getSquare()%8)
special+=pos2xy(a.getSquare()).substring(0,1)+"x";
special+=pos2xy(b.getSquare())+"="+prom.getPiece();
b=prom;
}
}
}
chunkMoves.add(new move(a,b,special));
}
}
}
}
if(chunkMoves.size()==0){
rdgtFendiff a = (rdgtFendiff)diffTable.get(start);
for(int s=start;s<=end;s++){
rdgtFendiff b = (rdgtFendiff)diffTable.get(s);
if(b.isAdded()){
if(a.getPiece()==P && a.getSquare()/8==1 && !a.isAdded()){
String special="";
if(a.getSquare()%8 != b.getSquare()%8)
special+=pos2xy(a.getSquare()).substring(0,1)+"x";
special+=pos2xy(b.getSquare())+"="+b.getPiece();
chunkMoves.add(new move(a,b,special));
}
else if(a.getPiece()==p && a.getSquare()/8==6 && !a.isAdded()){
String special="";
if(a.getSquare()%8 != b.getSquare()%8)
special+=pos2xy(a.getSquare()).substring(0,1)+"x";
special+=pos2xy(b.getSquare())+"="+b.getPiece();
chunkMoves.add(new move(a,b,special));
}
else
chunkMoves.add(new move(a,b,""+a.getPiece()+"@"+pos2xy(a.getSquare())));
}
}
}
for(int j=0;j<chunkMoves.size();j++){
if(debug) System.out.print( (chunkMoves.get(j)).toString() + " ");
moves.add(chunkMoves.get(j));
}
if(debug) System.out.print("\n");
}
}
static String pos2xy(int pos){
String s = "" + (char)((pos)%8+a) + "" + (8-pos/8);
return s;
}
static boolean isWhite(char piece){
if(piece>A && piece < Z)
return true;
else
return false;
}
static movelist moves;
static ArrayList boards;
static ArrayList diffTable;
static String result;
static int plyCount;
}
class move {
rdgtFendiff from;
rdgtFendiff to;
boolean take;
String special;
public move(rdgtFendiff from, rdgtFend