Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
Chess
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9631408
Chess
Commits
f6bd2726
Commit
f6bd2726
authored
May 23, 2019
by
kimia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
true moves
parent
00cffa12
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
85 deletions
+83
-85
Bishop.java
src/Bishop.java
+8
-28
ChessBoardGUI.java
src/ChessBoardGUI.java
+31
-30
ChessGameGUI.java
src/ChessGameGUI.java
+15
-5
Pawn.java
src/Pawn.java
+14
-10
Queen.java
src/Queen.java
+10
-8
Rook.java
src/Rook.java
+5
-4
No files found.
src/Bishop.java
View file @
f6bd2726
...
...
@@ -24,49 +24,29 @@ public class Bishop extends Piece {
)
&&
(
c
.
isEmpty
()
||
(!
c
.
isEmpty
()
&&
sw
==
1
))
)
{
if
(
this
.
getCell
().
getCol
()
<
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
<
c
.
getRow
())
{
for
(
int
i
=-
1
;
i
>-
8
;
--
i
)
{
if
(!
board
[
this
.
getCell
().
getRow
()-
i
][
this
.
getCell
().
getCol
()-
i
].
isEmpty
()){
Cell
newCell
=
new
Cell
(
this
.
getCell
().
getRow
()-
i
,
this
.
getCell
().
getCol
()-
i
);
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
()
&&
sw
==
1
)
break
;
if
(!
board
[
this
.
getCell
().
getRow
()-
i
][
this
.
getCell
().
getCol
()-
i
].
isEmpty
())
return
false
;
if
(
this
.
getCell
().
getRow
()-
i
==
c
.
getRow
())
break
;
}
}
if
(
this
.
getCell
().
getCol
()
<
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
>
c
.
getRow
())
{
for
(
int
i
=-
1
;
i
>-
8
;
--
i
)
{
if
(!
board
[
this
.
getCell
().
getRow
()+
i
][
this
.
getCell
().
getCol
()-
i
].
isEmpty
())
{
Cell
newCell
=
new
Cell
(
this
.
getCell
().
getRow
()+
i
,
this
.
getCell
().
getCol
()-
i
);
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
()
&&
sw
==
1
)
break
;
if
(!
board
[
this
.
getCell
().
getRow
()+
i
][
this
.
getCell
().
getCol
()-
i
].
isEmpty
())
return
false
;
if
(
this
.
getCell
().
getRow
()+
i
==
c
.
getRow
())
break
;
}
}
if
(
this
.
getCell
().
getCol
()
>
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
<
c
.
getRow
())
{
for
(
int
i
=
1
;
i
<
8
;
++
i
)
{
if
(!
board
[
this
.
getCell
().
getRow
()+
i
][
this
.
getCell
().
getCol
()-
i
].
isEmpty
())
{
Cell
newCell
=
new
Cell
(
this
.
getCell
().
getRow
()+
i
,
this
.
getCell
().
getCol
()-
i
);
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
()
&&
sw
==
1
)
break
;
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
()
>
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
>
c
.
getRow
())
{
for
(
int
i
=-
1
;
i
>-
8
;
--
i
)
{
if
(!
board
[
this
.
getCell
().
getRow
()+
i
][
this
.
getCell
().
getCol
()+
i
].
isEmpty
())
{
Cell
newCell
=
new
Cell
(
this
.
getCell
().
getRow
()+
i
,
this
.
getCell
().
getCol
()+
i
);
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
()
&&
sw
==
1
)
break
;
if
(!
board
[
this
.
getCell
().
getRow
()+
i
][
this
.
getCell
().
getCol
()+
i
].
isEmpty
())
return
false
;
if
(
this
.
getCell
().
getCol
()+
i
==
c
.
getCol
())
break
;
}
}
...
...
src/ChessBoardGUI.java
View file @
f6bd2726
...
...
@@ -6,8 +6,11 @@ import java.util.ArrayList;
public
class
ChessBoardGUI
extends
JPanel
{
public
JButton
[][]
button
=
new
JButton
[
8
][
8
];
JPanel
removedPiecePanel
;
JButton
removedPieces
[][]
=
new
JButton
[
8
][
4
];
private
JPanel
whiteRemovedPiecePanel
;
private
JPanel
blackRemovedPiecePanel
;
private
JPanel
turnPanel
;
private
JButton
removedPieces
[][]
=
new
JButton
[
8
][
4
];
private
JLabel
turnLabel
=
new
JLabel
();
private
int
wORb
=
0
;
private
Piece
pw
[];
private
Piece
pb
[];
...
...
@@ -19,9 +22,11 @@ public class ChessBoardGUI extends JPanel {
private
boolean
[][]
moveBoard
=
null
;
public
ArrayList
<
Piece
>
deletedList
=
new
ArrayList
<>();
private
JFrame
parentPanel
;
public
ChessBoardGUI
(
JPanel
removedPiece
Panel
,
JFrame
parentPanel
){
public
ChessBoardGUI
(
JPanel
whiteRemovedPiecePanel
,
JPanel
blackRemovedPiecePanel
,
JPanel
turn
Panel
,
JFrame
parentPanel
){
super
();
this
.
removedPiecePanel
=
removedPiecePanel
;
this
.
whiteRemovedPiecePanel
=
whiteRemovedPiecePanel
;
this
.
blackRemovedPiecePanel
=
blackRemovedPiecePanel
;
this
.
turnPanel
=
turnPanel
;
this
.
parentPanel
=
parentPanel
;
parentPanel
.
setTitle
(
"White Turn..."
);
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
...
...
@@ -53,10 +58,10 @@ public class ChessBoardGUI extends JPanel {
int
condition
=
checkCondition
(
board
,
pw
,
pb
);
if
(
condition
==
2
){
JOptionPane
.
showMessageDialog
(
removedPiece
Panel
,
"Condition White"
);
JOptionPane
.
showMessageDialog
(
turn
Panel
,
"Condition White"
);
}
else
if
(
condition
==
1
){
JOptionPane
.
showMessageDialog
(
removedPiece
Panel
,
"Condition Black"
);
JOptionPane
.
showMessageDialog
(
turn
Panel
,
"Condition Black"
);
}
//----------------
}
...
...
@@ -66,9 +71,9 @@ public class ChessBoardGUI extends JPanel {
updateGUIBoard
(
moveBoard
);
}
if
(
wORb
%
2
==
0
){
parentPanel
.
setTitle
(
"White Turn..."
);
turnLabel
.
setText
(
"White Turn..."
);
}
else
{
parentPanel
.
setTitle
(
"Black Turn..."
);
turnLabel
.
setText
(
"Black Turn..."
);
}
}
});
...
...
@@ -84,13 +89,18 @@ public class ChessBoardGUI extends JPanel {
}
private
void
inilizeRemovedPiecePanel
(){
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
].
setBackground
(
Color
.
YELLOW
);
// 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
(){
int
wCount
=
0
;
...
...
@@ -166,11 +176,11 @@ public class ChessBoardGUI extends JPanel {
boolean
[][]
binaryBoard
=
new
boolean
[
8
][
8
];
if
(
wORb
%
2
==
0
)
{
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
j
=
0
;
j
<
8
;
j
++){
Cell
dest
=
new
Cell
(
i
,
j
);
if
(
p
.
isValidMove
(
dest
,
board
,
pw
,
pb
)){
//
Cell dest = new Cell(i,j);
if
(
p
.
isValidMove
(
board
[
i
][
j
]
,
board
,
pw
,
pb
)){
binaryBoard
[
i
][
j
]
=
true
;
}
}
...
...
@@ -180,11 +190,10 @@ public class ChessBoardGUI extends JPanel {
}
}
else
{
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
j
=
0
;
j
<
8
;
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
;
}
}
...
...
@@ -199,18 +208,14 @@ public class ChessBoardGUI extends JPanel {
//--------------
if
(
wORb
%
2
==
0
)
{
for
(
Piece
p
:
pw
)
{
if
(
p
.
getCell
().
getRow
()
==
source
.
getRow
()
&&
if
(
!
p
.
isDeleted
()
&&
p
.
getCell
().
getRow
()
==
source
.
getRow
()
&&
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
++;
board
[
p
.
getCell
().
getRow
()][
p
.
getCell
().
getCol
()].
setEmpty
(
true
);
p
.
setCell
(
dest
);
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
)
{
Pawn
myPawn
=
(
Pawn
)
p
;
myPawn
.
setOnce
(
false
);
...
...
@@ -228,18 +233,14 @@ public class ChessBoardGUI extends JPanel {
}
}
else
{
for
(
Piece
p:
pb
)
{
if
(
p
.
getCell
().
getRow
()==
source
.
getRow
()
&&
if
(
!
p
.
isDeleted
()
&&
p
.
getCell
().
getRow
()==
source
.
getRow
()
&&
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
++
;
board
[
p
.
getCell
().
getRow
()][
p
.
getCell
().
getCol
()].
setEmpty
(
true
)
;
p
.
setCell
(
dest
)
;
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
)
{
Pawn
myPawn
=
(
Pawn
)
p
;
myPawn
.
setOnce
(
false
)
;
...
...
src/ChessGameGUI.java
View file @
f6bd2726
...
...
@@ -14,13 +14,23 @@ public class ChessGameGUI extends JFrame {
parent
.
setSize
(
1300
,
610
);
setResizable
(
false
);
parent
.
setLayout
(
new
BoxLayout
(
parent
,
BoxLayout
.
X_AXIS
));
JPanel
p1
=
new
JPanel
();
p1
.
setLayout
(
new
GridLayout
(
8
,
5
));
p1
.
setSize
(
500
,
600
);
//-----------------------------------------
JPanel
whiteRemovePanel
=
new
JPanel
();
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
);
parent
.
add
(
p1
);
parent
.
add
(
whiteRemovePanel
);
parent
.
add
(
turnPanel
);
parent
.
add
(
blackRemovePanel
);
parent
.
add
(
gameBoard
);
add
(
parent
);
setVisible
(
true
);
...
...
src/Pawn.java
View file @
f6bd2726
...
...
@@ -18,18 +18,22 @@ public class Pawn extends Piece{
@Override
public
boolean
isValidMove
(
Cell
c
,
Cell
board
[][],
Piece
pw
[],
Piece
pb
[])
{
if
(
super
.
isDeleted
())
return
false
;
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
.
BLACK
&&
super
.
getCell
().
getRow
()==
0
)
end
=
true
;
if
(
super
.
getPieceColor
()==
PieceColor
.
WHITE
&&
super
.
getCell
().
getRow
()==
7
)
end
=
true
;
int
sw
=
0
;
if
(
super
.
getPieceColor
()
==
PieceColor
.
BLACK
)
{
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
{
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{
//System.out.println("col: " + this.getCell().getCol()) ;
if
((
this
.
getCell
().
getCol
()
==
c
.
getCol
())
&&
(
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
)
{
return
true
;
}
else
if
(
getCell
().
getRow
()
>
c
.
getRow
()
&&
getPieceColor
()==
PieceColor
.
BLACK
){
...
...
@@ -62,13 +66,13 @@ public class Pawn extends Piece{
}
else
{
if
(
(
this
.
getCell
().
getCol
()
==
c
.
getCol
()
&&
((
this
.
getCell
().
getRow
()-
c
.
getRow
()==
1
&&
super
.
getPieceColor
()==
PieceColor
.
BLACK
)
||
(
this
.
getCell
().
getRow
()-
c
.
getRow
()==-
1
&&
super
.
getPieceColor
()==
PieceColor
.
WHITE
))
)
(
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
.
WHITE
))
)
||
(
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
.
WHITE
&&
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
))
)
)
return
true
;
else
return
false
;
}
...
...
src/Queen.java
View file @
f6bd2726
...
...
@@ -27,27 +27,28 @@ public class Queen extends Piece {
)
{
if
(
this
.
getCell
().
getCol
()
<
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
<
c
.
getRow
())
{
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
(
this
.
getCell
().
getRow
()-
i
==
c
.
getRow
())
break
;
}
}
if
(
this
.
getCell
().
getCol
()
<
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
>
c
.
getRow
())
{
for
(
int
i
=-
1
;
i
>-
8
;
--
i
)
{
if
(!
board
[
this
.
getCell
().
getRow
()+
i
][
this
.
getCell
().
getCol
()-
i
].
isEmpty
())
{
//System.out.println("294 294") ;
return
false
;
}
if
(
this
.
getCell
().
getRow
()+
i
==
c
.
getRow
()
&&
sw
==
1
)
break
;
if
(!
board
[
this
.
getCell
().
getRow
()+
i
][
this
.
getCell
().
getCol
()-
i
].
isEmpty
())
return
false
;
if
(
this
.
getCell
().
getRow
()+
i
==
c
.
getRow
())
break
;
}
}
if
(
this
.
getCell
().
getCol
()
>
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
<
c
.
getRow
())
{
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
(
this
.
getCell
().
getCol
()-
i
==
c
.
getCol
())
break
;
}
}
if
(
this
.
getCell
().
getCol
()
>
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
>
c
.
getRow
())
{
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
(
this
.
getCell
().
getCol
()+
i
==
c
.
getCol
())
break
;
}
...
...
@@ -55,27 +56,28 @@ public class Queen extends Piece {
if
(
this
.
getCell
().
getCol
()
==
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
<
c
.
getRow
())
{
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
(
this
.
getCell
().
getRow
()+
i
==
c
.
getRow
())
break
;
}
}
if
(
this
.
getCell
().
getCol
()
==
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
>
c
.
getRow
())
{
for
(
int
i
=-
1
;
i
>-
8
;
--
i
)
{
if
(!
board
[
this
.
getCell
().
getRow
()+
i
][
c
.
getCol
()].
isEmpty
())
{
//System.out.println("294 294") ;
return
false
;
}
if
(
this
.
getCell
().
getRow
()+
i
==
c
.
getRow
()
&&
sw
==
1
)
break
;
if
(!
board
[
this
.
getCell
().
getRow
()+
i
][
c
.
getCol
()].
isEmpty
())
return
false
;
if
(
this
.
getCell
().
getRow
()+
i
==
c
.
getRow
())
break
;
}
}
if
(
this
.
getCell
().
getCol
()
<
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
==
c
.
getRow
())
{
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
(
this
.
getCell
().
getCol
()+
i
==
c
.
getCol
())
break
;
}
}
if
(
this
.
getCell
().
getCol
()
>
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
==
c
.
getRow
())
{
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
(
this
.
getCell
().
getCol
()+
i
==
c
.
getCol
())
break
;
}
...
...
src/Rook.java
View file @
f6bd2726
...
...
@@ -31,27 +31,28 @@ public class Rook extends Piece {
)
{
if
(
this
.
getCell
().
getCol
()
==
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
<
c
.
getRow
())
{
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
(
this
.
getCell
().
getRow
()+
i
==
c
.
getRow
())
break
;
}
}
if
(
this
.
getCell
().
getCol
()
==
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
>
c
.
getRow
())
{
for
(
int
i
=-
1
;
i
>-
8
;
--
i
)
{
if
(!
board
[
this
.
getCell
().
getRow
()+
i
][
c
.
getCol
()].
isEmpty
())
{
//System.out.println("294 294") ;
return
false
;
}
if
(
this
.
getCell
().
getRow
()+
i
==
c
.
getRow
()
&&
sw
==
1
)
break
;
if
(!
board
[
this
.
getCell
().
getRow
()+
i
][
c
.
getCol
()].
isEmpty
())
return
false
;
if
(
this
.
getCell
().
getRow
()+
i
==
c
.
getRow
())
break
;
}
}
if
(
this
.
getCell
().
getCol
()
<
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
==
c
.
getRow
())
{
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
(
this
.
getCell
().
getCol
()+
i
==
c
.
getCol
())
break
;
}
}
if
(
this
.
getCell
().
getCol
()
>
c
.
getCol
()
&&
this
.
getCell
().
getRow
()
==
c
.
getRow
())
{
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
(
this
.
getCell
().
getCol
()+
i
==
c
.
getCol
())
break
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment