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
9731075
chess
Commits
f51b598c
Commit
f51b598c
authored
Apr 26, 2019
by
hosein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
canRoute -> override added
parent
8ce0c0e3
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
75 additions
and
11 deletions
+75
-11
Soldier.java
src/pack/Nut/Soldier.java
+0
-4
Bishop.java
src/pack/Nuts/Bishop.java
+15
-1
Knight.java
src/pack/Nuts/Knight.java
+4
-0
Nut.java
src/pack/Nuts/Nut.java
+17
-2
Pawn.java
src/pack/Nuts/Pawn.java
+14
-4
Rook.java
src/pack/Nuts/Rook.java
+25
-0
No files found.
src/pack/Nut/Soldier.java
deleted
100644 → 0
View file @
8ce0c0e3
package
pack
.
Nut
;
public
class
Soldier
{
}
src/pack/Nuts/Bishop.java
View file @
f51b598c
...
...
@@ -33,7 +33,7 @@ public class Bishop extends Nut {
public
boolean
canMove
(
int
[]
destination
)
{
if
(
x
==
destination
[
0
])
return
false
;
else
return
Math
.
abs
((
y
-
destination
[
1
])
/
(
x
-
destination
[
0
]))
==
1
;
return
Math
.
abs
((
y
-
destination
[
1
])
/
(
x
-
destination
[
0
]))
==
1
;
}
@Override
...
...
@@ -41,6 +41,20 @@ public class Bishop extends Nut {
isAlive
=
false
;
}
@Override
public
boolean
canRoute
(
int
[]
destination
,
int
[][]
ground
)
{
int
X
,
Y
;
if
(
destination
[
0
]
<
x
)
X
=
-
1
;
else
X
=
1
;
if
(
destination
[
1
]
<
y
)
Y
=
-
1
;
else
Y
=
1
;
for
(
int
i
=
x
+
X
,
j
=
y
+
Y
;
i
==
destination
[
0
];
i
+=
X
,
j
+=
Y
)
if
(
ground
[
i
][
j
]
!=
0
)
return
false
;
return
true
;
}
}
src/pack/Nuts/Knight.java
View file @
f51b598c
...
...
@@ -42,4 +42,8 @@ public class Knight extends Nut {
isAlive
=
false
;
}
@Override
public
boolean
canRoute
(
int
[]
destination
,
int
[][]
ground
)
{
return
true
;
}
}
src/pack/Nuts/Nut.java
View file @
f51b598c
package
pack
.
Nuts
;
public
abstract
class
Nut
{
public
abstract
void
move
();
protected
int
id
,
x
,
y
;
// 1 means white & -1 means black
protected
boolean
isAlive
;
public
void
move
(
int
[]
destination
)
{
x
=
destination
[
0
];
y
=
destination
[
1
];
}
public
abstract
boolean
canRoute
(
int
[]
destination
,
int
[][]
ground
);
public
abstract
boolean
canMove
(
int
[]
destination
);
public
void
changeAlive
()
{
isAlive
=
false
;
}
}
src/pack/Nuts/Pawn.java
View file @
f51b598c
...
...
@@ -22,16 +22,26 @@ public class Pawn extends Nut {
@Override
public
boolean
canMove
(
int
[]
destination
)
{
if
(
id
>
0
)
{
if
(
x
==
6
&&
destination
[
0
]
-
x
==
2
&&
destination
[
1
]
==
y
)
return
true
;
return
destination
[
0
]
<
x
&&
destination
[
0
]
>=
x
-
1
&&
destination
[
1
]
<=
y
+
1
&&
destination
[
1
]
>=
y
-
1
;
}
else
{
}
else
{
if
(
x
==
1
&&
destination
[
0
]
-
x
==
2
&&
destination
[
1
]
==
y
)
return
true
;
return
destination
[
0
]
>
x
&&
destination
[
0
]
<=
x
+
1
&&
destination
[
1
]
<=
y
+
1
&&
destination
[
1
]
>=
y
-
1
;
}}
}
}
@Override
public
void
changeAlive
()
{
isAlive
=
false
;
}
@Override
public
boolean
canRoute
(
int
[]
destination
,
int
[][]
ground
)
{
if
(
destination
[
0
]
-
x
==
2
&&
ground
[(
x
+
destination
[
0
])/
2
][
y
]
!=
0
)
return
false
;
return
true
;
}
}
src/pack/Nuts/Rook.java
View file @
f51b598c
...
...
@@ -40,4 +40,29 @@ public class Rook extends Nut {
isAlive
=
false
;
}
@Override
public
boolean
canRoute
(
int
[]
destination
,
int
[][]
ground
)
{
if
(
destination
[
0
]
==
x
)
{
int
t
;
if
(
destination
[
1
]
-
y
>
0
)
t
=
1
;
else
t
=
-
1
;
for
(
int
i
=
y
+
t
;
i
<
destination
[
1
];
i
+=
t
)
if
(
ground
[
x
][
i
]
!=
0
)
return
false
;
}
else
{
int
t
;
if
(
destination
[
0
]
-
x
>
0
)
t
=
1
;
else
t
=
-
1
;
for
(
int
i
=
x
+
t
;
i
<
destination
[
0
];
i
+=
t
)
if
(
ground
[
i
][
y
]
!=
0
)
return
false
;
}
return
true
;
}
}
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