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
a86e112e
authored
May 31, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exercise 6.5 done
parent
d2093f3a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
43 deletions
app/src/main/java/com/example/paktalin/agilejava_exercises/Piece.java
app/src/main/java/com/example/paktalin/agilejava_exercises/Position.java
app/src/main/java/com/example/paktalin/agilejava_exercises/Side.java
app/src/main/java/com/example/paktalin/agilejava_exercises/Piece.java
View file @
a86e112e
...
...
@@ -9,15 +9,13 @@ import java.util.List;
*/
public
class
Piece
implements
Comparable
<
Piece
>{
public
enum
Type
{
Pawn
,
Knight
,
Rook
,
Bishop
,
Queen
,
King
}
public
enum
Color
{
White
,
Black
}
private
Type
type
;
private
Color
color
;
private
double
strength
;
Position
position
;
private
Position
position
;
private
Piece
()
{}
...
...
@@ -26,12 +24,29 @@ public class Piece implements Comparable<Piece>{
this
.
type
=
type
;
}
void
setPosition
(
Position
position
)
{
this
.
position
=
position
;
public
enum
Type
{
Pawn
(
1
,
'p'
),
Knight
(
2.5
,
'n'
),
Rook
(
5
,
'r'
),
Bishop
(
3
,
'b'
),
Queen
(
9
,
'q'
),
King
(
0
,
'k'
);
private
double
strength
;
private
char
representation
;
Type
(
double
strength
,
char
representation
)
{
this
.
strength
=
strength
;
this
.
representation
=
representation
;
}
public
char
getRepresentation
()
{
return
representation
;
}
public
double
getStrength
()
{
return
strength
;
}
}
String
getStringPosition
(
)
{
return
position
.
toString
()
;
void
setPosition
(
Position
position
)
{
this
.
position
=
position
;
}
Position
getPosition
()
{
...
...
@@ -39,45 +54,20 @@ public class Piece implements Comparable<Piece>{
}
char
getRepresentation
()
{
char
representation
=
getRepresentationLetter
();
char
representation
=
this
.
type
.
getRepresentation
();
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
(
List
<
Piece
>
pieces
)
{
switch
(
this
.
type
)
{
case
Queen:
strength
=
9
;
break
;
case
Rook:
strength
=
5
;
break
;
case
Bishop:
strength
=
3
;
break
;
case
Knight:
strength
=
2.5
;
break
;
case
King:
strength
=
0
;
break
;
default
:
Position
.
setPawnStrength
(
this
,
pieces
);
}
if
(
this
.
type
!=
Type
.
Pawn
)
strength
=
this
.
type
.
getStrength
();
else
Position
.
setPawnStrength
(
this
,
pieces
);
}
@Override
...
...
app/src/main/java/com/example/paktalin/agilejava_exercises/Position.java
View file @
a86e112e
...
...
@@ -11,9 +11,9 @@ class Position {
private
int
row
;
private
char
column
;
Position
()
{}
private
Position
()
{}
Position
(
int
row
,
char
column
)
{
private
Position
(
int
row
,
char
column
)
{
this
.
row
=
row
;
this
.
column
=
column
;
}
...
...
app/src/main/java/com/example/paktalin/agilejava_exercises/Side.java
View file @
a86e112e
...
...
@@ -11,22 +11,22 @@ import java.util.List;
class
Side
{
private
List
<
Piece
>
pieces
=
new
ArrayList
<>();
public
List
<
Piece
>
getPieces
()
{
List
<
Piece
>
getPieces
()
{
return
pieces
;
}
public
double
getStrength
()
{
double
getStrength
()
{
double
strength
=
0.0
;
for
(
Piece
piece
:
pieces
)
strength
+=
piece
.
getStrength
();
return
strength
;
}
public
int
getPiecesCount
()
{
int
getPiecesCount
()
{
return
pieces
.
size
();
}
public
int
getPiecesCount
(
Piece
.
Type
type
)
{
int
getPiecesCount
(
Piece
.
Type
type
)
{
int
count
=
0
;
for
(
Piece
piece
:
pieces
)
...
...
@@ -36,7 +36,7 @@ class Side {
return
count
;
}
public
void
addPiece
(
Piece
piece
)
{
void
addPiece
(
Piece
piece
)
{
pieces
.
add
(
piece
);
Collections
.
sort
(
pieces
);
}
...
...
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