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
8ce0c0e3
Commit
8ce0c0e3
authored
Apr 25, 2019
by
hosein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
all nuts classes -> canMove added
parent
00443b1f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
193 additions
and
5 deletions
+193
-5
Bishop.java
src/pack/Nuts/Bishop.java
+43
-1
King.java
src/pack/Nuts/King.java
+32
-1
Knight.java
src/pack/Nuts/Knight.java
+42
-1
Queen.java
src/pack/Nuts/Queen.java
+36
-1
Rook.java
src/pack/Nuts/Rook.java
+40
-1
No files found.
src/pack/Nuts/Bishop.java
View file @
8ce0c0e3
package
pack
.
Nuts
;
public
class
Bishop
{
public
class
Bishop
extends
Nut
{
public
Bishop
(
int
id
)
{
this
.
id
=
id
;
isAlive
=
true
;
switch
(
id
)
{
case
13
:
x
=
7
;
y
=
2
;
break
;
case
14
:
x
=
7
;
y
=
5
;
break
;
case
-
13
:
x
=
0
;
y
=
5
;
break
;
case
-
14
:
x
=
0
;
y
=
2
;
}
}
// @Override
// public void move(int[] destination) {
//
// }
@Override
public
boolean
canMove
(
int
[]
destination
)
{
if
(
x
==
destination
[
0
])
return
false
;
else
return
Math
.
abs
((
y
-
destination
[
1
])/(
x
-
destination
[
0
]))
==
1
;
}
@Override
public
void
changeAlive
()
{
isAlive
=
false
;
}
}
src/pack/Nuts/King.java
View file @
8ce0c0e3
package
pack
.
Nuts
;
public
class
King
{
public
class
King
extends
Nut
{
public
King
(
int
id
)
{
this
.
id
=
id
;
isAlive
=
true
;
if
(
id
==
16
)
{
x
=
7
;
y
=
4
;
}
else
{
x
=
0
;
y
=
3
;
}
}
// @Override
// public void move(int[] destination) {
//
// }
@Override
public
boolean
canMove
(
int
[]
destination
)
{
return
Math
.
pow
(
x
-
destination
[
0
],
2
)
+
Math
.
pow
(
y
-
destination
[
1
],
2
)
<=
2
;
}
public
boolean
isCheck
()
{
return
false
;
}
@Override
public
void
changeAlive
()
{
isAlive
=
false
;
}
}
src/pack/Nuts/Knight.java
View file @
8ce0c0e3
package
pack
.
Nuts
;
public
class
Knight
{
import
java.lang.Math
;
public
class
Knight
extends
Nut
{
public
Knight
(
int
id
)
{
this
.
id
=
id
;
isAlive
=
true
;
switch
(
id
)
{
case
11
:
x
=
7
;
y
=
1
;
break
;
case
12
:
x
=
7
;
y
=
6
;
break
;
case
-
11
:
x
=
0
;
y
=
6
;
break
;
case
-
12
:
x
=
0
;
y
=
1
;
}
}
// @Override
// public void move(int[] destination) {
// x = destination[0];
// y = destination[1];
// }
@Override
public
boolean
canMove
(
int
[]
destination
)
{
return
Math
.
pow
(
destination
[
0
]
-
x
,
2
)
+
Math
.
pow
(
destination
[
1
]
-
y
,
2
)
==
5
;
}
@Override
public
void
changeAlive
()
{
isAlive
=
false
;
}
}
src/pack/Nuts/Queen.java
View file @
8ce0c0e3
package
pack
.
Nuts
;
public
class
Queen
{
public
class
Queen
extends
Nut
{
public
Queen
(
int
id
)
{
this
.
id
=
id
;
isAlive
=
true
;
if
(
id
==
15
)
{
x
=
7
;
y
=
3
;
}
else
{
x
=
0
;
y
=
4
;
}
}
// @Override
// public void move(int[] destination) {
//
// }
@Override
public
boolean
canMove
(
int
[]
destination
)
{
if
(
x
==
destination
[
0
]
||
y
==
destination
[
1
])
return
true
;
else
{
if
(
x
==
destination
[
0
])
return
false
;
else
return
Math
.
abs
((
y
-
destination
[
1
])/(
x
-
destination
[
0
]))
==
1
;
}
}
@Override
public
void
changeAlive
()
{
isAlive
=
false
;
}
}
src/pack/Nuts/Rook.java
View file @
8ce0c0e3
package
pack
.
Nuts
;
public
class
Rook
{
public
class
Rook
extends
Nut
{
public
Rook
(
int
id
)
{
this
.
id
=
id
;
isAlive
=
true
;
switch
(
id
)
{
case
9
:
x
=
7
;
y
=
0
;
break
;
case
10
:
x
=
7
;
y
=
7
;
break
;
case
-
9
:
x
=
0
;
y
=
7
;
break
;
case
-
10
:
x
=
0
;
y
=
0
;
}
}
// @Override
// public void move(int[] destination) {
// x = destination[0];
// y = destination[1];
// }
@Override
public
boolean
canMove
(
int
[]
destination
)
{
return
x
==
destination
[
0
]
||
y
==
destination
[
1
];
}
@Override
public
void
changeAlive
()
{
isAlive
=
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