home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
Boardsquares.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
3KB
|
91 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.
*/
/*
* %W% %E%
* helper class for Chessboard
*
*/
package borland.samples.apps.chess.client.board;
public class Boardsquares extends Object{
int[][] board = new int[8][8];
public synchronized void assign(int column,int row,int value){
board[column][row] = value;
}
public synchronized void add(Boardsquares b) {
int column,row;
for (column=0;column<8;column++){
for (row=0;row<8;row++) {
board[column][row] = board [column][row] +
b.board[column][row];
}
}
}
public synchronized void subtract(Boardsquares b) {
int column,row;
for (column=0;column<8;column++) {
for (row=0;row<8;row++) {
board[column][row] = board[column][row] -
b.board[column][row];
}
}
}
public int nonZeroElementCount() {
int count = 0;
for (int column=0;column<8;column++) {
for (int row=0;row<8;row++) {
if (board[column][row] != 0)
count++;
}
}
return count;
}
public boolean equals(Boardsquares b) {
int column,row;
for (column=0;column<8;column++) {
for (row=0;row<8;row++) {
if (board[column][row] != b.board [column][row])
return false;
}
}
return true;
}
public synchronized int value(int file,int rank) {
if (file < 0 || rank < 0 || file > 7 || rank > 7)
return 0 ;
else
return board[file][rank];
}
public synchronized void init(Boardsquares b) {
for (int column=0;column<8;column++) {
for (int row=0;row<8;row++) {
board[column][row] = b.board[column][row];
}
}
}
}