home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / MoveNode.java < prev    next >
Encoding:
Java Source  |  1997-07-03  |  2.4 KB  |  92 lines

  1.  /*
  2.  * %W% %E%
  3.  *
  4.  *     H
  5.  *
  6.  */
  7. package borland.samples.apps.chess.client;
  8.  
  9. import borland.samples.apps.chess.client.board.*;
  10.  
  11. public class MoveNode
  12. {
  13.   Boardsquares pieceColor = new Boardsquares();
  14.   Boardsquares pieceValue = new Boardsquares();
  15.   String movetext = new String("_");
  16.   String comment = new String(" ");
  17.   int nestlevel = 0;
  18.   int prevsub = -1;
  19.   int movenum = 0;
  20.   boolean [] qCastleForfeited = new boolean [2];
  21.   boolean [] kCastleForfeited = new boolean [2];
  22.   int enpassantFile = -1;
  23.  
  24.   public MoveNode() {
  25.     for (int i = 0;i < 2;i++) {
  26.       this.qCastleForfeited[i] = false;
  27.       this.kCastleForfeited[i] = false;
  28.     }
  29.   }
  30.  
  31.   public void assign(int file,int rank,int piece,int clr) {
  32.     pieceValue.assign(file,rank,piece);
  33.     pieceColor.assign(file,rank,clr);
  34.   }
  35.  
  36.   public boolean equals(MoveNode x) {
  37.     if (pieceColor.equals(x.pieceColor) &&
  38.         pieceValue.equals(x.pieceValue) &&
  39.         qCastleForfeited[0] == x.qCastleForfeited[0]   &&
  40.         kCastleForfeited[0] == x.kCastleForfeited[0] &&
  41.         qCastleForfeited[1] == x.qCastleForfeited[1]   &&
  42.         kCastleForfeited[1] == x.kCastleForfeited[1] &&
  43.         enpassantFile < 0 &&
  44.         x.enpassantFile < 0 )
  45.       return true;
  46.     else
  47.       return false;
  48.   }
  49.  
  50.   public boolean MatchingPawnSkeleton(MoveNode x) {
  51.     int ourSquare;
  52.     int theirSquare;
  53.     for (int file = 0;file < 8;file++)
  54.       for (int rank = 0;rank < 8;rank++) {
  55.         ourSquare = pieceValue.value(file,rank);
  56.         theirSquare = x.pieceValue.value(file,rank);
  57.         if (ourSquare == theirSquare);
  58.         else
  59.           if (ourSquare == Chessboard.PAWN ||
  60.             theirSquare == Chessboard.PAWN)
  61.             return false;
  62.       }
  63.     return true;
  64.   }
  65.  
  66.   public int PieceValues(int Color) {
  67.     int sum = 0;
  68.     for (int column=0;column<8;column++)
  69.       for (int row=0;row<8;row++)
  70.         if (pieceColor.value(column,row) == Color)
  71.           sum = sum + pieceValue.value(column,row);
  72.     return sum;
  73.   }
  74.  
  75.   public int PieceCount() {
  76.     return pieceValue.nonZeroElementCount();
  77.   }
  78.  
  79.   public void copy(MoveNode from){
  80.     this.pieceColor.init(from.pieceColor);
  81.     this.pieceValue.init(from.pieceValue);
  82.     for (int i = 0;i < 2;i++) {
  83.       this.qCastleForfeited[i] = from.qCastleForfeited[i];
  84.       this.kCastleForfeited[i] = from.kCastleForfeited[i];
  85.     }
  86.     this.enpassantFile = from.enpassantFile;
  87.   }
  88. }  //end of class
  89.  
  90.  
  91.  
  92.