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
2af1b9c5
authored
May 31, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
6.1 complete
parent
502537f3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
36 deletions
app/src/main/java/com/example/paktalin/agilejava_exercises/Board.java
app/src/main/java/com/example/paktalin/agilejava_exercises/Piece.java
app/src/main/java/com/example/paktalin/agilejava_exercises/Board.java
View file @
2af1b9c5
...
...
@@ -31,9 +31,11 @@ class Board {
void
placePiece
(
Piece
piece
,
String
position
)
{
layout
.
placePiece
(
piece
,
position
);
}
Piece
getPieceAtPosition
(
String
position
)
{
return
layout
.
getPieceAtPosition
(
position
);
}
String
print
()
{
return
layout
.
print
();
}
...
...
@@ -41,6 +43,7 @@ class Board {
void
addToCollection
(
Piece
piece
)
{
getSide
(
piece
.
getColor
()).
addPiece
(
piece
);
}
private
Side
getSide
(
Piece
.
Color
color
){
if
(
color
==
White
)
return
whiteSide
;
...
...
app/src/main/java/com/example/paktalin/agilejava_exercises/Piece.java
View file @
2af1b9c5
...
...
@@ -23,45 +23,38 @@ public class Piece implements Comparable<Piece>{
this
.
type
=
type
;
}
public
Color
getColor
()
{
return
color
;
}
Type
getType
()
{
return
type
;
}
char
getRepresentation
()
{
char
representation
=
0
;
if
(
type
==
Type
.
King
)
representation
=
'k'
;
if
(
type
==
Type
.
Queen
)
representation
=
'q'
;
if
(
type
==
Type
.
Pawn
)
representation
=
'p'
;
if
(
type
==
Type
.
Rook
)
representation
=
'r'
;
if
(
type
==
Type
.
Bishop
)
representation
=
'b'
;
if
(
type
==
Type
.
Knight
)
representation
=
'n'
;
char
representation
=
getRepresentationLetter
();
if
(
this
.
isBlack
())
return
Character
.
toUpperCase
(
representation
);
return
representation
;
}
private
char
getRepresentationLetter
()
{
switch
(
this
.
type
)
{
case
Knight:
return
'n'
;
case
King:
return
'k'
;
case
Queen:
return
'q'
;
case
Rook:
return
'r'
;
case
Bishop:
return
'b'
;
default
:
return
'p'
;
}
}
void
setStrength
(
double
strength
)
{
this
.
strength
=
strength
;
}
void
setStrength
()
{
if
(
type
==
Type
.
Queen
)
strength
=
9
;
if
(
type
==
Type
.
Rook
)
strength
=
5
;
if
(
type
==
Type
.
Bishop
)
strength
=
3
;
if
(
type
==
Type
.
Knight
)
strength
=
2.5
;
if
(
type
==
Type
.
King
)
strength
=
0.0
;
strength
=
calculateStrength
();
}
private
double
calculateStrength
()
{
switch
(
this
.
type
)
{
case
Queen:
return
9
;
case
Rook:
return
5
;
case
Bishop:
return
3
;
case
Knight:
return
2.5
;
default
:
return
0
;
}
}
@Override
...
...
@@ -73,13 +66,15 @@ public class Piece implements Comparable<Piece>{
return
0
;
}
void
setStrength
(
double
strength
)
{
this
.
strength
=
strength
;
}
double
getStrength
()
{
return
strength
;
}
public
Color
getColor
()
{
return
color
;
}
Type
getType
()
{
return
type
;
}
boolean
isColor
(
Color
color
)
{
return
this
.
color
==
color
;
...
...
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