Commit f6bd2726 authored by kimia's avatar kimia

true moves

parent 00cffa12
...@@ -24,49 +24,29 @@ public class Bishop extends Piece { ...@@ -24,49 +24,29 @@ public class Bishop extends Piece {
) && (c.isEmpty() || (!c.isEmpty() && sw==1)) ) { ) && (c.isEmpty() || (!c.isEmpty() && sw==1)) ) {
if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() < c.getRow()) { if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() < c.getRow()) {
for (int i=-1 ; i>-8 ; --i) { for (int i=-1 ; i>-8 ; --i) {
if (!board[this.getCell().getRow()-i][this.getCell().getCol()-i].isEmpty()){ if (this.getCell().getRow()-i == c.getRow() && sw==1) break ;
Cell newCell = new Cell(this.getCell().getRow()-i,this.getCell().getCol()-i); if (!board[this.getCell().getRow()-i][this.getCell().getCol()-i].isEmpty()) return false;
if(checkCellPieceColor(newCell,board,pw,pb)!=super.getPieceColor() && newCell.getRow()==c.getRow() && newCell.getCol()==c.getCol()){
return true;
}
return false;
}
if (this.getCell().getRow()-i == c.getRow()) break ; if (this.getCell().getRow()-i == c.getRow()) break ;
} }
} }
if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() > c.getRow()) { if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() > c.getRow()) {
for (int i=-1 ; i>-8 ; --i) { for (int i=-1 ; i>-8 ; --i) {
if (!board[this.getCell().getRow()+i][this.getCell().getCol()-i].isEmpty()) { if (this.getCell().getRow()+i == c.getRow() && sw==1) break ;
Cell newCell = new Cell(this.getCell().getRow()+i,this.getCell().getCol()-i); if (!board[this.getCell().getRow()+i][this.getCell().getCol()-i].isEmpty()) return false ;
if(checkCellPieceColor(newCell,board,pw,pb)!=super.getPieceColor() && newCell.getRow()==c.getRow() && newCell.getCol()==c.getCol()){
return true;
}
return false;
}
if (this.getCell().getRow()+i == c.getRow()) break ; if (this.getCell().getRow()+i == c.getRow()) break ;
} }
} }
if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() < c.getRow()) { if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() < c.getRow()) {
for (int i=1 ; i<8 ; ++i) { for (int i=1 ; i<8 ; ++i) {
if (!board[this.getCell().getRow()+i][this.getCell().getCol()-i].isEmpty()) { if (this.getCell().getRow()+i == c.getRow() && sw==1) break ;
Cell newCell = new Cell(this.getCell().getRow()+i,this.getCell().getCol()-i); if (!board[this.getCell().getRow()+i][this.getCell().getCol()-i].isEmpty()) return false;
if(checkCellPieceColor(newCell,board,pw,pb)!=super.getPieceColor() && newCell.getRow()==c.getRow() && newCell.getCol()==c.getCol()){
return true;
}
return false;
}
if (this.getCell().getCol()-i == c.getCol()) break ; if (this.getCell().getCol()-i == c.getCol()) break ;
} }
} }
if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() > c.getRow()) { if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() > c.getRow()) {
for (int i=-1 ; i>-8 ; --i) { for (int i=-1 ; i>-8 ; --i) {
if (!board[this.getCell().getRow()+i][this.getCell().getCol()+i].isEmpty()) { if (this.getCell().getRow()+i == c.getRow() && sw==1) break ;
Cell newCell = new Cell(this.getCell().getRow()+i,this.getCell().getCol()+i); if (!board[this.getCell().getRow()+i][this.getCell().getCol()+i].isEmpty()) return false;
if(checkCellPieceColor(newCell,board,pw,pb)!=super.getPieceColor() && newCell.getRow()==c.getRow() && newCell.getCol()==c.getCol()){
return true;
}
return false;
}
if (this.getCell().getCol()+i == c.getCol()) break ; if (this.getCell().getCol()+i == c.getCol()) break ;
} }
} }
......
...@@ -6,8 +6,11 @@ import java.util.ArrayList; ...@@ -6,8 +6,11 @@ import java.util.ArrayList;
public class ChessBoardGUI extends JPanel { public class ChessBoardGUI extends JPanel {
public JButton[][] button = new JButton[8][8]; public JButton[][] button = new JButton[8][8];
JPanel removedPiecePanel; private JPanel whiteRemovedPiecePanel;
JButton removedPieces[][] = new JButton[8][4]; private JPanel blackRemovedPiecePanel;
private JPanel turnPanel;
private JButton removedPieces[][] = new JButton[8][4];
private JLabel turnLabel = new JLabel();
private int wORb = 0; private int wORb = 0;
private Piece pw[]; private Piece pw[];
private Piece pb[]; private Piece pb[];
...@@ -19,9 +22,11 @@ public class ChessBoardGUI extends JPanel { ...@@ -19,9 +22,11 @@ public class ChessBoardGUI extends JPanel {
private boolean[][] moveBoard = null; private boolean[][] moveBoard = null;
public ArrayList<Piece> deletedList = new ArrayList<>(); public ArrayList<Piece> deletedList = new ArrayList<>();
private JFrame parentPanel; private JFrame parentPanel;
public ChessBoardGUI(JPanel removedPiecePanel,JFrame parentPanel){ public ChessBoardGUI(JPanel whiteRemovedPiecePanel,JPanel blackRemovedPiecePanel,JPanel turnPanel,JFrame parentPanel){
super(); super();
this.removedPiecePanel=removedPiecePanel; this.whiteRemovedPiecePanel= whiteRemovedPiecePanel;
this.blackRemovedPiecePanel = blackRemovedPiecePanel;
this.turnPanel = turnPanel;
this.parentPanel = parentPanel; this.parentPanel = parentPanel;
parentPanel.setTitle("White Turn..."); parentPanel.setTitle("White Turn...");
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
...@@ -53,10 +58,10 @@ public class ChessBoardGUI extends JPanel { ...@@ -53,10 +58,10 @@ public class ChessBoardGUI extends JPanel {
int condition = checkCondition(board,pw,pb); int condition = checkCondition(board,pw,pb);
if(condition==2){ if(condition==2){
JOptionPane.showMessageDialog(removedPiecePanel,"Condition White"); JOptionPane.showMessageDialog(turnPanel,"Condition White");
} }
else if(condition==1){ else if(condition==1){
JOptionPane.showMessageDialog(removedPiecePanel,"Condition Black"); JOptionPane.showMessageDialog(turnPanel,"Condition Black");
} }
//---------------- //----------------
} }
...@@ -66,9 +71,9 @@ public class ChessBoardGUI extends JPanel { ...@@ -66,9 +71,9 @@ public class ChessBoardGUI extends JPanel {
updateGUIBoard(moveBoard); updateGUIBoard(moveBoard);
} }
if(wORb%2==0){ if(wORb%2==0){
parentPanel.setTitle("White Turn..."); turnLabel.setText("White Turn...");
}else { }else {
parentPanel.setTitle("Black Turn..."); turnLabel.setText("Black Turn...");
} }
} }
}); });
...@@ -84,13 +89,18 @@ public class ChessBoardGUI extends JPanel { ...@@ -84,13 +89,18 @@ public class ChessBoardGUI extends JPanel {
} }
private void inilizeRemovedPiecePanel(){ private void inilizeRemovedPiecePanel(){
for (int i = 0 ; i < 8 ;i++){ for (int i = 0 ; i < 8 ;i++){
for (int j = 0 ; j < 4 ;j++) { for (int j = 0 ; j < 2 ;j++) {
removedPieces[i][j] = new JButton(); removedPieces[i][j] = new JButton();
removedPieces[i][j].setBackground(Color.YELLOW); removedPieces[i][j].setBackground(Color.YELLOW);
// added.setMinimumSize(new Dimension(50,50)); // added.setMinimumSize(new Dimension(50,50));
removedPiecePanel.add( removedPieces[i][j]); whiteRemovedPiecePanel.add( removedPieces[i][j]);
removedPieces[i][3-j] = new JButton();
removedPieces[i][3-j].setBackground(Color.YELLOW);
blackRemovedPiecePanel.add( removedPieces[i][3-j]);
} }
} }
turnPanel.setLayout( new FlowLayout(FlowLayout.CENTER));
turnPanel.add(turnLabel);
} }
private void updateDeletedPanel(){ private void updateDeletedPanel(){
int wCount = 0; int wCount = 0;
...@@ -166,11 +176,11 @@ public class ChessBoardGUI extends JPanel { ...@@ -166,11 +176,11 @@ public class ChessBoardGUI extends JPanel {
boolean[][] binaryBoard = new boolean[8][8]; boolean[][] binaryBoard = new boolean[8][8];
if (wORb%2==0) { if (wORb%2==0) {
for (Piece p : pw){ for (Piece p : pw){
if(p.getCell().getRow() == source.getRow() && p.getCell().getCol()==source.getCol()){ if(!p.isDeleted() && p.getCell().getRow() == source.getRow() && p.getCell().getCol()==source.getCol()){
for (int i = 0 ; i < 8;i++){ for (int i = 0 ; i < 8;i++){
for (int j = 0 ; j < 8 ;j++){ for (int j = 0 ; j < 8 ;j++){
Cell dest = new Cell(i,j); // Cell dest = new Cell(i,j);
if(p.isValidMove(dest,board,pw,pb)){ if(p.isValidMove(board[i][j],board,pw,pb)){
binaryBoard[i][j] = true; binaryBoard[i][j] = true;
} }
} }
...@@ -180,11 +190,10 @@ public class ChessBoardGUI extends JPanel { ...@@ -180,11 +190,10 @@ public class ChessBoardGUI extends JPanel {
} }
}else { }else {
for (Piece p : pb){ for (Piece p : pb){
if(p.getCell().getRow() == source.getRow() && p.getCell().getCol()==source.getCol()){ if(!p.isDeleted() && p.getCell().getRow() == source.getRow() && p.getCell().getCol()==source.getCol()){
for (int i = 0 ; i < 8;i++){ for (int i = 0 ; i < 8;i++){
for (int j = 0 ; j < 8 ;j++){ for (int j = 0 ; j < 8 ;j++){
Cell dest = new Cell(i,j); if(p.isValidMove(board[i][j],board,pw,pb)){
if(p.isValidMove(dest,board,pw,pb)){
binaryBoard[i][j] = true; binaryBoard[i][j] = true;
} }
} }
...@@ -199,18 +208,14 @@ public class ChessBoardGUI extends JPanel { ...@@ -199,18 +208,14 @@ public class ChessBoardGUI extends JPanel {
//-------------- //--------------
if (wORb%2==0) { if (wORb%2==0) {
for (Piece p : pw) { for (Piece p : pw) {
if (p.getCell().getRow() == source.getRow() && if (!p.isDeleted() && p.getCell().getRow() == source.getRow() &&
p.getCell().getCol() == source.getCol()) { p.getCell().getCol() == source.getCol()) {
if (p.isValidMove(dest, board, pw, pb)) { if (p.isValidMove(board[dest.getRow()][dest.getCol()], board, pw, pb)) {
dest = board[dest.getRow()][dest.getCol()];
wORb++; wORb++;
board[p.getCell().getRow()][p.getCell().getCol()].setEmpty(true); board[p.getCell().getRow()][p.getCell().getCol()].setEmpty(true);
p.setCell(dest); p.setCell(dest);
board[p.getCell().getRow()][p.getCell().getCol()].setEmpty(false); board[p.getCell().getRow()][p.getCell().getCol()].setEmpty(false);
for (Piece p1 : pb) {
if (p1.getCell().getRow() == dest.getRow() && p1.getCell().getCol() == dest.getCol()) {
p1.setDeleted(true);
}
}
if (p instanceof Pawn) { if (p instanceof Pawn) {
Pawn myPawn = (Pawn) p; Pawn myPawn = (Pawn) p;
myPawn.setOnce(false); myPawn.setOnce(false);
...@@ -228,18 +233,14 @@ public class ChessBoardGUI extends JPanel { ...@@ -228,18 +233,14 @@ public class ChessBoardGUI extends JPanel {
} }
}else { }else {
for (Piece p:pb) { for (Piece p:pb) {
if (p.getCell().getRow()==source.getRow() && if (!p.isDeleted() && p.getCell().getRow()==source.getRow() &&
p.getCell().getCol() == source.getCol()) p.getCell().getCol() == source.getCol())
if (p.isValidMove(dest, board, pw, pb) ) { if (p.isValidMove(board[dest.getRow()][dest.getCol()], board, pw, pb) ) {
dest = board[dest.getRow()][dest.getCol()];
wORb++ ; wORb++ ;
board[p.getCell().getRow()][p.getCell().getCol()].setEmpty(true) ; board[p.getCell().getRow()][p.getCell().getCol()].setEmpty(true) ;
p.setCell(dest) ; p.setCell(dest) ;
board[p.getCell().getRow()][p.getCell().getCol()].setEmpty(false) ; board[p.getCell().getRow()][p.getCell().getCol()].setEmpty(false) ;
for (Piece p1:pw) {
if (p1.getCell().getRow()==dest.getRow() && p1.getCell().getCol()==dest.getCol()) {
p1.setDeleted(true) ;
}
}
if (p instanceof Pawn) { if (p instanceof Pawn) {
Pawn myPawn = (Pawn) p; Pawn myPawn = (Pawn) p;
myPawn.setOnce(false) ; myPawn.setOnce(false) ;
......
...@@ -14,13 +14,23 @@ public class ChessGameGUI extends JFrame { ...@@ -14,13 +14,23 @@ public class ChessGameGUI extends JFrame {
parent.setSize(1300,610); parent.setSize(1300,610);
setResizable(false); setResizable(false);
parent.setLayout(new BoxLayout(parent,BoxLayout.X_AXIS)); parent.setLayout(new BoxLayout(parent,BoxLayout.X_AXIS));
JPanel p1 = new JPanel(); //-----------------------------------------
p1.setLayout(new GridLayout(8,5)); JPanel whiteRemovePanel = new JPanel();
p1.setSize(500,600); whiteRemovePanel.setLayout(new GridLayout(8,2));
whiteRemovePanel.setSize(200,600);
//-----------------------------------------
JPanel turnPanel = new JPanel();
//-----------------------------------------
JPanel blackRemovePanel = new JPanel();
blackRemovePanel.setLayout(new GridLayout(8,2));
blackRemovePanel.setSize(200,600);
//-----------------------------------------
JPanel gameBoard = new ChessBoardGUI(p1,this); JPanel gameBoard = new ChessBoardGUI(whiteRemovePanel,blackRemovePanel,turnPanel,this);
gameBoard.setSize(800,600); gameBoard.setSize(800,600);
parent.add(p1); parent.add(whiteRemovePanel);
parent.add(turnPanel);
parent.add(blackRemovePanel);
parent.add(gameBoard); parent.add(gameBoard);
add(parent); add(parent);
setVisible(true); setVisible(true);
......
...@@ -18,18 +18,22 @@ public class Pawn extends Piece{ ...@@ -18,18 +18,22 @@ public class Pawn extends Piece{
@Override @Override
public boolean isValidMove(Cell c, Cell board[][], Piece pw[], Piece pb[]) { public boolean isValidMove(Cell c, Cell board[][], Piece pw[], Piece pb[]) {
if (super.isDeleted()) return false ; if (super.isDeleted()) return false ;
if (super.getPieceColor()== PieceColor.BLACK && super.getCell().getRow()==0) end = true ; if (super.getPieceColor()==PieceColor.BLACK && super.getCell().getRow()==0) end = true ;
if (super.getPieceColor()== PieceColor.WHITE && super.getCell().getRow()==7) end = true ; if (super.getPieceColor()==PieceColor.WHITE && super.getCell().getRow()==7) end = true ;
int sw=0 ; int sw=0 ;
if (super.getPieceColor() == PieceColor.BLACK) { if (super.getPieceColor() == PieceColor.BLACK) {
for (Piece p:pw) { for (Piece p:pw) {
if (!p.isDeleted() && p.getCell().getRow()==c.getRow() && p.getCell().getCol()==c.getCol()) sw=1 ; if (!p.isDeleted() && p.getCell().getRow()==c.getRow() && p.getCell().getCol()==c.getCol()
&& c.getRow()-this.getCell().getRow()==-1
&& Math.abs(this.getCell().getCol()-c.getCol())==1) sw=1 ;
} }
} }
else { else {
for (Piece p:pb) { for (Piece p:pb) {
if (!p.isDeleted() && p.getCell().getRow()==c.getRow() && p.getCell().getCol()==c.getCol()) sw=1 ; if (!p.isDeleted() && p.getCell().getRow()==c.getRow() && p.getCell().getCol()==c.getCol()
&& c.getRow()-this.getCell().getRow()==1
&& Math.abs(this.getCell().getCol()-c.getCol())==1) sw=1 ;
} }
} }
...@@ -39,7 +43,7 @@ public class Pawn extends Piece{ ...@@ -39,7 +43,7 @@ public class Pawn extends Piece{
//System.out.println("col: " + this.getCell().getCol()) ; //System.out.println("col: " + this.getCell().getCol()) ;
if ((this.getCell().getCol() == c.getCol()) && if ((this.getCell().getCol() == c.getCol()) &&
(Math.abs(this.getCell().getRow()-c.getRow())==1 || Math.abs(this.getCell().getRow()-c.getRow())==2) (Math.abs(this.getCell().getRow()-c.getRow())==1 || Math.abs(this.getCell().getRow()-c.getRow())==2)
&& c.isEmpty()) { && c.isEmpty()){
if(getCell().getRow() < c.getRow() && getPieceColor()==PieceColor.WHITE) { if(getCell().getRow() < c.getRow() && getPieceColor()==PieceColor.WHITE) {
return true; return true;
}else if(getCell().getRow() > c.getRow() && getPieceColor()==PieceColor.BLACK){ }else if(getCell().getRow() > c.getRow() && getPieceColor()==PieceColor.BLACK){
...@@ -62,13 +66,13 @@ public class Pawn extends Piece{ ...@@ -62,13 +66,13 @@ public class Pawn extends Piece{
} }
else { else {
if( if(
(this.getCell().getCol() == c.getCol() && (this.getCell().getCol() == c.getCol() && c.isEmpty() &&
((this.getCell().getRow()-c.getRow()==1 && super.getPieceColor()== PieceColor.BLACK) || ((this.getCell().getRow()-c.getRow()==1 && super.getPieceColor()==PieceColor.BLACK) ||
(this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()== PieceColor.WHITE)) ) (this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()==PieceColor.WHITE)) )
|| ||
(Math.abs(this.getCell().getCol()-c.getCol())==Math.abs(this.getCell().getRow()-c.getRow()) && (Math.abs(this.getCell().getCol()-c.getCol())==Math.abs(this.getCell().getRow()-c.getRow()) &&
((this.getCell().getRow()-c.getRow()==1 && super.getPieceColor()== PieceColor.BLACK && sw==1) || ((this.getCell().getRow()-c.getRow()==1 && super.getPieceColor()==PieceColor.BLACK && sw==1) ||
(this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()== PieceColor.WHITE && sw==1)) ) (this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()==PieceColor.WHITE && sw==1)) )
) return true ; ) return true ;
else return false ; else return false ;
} }
......
...@@ -27,27 +27,28 @@ public class Queen extends Piece { ...@@ -27,27 +27,28 @@ public class Queen extends Piece {
) { ) {
if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() < c.getRow()) { if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() < c.getRow()) {
for (int i=-1 ; i>-8 ; --i) { for (int i=-1 ; i>-8 ; --i) {
if (this.getCell().getRow()-i == c.getRow() && sw==1) break ;
if (!board[this.getCell().getRow()-i][this.getCell().getCol()-i].isEmpty()) return false; if (!board[this.getCell().getRow()-i][this.getCell().getCol()-i].isEmpty()) return false;
if (this.getCell().getRow()-i == c.getRow()) break ; if (this.getCell().getRow()-i == c.getRow()) break ;
} }
} }
if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() > c.getRow()) { if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() > c.getRow()) {
for (int i=-1 ; i>-8 ; --i) { for (int i=-1 ; i>-8 ; --i) {
if (!board[this.getCell().getRow()+i][this.getCell().getCol()-i].isEmpty()) { if (this.getCell().getRow()+i == c.getRow() && sw==1) break ;
//System.out.println("294 294") ; if (!board[this.getCell().getRow()+i][this.getCell().getCol()-i].isEmpty()) return false ;
return false ;
}
if (this.getCell().getRow()+i == c.getRow()) break ; if (this.getCell().getRow()+i == c.getRow()) break ;
} }
} }
if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() < c.getRow()) { if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() < c.getRow()) {
for (int i=1 ; i<8 ; ++i) { for (int i=1 ; i<8 ; ++i) {
if (this.getCell().getRow()+i == c.getRow() && sw==1) break ;
if (!board[this.getCell().getRow()+i][this.getCell().getCol()-i].isEmpty()) return false; if (!board[this.getCell().getRow()+i][this.getCell().getCol()-i].isEmpty()) return false;
if (this.getCell().getCol()-i == c.getCol()) break ; if (this.getCell().getCol()-i == c.getCol()) break ;
} }
} }
if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() > c.getRow()) { if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() > c.getRow()) {
for (int i=-1 ; i>-8 ; --i) { for (int i=-1 ; i>-8 ; --i) {
if (this.getCell().getRow()+i == c.getRow() && sw==1) break ;
if (!board[this.getCell().getRow()+i][this.getCell().getCol()+i].isEmpty()) return false; if (!board[this.getCell().getRow()+i][this.getCell().getCol()+i].isEmpty()) return false;
if (this.getCell().getCol()+i == c.getCol()) break ; if (this.getCell().getCol()+i == c.getCol()) break ;
} }
...@@ -55,27 +56,28 @@ public class Queen extends Piece { ...@@ -55,27 +56,28 @@ public class Queen extends Piece {
if (this.getCell().getCol() == c.getCol() && this.getCell().getRow() < c.getRow()) { if (this.getCell().getCol() == c.getCol() && this.getCell().getRow() < c.getRow()) {
for (int i=1 ; i<8 ; ++i) { for (int i=1 ; i<8 ; ++i) {
if (this.getCell().getRow()+i == c.getRow() && sw==1) break ;
if (!board[this.getCell().getRow()+i][c.getCol()].isEmpty()) return false; if (!board[this.getCell().getRow()+i][c.getCol()].isEmpty()) return false;
if (this.getCell().getRow()+i == c.getRow()) break ; if (this.getCell().getRow()+i == c.getRow()) break ;
} }
} }
if (this.getCell().getCol() == c.getCol() && this.getCell().getRow() > c.getRow()) { if (this.getCell().getCol() == c.getCol() && this.getCell().getRow() > c.getRow()) {
for (int i=-1 ; i>-8 ; --i) { for (int i=-1 ; i>-8 ; --i) {
if (!board[this.getCell().getRow()+i][c.getCol()].isEmpty()) { if (this.getCell().getRow()+i == c.getRow() && sw==1) break ;
//System.out.println("294 294") ; if (!board[this.getCell().getRow()+i][c.getCol()].isEmpty()) return false ;
return false;
}
if (this.getCell().getRow()+i == c.getRow()) break ; if (this.getCell().getRow()+i == c.getRow()) break ;
} }
} }
if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() == c.getRow()) { if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() == c.getRow()) {
for (int i=1 ; i<8 ; ++i) { for (int i=1 ; i<8 ; ++i) {
if (this.getCell().getCol()+i == c.getCol() && sw==1) break ;
if (!board[c.getRow()][this.getCell().getCol()+i].isEmpty()) return false; if (!board[c.getRow()][this.getCell().getCol()+i].isEmpty()) return false;
if (this.getCell().getCol()+i == c.getCol()) break ; if (this.getCell().getCol()+i == c.getCol()) break ;
} }
} }
if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() == c.getRow()) { if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() == c.getRow()) {
for (int i=-1 ; i>-8 ; --i) { for (int i=-1 ; i>-8 ; --i) {
if (this.getCell().getCol()+i == c.getCol() && sw==1) break ;
if (!board[c.getRow()][this.getCell().getCol()+i].isEmpty()) return false; if (!board[c.getRow()][this.getCell().getCol()+i].isEmpty()) return false;
if (this.getCell().getCol()+i == c.getCol()) break ; if (this.getCell().getCol()+i == c.getCol()) break ;
} }
......
...@@ -31,27 +31,28 @@ public class Rook extends Piece { ...@@ -31,27 +31,28 @@ public class Rook extends Piece {
) { ) {
if (this.getCell().getCol() == c.getCol() && this.getCell().getRow() < c.getRow()) { if (this.getCell().getCol() == c.getCol() && this.getCell().getRow() < c.getRow()) {
for (int i=1 ; i<8 ; ++i) { for (int i=1 ; i<8 ; ++i) {
if (this.getCell().getRow()+i == c.getRow() && sw==1) break ;
if (!board[this.getCell().getRow()+i][c.getCol()].isEmpty()) return false; if (!board[this.getCell().getRow()+i][c.getCol()].isEmpty()) return false;
if (this.getCell().getRow()+i == c.getRow()) break ; if (this.getCell().getRow()+i == c.getRow()) break ;
} }
} }
if (this.getCell().getCol() == c.getCol() && this.getCell().getRow() > c.getRow()) { if (this.getCell().getCol() == c.getCol() && this.getCell().getRow() > c.getRow()) {
for (int i=-1 ; i>-8 ; --i) { for (int i=-1 ; i>-8 ; --i) {
if (!board[this.getCell().getRow()+i][c.getCol()].isEmpty()) { if (this.getCell().getRow()+i == c.getRow() && sw==1) break ;
//System.out.println("294 294") ; if (!board[this.getCell().getRow()+i][c.getCol()].isEmpty()) return false;
return false;
}
if (this.getCell().getRow()+i == c.getRow()) break ; if (this.getCell().getRow()+i == c.getRow()) break ;
} }
} }
if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() == c.getRow()) { if (this.getCell().getCol() < c.getCol() && this.getCell().getRow() == c.getRow()) {
for (int i=1 ; i<8 ; ++i) { for (int i=1 ; i<8 ; ++i) {
if (this.getCell().getCol()+i == c.getCol() && sw==1) break ;
if (!board[c.getRow()][this.getCell().getCol()+i].isEmpty()) return false; if (!board[c.getRow()][this.getCell().getCol()+i].isEmpty()) return false;
if (this.getCell().getCol()+i == c.getCol()) break ; if (this.getCell().getCol()+i == c.getCol()) break ;
} }
} }
if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() == c.getRow()) { if (this.getCell().getCol() > c.getCol() && this.getCell().getRow() == c.getRow()) {
for (int i=-1 ; i>-8 ; --i) { for (int i=-1 ; i>-8 ; --i) {
if (this.getCell().getCol()+i == c.getCol() && sw==1) break ;
if (!board[c.getRow()][this.getCell().getCol()+i].isEmpty()) return false; if (!board[c.getRow()][this.getCell().getCol()+i].isEmpty()) return false;
if (this.getCell().getCol()+i == c.getCol()) break ; if (this.getCell().getCol()+i == c.getCol()) break ;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment