Обеспечение всемирной трансляции спортивных шахматных соревнований с применением разработанного в ходе проекта законченного программного продукта

Дипломная работа - Компьютеры, программирование

Другие дипломы по предмету Компьютеры, программирование

iff to){

this.from=from;

this.to=to;

take=false;

special="";

}

 

public move(rdgtFendiff from, rdgtFendiff to, String special){

this.from=from;

this.to=to;

take=false;

this.special=special;

}

 

 

public rdgtFendiff getFrom(){ return from; }

public rdgtFendiff getTo(){ return to; }

public char getPiece(){ return from.getPiece(); }

public int getFromSquare() { return from.getSquare(); }

public int getToSquare() { return to.getSquare(); }

public String getFromCor() { return pos2xy(getFromSquare()); }

public String getToCor() { return pos2xy(getToSquare()); }

public boolean isWhite() { return from.isWhite(); }

 

public String longNotation() { return moveString(false); }

public String shortNotation() { return moveString(true); }

 

public void setTake(boolean take){ this.take=take; }

 

public boolean getTake() { return take; }

String moveString(boolean shortNotation){

if(!special.equals("")) {

if(isCheck(isWhite()))

return special + "+";

else

return special;

}

boolean ep=false;

 

char takeBit=-;

if(take) takeBit=x;

 

String s="";

if(getPiece()!=p && getPiece()!=P)

s+=new String(""+getPiece()).toUpperCase();

 

if(!shortNotation)

s+=getFromCor()+takeBit;

else {

if(getPiece()==R || getPiece()==r)

if(findRookLength(getToSquare()%8,getToSquare()/8,getPiece()))

s+=getFromCor()+takeBit;

if(getPiece()==N || getPiece()==n)

if(findNightLength(getToSquare()%8,getToSquare()/8,getPiece()))

s+=getFromCor()+takeBit;

if(getPiece()==B || getPiece()==b)

if(findBishopLength(getToSquare()%8,getToSquare()/8,getPiece()))

s+=getFromCor()+takeBit;

if(getPiece()==Q || getPiece()==q)

if(findQueenLength(getToSquare()%8,getToSquare()/8,getPiece()))

s+=getFromCor()+takeBit;

if(getPiece()==P || getPiece()==p)

if( !getFromCor().substring(0,1).equals( getToCor().substring(0,1) ) ) {

s+=getFromCor().substring(0,1)+"x";

if(!take) ep=true;

}

 

=1){"> if(take && s.length()>=1){

if(s.charAt(s.length()-1) != x)

s+="x";

}

}

 

s+=getToCor();

if(ep)

s+=" ep.";

 

/** Is it a check? **/

if(isCheck(isWhite())) s+=+;

 

return s;

}

 

boolean isCheck(boolean white){

int k=-1;

int K=-1;

for(int i=0;i<64;i++){

if(to.getAfter().getPieceAt(i%8,i/8) == k) k=i;

if(to.getAfter().getPieceAt(i%8,i/8) == K) K=i;

}

boolean check=false;

 

if(white){

if(findQueenLength(k%8,k/8,Q)) check=true;

if(findRookLength(k%8,k/8,R)) check=true;

if(findBishopLength(k%8,k/8,B)) check=true;

if(findNightLength(k%8,k/8,N)) check=true;

if(findPawnLength(k%8,k/8,P)) check=true;

}

else{

if(findQueenLength(K%8,K/8,q)) check=true;

if(findRookLength(K%8,K/8,r)) check=true;

if(findBishopLength(K%8,K/8,b)) check=true;

if(findNightLength(K%8,K/8,n)) check=true;

if(findPawnLength(K%8,K/8,p)) check=true;

}

 

return check;

}

 

 

/** Is there a night on a night-distance from square? **/

boolean findNightLength(int x, int y,char n){

rdgtFenboard b = to.getAfter();

 

if(b.getPieceAt(x-1,y-2) == n) return true;

if(b.getPieceAt(x+1,y-2) == n) return true;

if(b.getPieceAt(x-2,y-1) == n) return true;

if(b.getPieceAt(x+2,y-1) == n) return true;

if(b.getPieceAt(x-2,y+1) == n) return true;

if(b.getPieceAt(x+2,y+1) == n) return true;

if(b.getPieceAt(x-1,y+2) == n) return true;

if(b.getPieceAt(x+1,y+2) == n) return true;

 

return false;

}

 

boolean findRookLength(int x, int y, char r){

rdgtFenboard b = to.getAfter();

 

int xx=0;

int yy=0;

 

do{

xx++;

if(b.getPieceAt(x+xx,y+yy) == r) return true;

}while(b.getPieceAt(x+xx,y+yy) == .);

 

xx=0;

do{

xx--;

if(b.getPieceAt(x+xx,y+yy) == r) return true;

}while(b.getPieceAt(x+xx,y+yy) == .);

 

xx=0;

do{

yy--;

if(b.getPieceAt(x+xx,y+yy) == r) return true;

}while(b.getPieceAt(x+xx,y+yy) == .);

yy=0;

do{

yy++;

if(b.getPieceAt(x+xx,y+yy) == r) return true;

}while(b.getPieceAt(x+xx,y+yy) == .);

 

return false;

}

 

boolean findBishopLength(int x, int y, char r){

rdgtFenboard b = to.getAfter();

 

int xx=0;

int yy=0;

 

do{

xx++;

yy++;

if(b.getPieceAt(x+xx,y+yy) == r) return true;

}while(b.getPieceAt(x+xx,y+yy) == .);

 

xx=0;

yy=0;

do{

xx--;

yy--;

if(b.getPieceAt(x+xx,y+yy) == r) return true;

}while(b.getPieceAt(x+xx,y+yy) == .);

 

xx=0;

yy=0;

do{

yy--;

xx++;

if(b.getPieceAt(x+xx,y+yy) == r) return true;

}while(b.getPieceAt(x+xx,y+yy) == .);

 

yy=0;

xx=0;

do{

yy++;

xx--;

if(b.getPieceAt(x+xx,y+yy) == r) return true;

}while(b.getPieceAt(x+xx,y+yy) == .);

 

return false;

}

 

boolean findQueenLength(int x, int y, char q){

if(findRookLength(x,y,q)) return true;

if(findBishopLength(x,y,q)) return true;

 

return false;

}

 

boolean findPawnLength(int x, int y, char p){

rdgtFenboard b = to.getAfter();

if(p==P){

if(b.getPieceAt(x-1,y-1)==p) return true;

if(b.getPieceAt(x+1,y-1)==p) return true;

}

else {

if(b.getPieceAt(x-1,y-1)==p) return true;

if(b.getPieceAt(x+1,y-1)==p) return true;

}

 

return false;

}

 

public String toString(){

return ""+from.toString() + "-" + to.toString();

}

 

public boolean equals(move other){

if(!from.equals( other.getFrom() )) return false;

if(!to.equals( other.getTo() )) return false;

return true;

}

 

String pos2xy(int pos){

String s = "" + (char)((pos)%8+a) + "" + (8-pos/8);

return s;

}

 

}

 

class movelist {

ArrayList moves;

boolean unique;

boolean noSmooth;

public void clear(){moves.clear(); }

public void remove(int n) { moves.remove(n); }

 

public movelist(){ moves=new ArrayList(); unique=false; }

public movelist(boolean unique, boolean noSmooth) {

moves=new ArrayList();

this.unique=unique;

this.noSmooth=noSmooth;

}

 

public move get(int n){ return (move)moves.get(n); }

public int size() { return moves.size(); }

 

public String toString() { return getAll(false,false); }

public void print(boolean shortNotation) {

System.out.println("Moves");

System.out.print(getAll(shortNotation,true));

}

 

void fixTakes(){

for(int i=1;i<moves.size();i++){

int toSquare = ((move)moves.get(i)).getToSquare();

char p = (char) ((move)moves.get(i-1)).getTo().getAfter().getBoard()[toSquare];

if(p!=.){

move m=(move)moves.get(i);

m.setTake(true);

moves.set(i,m);

}

}

}

public String getAll(boolean shortNotation,boolean nice){

fixTakes();

 

String output="";

boolean lastColor=false;

int n=1;

for(int i=0;i<moves.size();i++){

move m=(move)moves.get(i);

 

if(m.isWhite() && lastColor==false){

if(nice)

output += n+".\t";

else

output += n+". ";

n++;

}

 

if(n==1 && !m.isWhite()) {

if(nice)

output += "1.\t...\t\t";

else

output += "1. ... ";

}

 

lastColor=m.isWhite();

int length=output.length();

 

if(shor