Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
Chess-AP
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
Omid Sayfun
Chess-AP
Commits
8b09ab57
Commit
8b09ab57
authored
May 20, 2019
by
Omid Sayfun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Socket added
parent
67380b70
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
318 additions
and
118 deletions
+318
-118
Main.java
src/Main.java
+277
-108
Bishop.java
src/lab/game/Bishop.java
+2
-2
Board.java
src/lab/game/Board.java
+32
-2
Pawn.java
src/lab/game/Pawn.java
+1
-1
Piece.java
src/lab/game/Piece.java
+4
-3
Rook.java
src/lab/game/Rook.java
+2
-2
No files found.
src/Main.java
View file @
8b09ab57
This diff is collapsed.
Click to expand it.
src/lab/game/Bishop.java
View file @
8b09ab57
...
...
@@ -36,7 +36,7 @@ public class Bishop extends Piece{
int
yShift
=
(
y
-
p
.
y
)
/
Math
.
abs
(
y
-
p
.
y
);
int
i
=
1
;
while
(
x
!=
(
char
)(
p
.
x
+
i
*
xShift
)
&&
y
!=
p
.
y
+
i
*
yShift
){
if
(
checkTaken
(
pieces
,
(
char
)(
p
.
x
+
i
*
xShift
),
p
.
y
+
i
*
yShift
)
){
if
(
checkTaken
(
pieces
,
(
char
)(
p
.
x
+
i
*
xShift
),
p
.
y
+
i
*
yShift
)
!=
null
&&
!(
checkTaken
(
pieces
,
(
char
)(
p
.
x
+
i
*
xShift
),
p
.
y
+
i
*
yShift
)
instanceof
King
)
){
return
false
;
}
...
...
@@ -50,7 +50,7 @@ public class Bishop extends Piece{
int
yShift
=
(
y
-
this
.
y
)
/
Math
.
abs
(
y
-
this
.
y
);
int
i
=
1
;
while
(
x
!=
(
char
)(
this
.
x
+
i
*
xShift
)
&&
y
!=
this
.
y
+
i
*
yShift
){
if
(
checkTaken
(
pieces
,
(
char
)(
this
.
x
+
i
*
xShift
),
this
.
y
+
i
*
yShift
)
){
if
(
checkTaken
(
pieces
,
(
char
)(
this
.
x
+
i
*
xShift
),
this
.
y
+
i
*
yShift
)
!=
null
&&
!(
checkTaken
(
pieces
,
(
char
)(
this
.
x
+
i
*
xShift
),
this
.
y
+
i
*
yShift
)
instanceof
King
)
){
return
false
;
}
...
...
src/lab/game/Board.java
View file @
8b09ab57
...
...
@@ -343,15 +343,21 @@ public class Board{
}
public
boolean
virtualCheck
(
ArrayList
<
Piece
>
enemy
,
char
x
,
int
y
){
String
temp
=
Character
.
toString
(
enemy
.
get
(
0
).
getName
().
charAt
(
0
));
for
(
Piece
p
:
enemy
){
if
(
p
.
canMove
(
x
,
y
)
){
// Check if move is valid
if
(
p
.
checkWay
(
this
.
allPieces
,
x
,
y
)
){
if
(
p
instanceof
Pawn
&&
p
.
getX
()
-
x
==
0
){
return
false
;
}
else
{
return
true
;
}
}
}
}
return
false
;
}
...
...
@@ -630,7 +636,31 @@ public class Board{
if
(
found
.
checkWay
(
this
.
allPieces
,
x
,
y
)
){
if
(
(
found
instanceof
Pawn
)
&&
found
.
crossMove
(
x
,
y
)
&&
attack
==
null
){
if
(
(
found
instanceof
Pawn
)
&&
found
.
crossMove
(
x
,
y
)
){
if
(
attack
==
null
){
return
false
;
}
else
{
if
(
y
==
attack
.
getY
()
&&
x
==
attack
.
getX
()
){
if
(
found
.
color
&&
y
<
found
.
getY
()
){
return
true
;
}
else
if
(
!
found
.
color
&&
found
.
getY
()
<
y
){
return
true
;
}
else
{
return
false
;
}
}
else
{
return
false
;
}
}
}
else
if
(
(
found
instanceof
Pawn
)
&&
attack
!=
null
&&
found
.
getX
()
-
attack
.
getX
()
==
0
){
return
false
;
}
else
if
(
(
found
instanceof
King
)
&&
virtualCheck
(
enemy
,
x
,
y
)){
return
false
;
}
else
{
...
...
src/lab/game/Pawn.java
View file @
8b09ab57
...
...
@@ -55,7 +55,7 @@ public class Pawn extends Piece{
return
true
;
}
else
{
int
yShift
=
(
y
-
this
.
y
)
/
Math
.
abs
(
y
-
this
.
y
);
if
(
checkTaken
(
pieces
,
this
.
x
,
this
.
y
+
yShift
)
||
checkTaken
(
pieces
,
this
.
x
,
this
.
y
+
2
*
yShift
)
){
if
(
checkTaken
(
pieces
,
this
.
x
,
this
.
y
+
yShift
)
!=
null
||
checkTaken
(
pieces
,
this
.
x
,
this
.
y
+
2
*
yShift
)
!=
null
){
return
false
;
}
...
...
src/lab/game/Piece.java
View file @
8b09ab57
...
...
@@ -47,14 +47,15 @@ public abstract class Piece{
return
this
.
color
;
}
public
static
boolean
checkTaken
(
ArrayList
<
Piece
>
pieces
,
char
x
,
int
y
){
public
static
Piece
checkTaken
(
ArrayList
<
Piece
>
pieces
,
char
x
,
int
y
){
for
(
Piece
p
:
pieces
){
if
(
p
.
x
==
x
&&
p
.
y
==
y
){
return
true
;
return
p
;
}
}
return
false
;
return
null
;
}
public
boolean
crossMove
(
char
x
,
int
y
){
...
...
src/lab/game/Rook.java
View file @
8b09ab57
...
...
@@ -63,7 +63,7 @@ public class Rook extends Piece{
int
i
=
1
;
boolean
flag
=
true
;
while
(
this
.
x
!=
(
char
)(
x
+
i
*
xShift
)
||
this
.
y
!=
y
+
i
*
yShift
){
if
(
checkTaken
(
pieces
,
(
char
)(
x
+
i
*
xShift
),
y
+
i
*
yShift
)
){
if
(
checkTaken
(
pieces
,
(
char
)(
x
+
i
*
xShift
),
y
+
i
*
yShift
)
!=
null
&&
!(
checkTaken
(
pieces
,
(
char
)(
x
+
i
*
xShift
),
y
+
i
*
yShift
)
instanceof
King
)
){
flag
=
false
;
}
...
...
@@ -90,7 +90,7 @@ public class Rook extends Piece{
}
int
i
=
1
;
while
(
x
!=
(
char
)(
p
.
x
+
i
*
xShift
)
||
y
!=
p
.
y
+
i
*
yShift
){
if
(
checkTaken
(
pieces
,
(
char
)(
p
.
x
+
i
*
xShift
),
p
.
y
+
i
*
yShift
)
){
if
(
checkTaken
(
pieces
,
(
char
)(
p
.
x
+
i
*
xShift
),
p
.
y
+
i
*
yShift
)
!=
null
&&
!(
checkTaken
(
pieces
,
(
char
)(
p
.
x
+
i
*
xShift
),
p
.
y
+
i
*
yShift
)
instanceof
King
)
){
return
false
;
}
...
...
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