home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 3.0 KB | 119 lines |
- /*
- * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
- *
- * This SOURCE CODE FILE, which has been provided by Borland as part
- * of a Borland product for use ONLY by licensed users of the product,
- * includes CONFIDENTIAL and PROPRIETARY information of Borland.
- *
- * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
- * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
- * THE PRODUCT.
- *
- * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
- * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
- * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
- * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
- * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
- * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
- * CODE FILE.
- */
- package borland.samples.apps.chess.client;
-
- import borland.samples.apps.chess.client.board.*;
-
- /**helper class for the ChessRules class
- */
- public class KingPos
- {
- private int kingRank = -1;
- private int kingFile = -1;
- private int kingCheckCount = 0;
- private int attacker = -1;
- private int attackerFile = -1;
- private int attackerRank = -1;
- private int kingColor;
-
- public KingPos(int color) {
- if (color == Chessboard.WHITEPIECE)
- kingColor = Chessboard.WHITEPIECE ;
- else
- kingColor = Chessboard.BLACKPIECE;
- }
-
- public int getKingColor() {
- return kingColor;
- }
-
- public boolean kingPosEquals(int file,int rank){
- if (rank == kingRank && file == kingFile)
- return true;
- else
- return false;
- }
-
- public void setKingPos(int file,int rank) {
- if (rank >= 0)
- kingRank = rank;
- if (file >= 0)
- kingFile = file;
- //System.out.println("King Pos = " + file + rank + " (" + kingColor);
- }
-
- public void setAttacker(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 int getKingFile(){
- return kingFile;
- }
-
- public int getKingRank(){
- return kingRank;
- }
-
- public int getAttacker() {
- return attacker;
- }
-
- public int getAttackerFile() {
- return attackerFile;
- }
-
- public int getAttackerRank() {
- return attackerRank;
- }
-
- public void kingInCheck(boolean b) {
- if (b)
- kingCheckCount++;
- else {
- // System.out.println("no attacker");
- attacker = -1;
- attackerRank = -1;
- attackerFile = -1;
- kingCheckCount = 0;
- }
- }
-
- public boolean isDoubleCheck() {
- return (kingCheckCount > 1) ;
- }
-
- public boolean isInCheck () {
- return (kingCheckCount != 0);
- }
- }
-