Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
ChessProject
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
9631413
ChessProject
Commits
7fa5c498
Commit
7fa5c498
authored
May 12, 2019
by
hamed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
threats of King is removed from list of possible movment
parent
610acdb4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
2 deletions
+44
-2
Cell.java
src/Main/Cell.java
+20
-0
Main.java
src/Main/Main.java
+1
-1
King.java
src/Pieces/King.java
+23
-1
No files found.
src/Main/Cell.java
0 → 100644
View file @
7fa5c498
package
Main
;
public
class
Cell
implements
Comparable
<
Cell
>{
int
x
;
int
y
;
public
Cell
(
int
x
,
int
y
){
this
.
x
=
x
;
this
.
y
=
y
;
}
@Override
public
int
compareTo
(
Cell
o
)
{
if
(
o
.
x
==
x
){
return
o
.
y
-
y
;
}
else
{
return
o
.
x
-
x
;
}
}
}
src/Main/Main.java
View file @
7fa5c498
...
...
@@ -72,7 +72,7 @@ public class Main {
}
public
static
void
printMoves
(
ArrayList
<
int
[]>
moves
){
for
(
int
m
[]
:
moves
){
System
.
out
.
print
((
char
)(
m
[
0
]+
'a'
)+
""
+(
m
[
1
]+
1
)+
"
\t
"
);
System
.
out
.
print
((
char
)(
m
[
0
]+
'a'
)+
""
+(
m
[
1
]+
1
)+
"
,
"
);
}
System
.
out
.
println
();
}
...
...
src/Pieces/King.java
View file @
7fa5c498
package
Pieces
;
import
Main.Board
;
import
Main.Cell
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
public
class
King
extends
Piece
{
...
...
@@ -40,9 +42,26 @@ public class King extends Piece {
return
false
;
}
public
HashSet
<
Cell
>
getThreatedPlaces
(){
HashSet
<
Cell
>
retSet
=
new
HashSet
<>();
for
(
int
i
=
0
;
i
<
8
;
i
++){
for
(
int
j
=
0
;
j
<
8
;
j
++){
Piece
p
=
getBoard
().
getBoard
()[
i
][
j
];
if
(
p
!=
null
&&
(
p
.
isWhite
()!=
isWhite
())){
ArrayList
<
int
[]>
moves
=
p
.
moves
();
for
(
int
m
[]
:
moves
){
Cell
c
=
new
Cell
(
m
[
0
],
m
[
1
]);
retSet
.
add
(
c
);
}
}
}
}
return
retSet
;
}
@Override
public
ArrayList
<
int
[]>
moves
()
{
ArrayList
<
int
[]>
move
=
new
ArrayList
<>();
HashSet
<
Cell
>
threats
=
getThreatedPlaces
();
int
x
=
getX
();
int
y
=
getY
();
int
posx
[]={
x
,
x
,
x
+
1
,
x
+
1
,
x
+
1
,
x
-
1
,
x
-
1
,
x
-
1
};
...
...
@@ -51,7 +70,10 @@ public class King extends Piece {
if
((
posx
[
i
]>=
0
&&
posx
[
i
]<
8
&&
posy
[
i
]>=
0
&&
posy
[
i
]<
8
)){
if
(
getBoard
().
isEmpty
(
posx
[
i
],
posy
[
i
])
||
(
getBoard
().
getColor
(
posx
[
i
],
posy
[
i
])==
2
&&
this
.
isWhite
())
||(
getBoard
().
getColor
(
posx
[
i
],
posy
[
i
])==
1
&&
isBlack
())
)
{
move
.
add
(
new
int
[]{
posx
[
i
],
posy
[
i
]});
Cell
cmp
=
new
Cell
(
posx
[
i
],
posy
[
i
]);
if
(!
threats
.
contains
(
cmp
))
{
move
.
add
(
new
int
[]{
posx
[
i
],
posy
[
i
]});
}
}
}
}
...
...
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