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
Hide 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;
...
@@ -9,15 +9,13 @@ import java.util.List;
*/
*/
public
class
Piece
implements
Comparable
<
Piece
>{
public
class
Piece
implements
Comparable
<
Piece
>{
public
enum
Type
{
Pawn
,
Knight
,
Rook
,
Bishop
,
Queen
,
King
}
public
enum
Color
{
White
,
Black
}
public
enum
Color
{
White
,
Black
}
private
Type
type
;
private
Type
type
;
private
Color
color
;
private
Color
color
;
private
double
strength
;
private
double
strength
;
Position
position
;
private
Position
position
;
private
Piece
()
{}
private
Piece
()
{}
...
@@ -26,12 +24,29 @@ public class Piece implements Comparable<Piece>{
...
@@ -26,12 +24,29 @@ public class Piece implements Comparable<Piece>{
this
.
type
=
type
;
this
.
type
=
type
;
}
}
void
setPosition
(
Position
position
)
{
public
enum
Type
{
this
.
position
=
position
;
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
(
)
{
void
setPosition
(
Position
position
)
{
return
position
.
toString
()
;
this
.
position
=
position
;
}
}
Position
getPosition
()
{
Position
getPosition
()
{
...
@@ -39,45 +54,20 @@ public class Piece implements Comparable<Piece>{
...
@@ -39,45 +54,20 @@ public class Piece implements Comparable<Piece>{
}
}
char
getRepresentation
()
{
char
getRepresentation
()
{
char
representation
=
getRepresentationLetter
();
char
representation
=
this
.
type
.
getRepresentation
();
if
(
this
.
isBlack
())
if
(
this
.
isBlack
())
return
Character
.
toUpperCase
(
representation
);
return
Character
.
toUpperCase
(
representation
);
return
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
)
{
void
setStrength
(
double
strength
)
{
this
.
strength
=
strength
;
this
.
strength
=
strength
;
}
}
void
setStrength
(
List
<
Piece
>
pieces
)
{
void
setStrength
(
List
<
Piece
>
pieces
)
{
switch
(
this
.
type
)
{
if
(
this
.
type
!=
Type
.
Pawn
)
case
Queen:
strength
=
this
.
type
.
getStrength
();
strength
=
9
;
else
Position
.
setPawnStrength
(
this
,
pieces
);
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
);
}
}
}
@Override
@Override
...
...
app/src/main/java/com/example/paktalin/agilejava_exercises/Position.java
View file @
a86e112e
...
@@ -11,9 +11,9 @@ class Position {
...
@@ -11,9 +11,9 @@ class Position {
private
int
row
;
private
int
row
;
private
char
column
;
private
char
column
;
Position
()
{}
private
Position
()
{}
Position
(
int
row
,
char
column
)
{
private
Position
(
int
row
,
char
column
)
{
this
.
row
=
row
;
this
.
row
=
row
;
this
.
column
=
column
;
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;
...
@@ -11,22 +11,22 @@ import java.util.List;
class
Side
{
class
Side
{
private
List
<
Piece
>
pieces
=
new
ArrayList
<>();
private
List
<
Piece
>
pieces
=
new
ArrayList
<>();
public
List
<
Piece
>
getPieces
()
{
List
<
Piece
>
getPieces
()
{
return
pieces
;
return
pieces
;
}
}
public
double
getStrength
()
{
double
getStrength
()
{
double
strength
=
0.0
;
double
strength
=
0.0
;
for
(
Piece
piece
:
pieces
)
for
(
Piece
piece
:
pieces
)
strength
+=
piece
.
getStrength
();
strength
+=
piece
.
getStrength
();
return
strength
;
return
strength
;
}
}
public
int
getPiecesCount
()
{
int
getPiecesCount
()
{
return
pieces
.
size
();
return
pieces
.
size
();
}
}
public
int
getPiecesCount
(
Piece
.
Type
type
)
{
int
getPiecesCount
(
Piece
.
Type
type
)
{
int
count
=
0
;
int
count
=
0
;
for
(
Piece
piece
:
pieces
)
for
(
Piece
piece
:
pieces
)
...
@@ -36,7 +36,7 @@ class Side {
...
@@ -36,7 +36,7 @@ class Side {
return
count
;
return
count
;
}
}
public
void
addPiece
(
Piece
piece
)
{
void
addPiece
(
Piece
piece
)
{
pieces
.
add
(
piece
);
pieces
.
add
(
piece
);
Collections
.
sort
(
pieces
);
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