Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
agile-java
/
ChessAndroid
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
125aa959
authored
Jun 01, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring in Piece and Pawn
parent
63f13924
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
33 deletions
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Bishop.java
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Knight.java
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Pawn.java
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Piece.java
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Bishop.java
View file @
125aa959
package
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
;
import
com.example.paktalin.agilejava_exercises.Position
;
/**
* Created by Paktalin on 01/06/2018.
*/
public
class
Bishop
extends
Piece
{
public
Bishop
(
Piece
.
Color
color
)
{
strength
=
3
;
representation
=
'b'
;
...
...
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Knight.java
View file @
125aa959
package
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
;
import
com.example.paktalin.agilejava_exercises.Position
;
/**
* Created by Paktalin on 01/06/2018.
*/
...
...
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Pawn.java
View file @
125aa959
package
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
;
import
com.example.paktalin.agilejava_exercises.Position
;
import
java.util.List
;
/**
...
...
@@ -27,8 +25,16 @@ public class Pawn extends Piece {
}
private
static
boolean
pawnsOnSameColumn
(
Piece
currentPiece
,
Piece
piece
)
{
return
piece
.
getPosition
().
getColumn
()
==
currentPiece
.
getPosition
().
getColumn
()
&&
piece
.
getPosition
().
getRow
()
!=
currentPiece
.
getPosition
().
getRow
()
&&
piece
.
getClass
()
==
currentPiece
.
getClass
();
return
sameColumn
(
currentPiece
,
piece
)
&&
sameRow
(
currentPiece
,
piece
)
&&
piece
.
getClass
()
==
Pawn
.
class
;
}
private
static
boolean
sameColumn
(
Piece
piece1
,
Piece
piece2
)
{
return
piece2
.
getPosition
().
getColumn
()
==
piece1
.
getPosition
().
getColumn
();
}
private
static
boolean
sameRow
(
Piece
piece1
,
Piece
piece2
)
{
return
piece2
.
getPosition
().
getRow
()
==
piece1
.
getPosition
().
getRow
();
}
}
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Piece.java
View file @
125aa959
...
...
@@ -17,22 +17,25 @@ public abstract class Piece implements Comparable<Piece> {
public
enum
Color
{
White
,
Black
}
Color
color
;
private
Position
position
;
double
strength
;
private
Position
position
;
MoveStrategy
moveStrategy
;
char
representation
;
Piece
()
{}
public
void
setPosition
(
Position
position
)
{
this
.
position
=
position
;
@Override
public
int
compareTo
(
@NonNull
Piece
that
)
{
if
(
this
.
getStrength
()
>
that
.
getStrength
())
return
-
1
;
if
(
this
.
getStrength
()
<
that
.
getStrength
())
return
1
;
return
0
;
}
public
char
getRepresentation
()
{
if
(
isBlack
())
return
Character
.
toUpperCase
(
representation
);
return
representation
;
public
void
setPosition
(
Position
position
)
{
this
.
position
=
position
;
}
public
void
setStrength
(
List
<
Piece
>
pieces
)
{}
...
...
@@ -41,39 +44,37 @@ public abstract class Piece implements Comparable<Piece> {
this
.
strength
=
strength
;
}
@Override
public
int
compareTo
(
@NonNull
Piece
that
)
{
if
(
this
.
getStrength
()
>
that
.
getStrength
())
return
-
1
;
if
(
this
.
getStrength
()
<
that
.
getStrength
())
return
1
;
return
0
;
}
public
boolean
isMovable
(
Position
from
,
Position
to
){
return
moveStrategy
.
isMovable
(
from
,
to
);
public
char
getRepresentation
()
{
if
(
isBlack
())
return
Character
.
toUpperCase
(
representation
);
return
representation
;
}
public
double
getStrength
()
{
return
this
.
strength
;
return
strength
;
}
public
Color
getColor
()
{
return
color
;
}
public
Position
getPosition
()
{
return
position
;
}
boolean
isColor
(
Color
color
)
{
return
this
.
color
==
color
;
}
public
boolean
isWhite
()
{
return
isColor
(
Color
.
White
)
;
return
this
.
color
==
Color
.
White
;
}
public
boolean
isBlack
()
{
return
isColor
(
Color
.
Black
)
;
return
this
.
color
==
Color
.
Black
;
}
public
boolean
isAtPosition
(
Position
position
)
{
return
this
.
position
.
equals
(
position
);
}
public
boolean
isMovable
(
Position
from
,
Position
to
){
return
moveStrategy
.
isMovable
(
from
,
to
);
}
}
\ No newline at end of file
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