home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
jbuilder
/
jsamples.z
/
Boardsquares.java
< prev
next >
Wrap
Text File
|
1997-07-03
|
2KB
|
70 lines
/*
* %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];
}
}
}}