FileDocCategorySizeDatePackage
KingPos.javaAPI DocExample3057Sat Sep 12 03:01:00 BST 1998borland.samples.apps.chess.client

KingPos

public class KingPos extends Object
helper class for the ChessRules class

Fields Summary
private int
kingRank
private int
kingFile
private int
kingCheckCount
private int
attacker
private int
attackerFile
private int
attackerRank
private int
kingColor
Constructors Summary
public KingPos(int color)


     
    if (color == Chessboard.WHITEPIECE)
      kingColor = Chessboard.WHITEPIECE ;
    else
      kingColor = Chessboard.BLACKPIECE;
  
Methods Summary
public intgetAttacker()

   return attacker;
  
public intgetAttackerFile()

    return attackerFile;
  
public intgetAttackerRank()

    return attackerRank;
  
public intgetKingColor()

    return kingColor;
  
public intgetKingFile()

    return kingFile;
  
public intgetKingRank()

    return kingRank;
  
public booleanisDoubleCheck()

    return (kingCheckCount > 1)  ;
  
public booleanisInCheck()

    return (kingCheckCount != 0);
  
public voidkingInCheck(boolean b)

    if (b)
      kingCheckCount++;
    else {
      // System.out.println("no attacker");
      attacker = -1;
      attackerRank = -1;
      attackerFile = -1;
      kingCheckCount = 0;
    }
  
public booleankingPosEquals(int file, int rank)

    if (rank == kingRank && file == kingFile)
      return true;
    else
      return false;
  
public voidsetAttacker(int piecevalue, int file, int rank)

    if (piecevalue  < 0) {
      System.out.println("no attacker");
      attacker = -1;
      attackerRank = -1;
      attackerFile = -1;
      kingCheckCount = 0;
    }
    else {
      System.out.println("found attacker" + piecevalue + file + rank);
      attacker = piecevalue;
      attackerRank = rank;
      attackerFile = file;
      kingCheckCount++;
    }
  
public voidsetKingPos(int file, int rank)

    if (rank >= 0)
      kingRank = rank;
    if (file >= 0)
      kingFile = file;
  //System.out.println("King Pos = " + file + rank + " (" + kingColor);