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
611a32a1
authored
May 26, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lesson 5 Exercise 7 complete
parent
59a9a544
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
16 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/test/java/com/example/paktalin/agilejava_exercises/BoardTest.java
app/src/main/java/com/example/paktalin/agilejava_exercises/Board.java
View file @
611a32a1
...
...
@@ -118,11 +118,12 @@ class Board {
double
getStrength
(
Piece
.
Color
color
)
{
double
strength
=
0
;
for
(
int
i
=
0
;
i
<
ROW_COUNT
;
i
++)
{
for
(
int
j
=
0
;
j
<
COLUMN_COUNT
;
j
++)
{
Piece
piece
=
getPieceAtPosition
(
i
,
j
);
for
(
int
row
=
0
;
row
<
ROW_COUNT
;
row
++)
{
for
(
int
column
=
0
;
column
<
COLUMN_COUNT
;
column
++)
{
Piece
piece
=
getPieceAtPosition
(
row
,
column
);
if
(
piece
!=
null
&&
piece
.
getColor
()
==
color
)
strength
+=
piece
.
getStrength
();
strength
+=
piece
.
getStrength
(
this
,
column
,
color
);
}
}
return
strength
;
...
...
@@ -134,4 +135,15 @@ class Board {
double
getWhiteStrength
()
{
return
getStrength
(
Piece
.
Color
.
White
);
}
int
getPawnsPerColumn
(
int
column
,
Piece
.
Color
color
)
{
int
count
=
0
;
for
(
int
row
=
0
;
row
<
ROW_COUNT
;
row
++)
{
Piece
currentPiece
=
getPieceAtPosition
(
row
,
column
);
if
(
currentPiece
!=
null
)
if
(
currentPiece
.
isType
(
Piece
.
Type
.
Pawn
)
&&
currentPiece
.
isColor
(
color
))
count
++;
}
return
count
;
}
}
\ No newline at end of file
app/src/main/java/com/example/paktalin/agilejava_exercises/Piece.java
View file @
611a32a1
...
...
@@ -46,7 +46,7 @@ public class Piece {
return
representation
;
}
double
getStrength
()
{
double
getStrength
(
Board
board
,
int
column
,
Color
color
)
{
if
(
type
==
Type
.
Queen
)
return
9
;
if
(
type
==
Type
.
Rook
)
...
...
@@ -55,16 +55,23 @@ public class Piece {
return
3
;
if
(
type
==
Type
.
Knight
)
return
2.5
;
if
(
type
==
Type
.
Pawn
)
if
(
type
==
Type
.
Pawn
)
{
if
(
board
.
getPawnsPerColumn
(
column
,
color
)
>
1
)
return
0.5
;
return
1.0
;
}
return
0
;
}
boolean
isColor
(
Color
color
)
{
return
this
.
color
==
color
;
}
boolean
isWhite
()
{
return
this
.
color
==
Color
.
White
;
return
isColor
(
Color
.
White
)
;
}
boolean
isBlack
()
{
return
this
.
color
==
Color
.
Black
;
return
isColor
(
Color
.
Black
)
;
}
boolean
isType
(
Piece
.
Type
type
)
{
return
this
.
getType
()
==
type
;
...
...
app/src/test/java/com/example/paktalin/agilejava_exercises/BoardTest.java
View file @
611a32a1
...
...
@@ -71,18 +71,18 @@ public class BoardTest extends TestCase {
verifyStrength
(
Piece
.
createRook
(
White
),
"e1"
,
14.0
,
14.0
);
verifyStrength
(
Piece
.
createPawn
(
Black
),
"a7"
,
15.0
,
14.0
);
verifyStrength
(
Piece
.
createPawn
(
White
),
"f2"
,
15.0
,
1
4.5
);
verifyStrength
(
Piece
.
createPawn
(
White
),
"f2"
,
15.0
,
1
5.0
);
verifyStrength
(
Piece
.
createPawn
(
Black
),
"c7"
,
16.0
,
1
4.5
);
verifyStrength
(
Piece
.
createPawn
(
White
),
"g2"
,
16.0
,
1
5
.0
);
verifyStrength
(
Piece
.
createPawn
(
Black
),
"c7"
,
16.0
,
1
5.0
);
verifyStrength
(
Piece
.
createPawn
(
White
),
"g2"
,
16.0
,
1
6
.0
);
verifyStrength
(
Piece
.
createBishop
(
Black
),
"d7"
,
19.0
,
1
5
.0
);
verifyStrength
(
Piece
.
createPawn
(
White
),
"f3"
,
19.0
,
1
5.5
);
verifyStrength
(
Piece
.
createBishop
(
Black
),
"d7"
,
19.0
,
1
6
.0
);
verifyStrength
(
Piece
.
createPawn
(
White
),
"f3"
,
19.0
,
1
6.0
);
verifyStrength
(
Piece
.
createPawn
(
Black
),
"b6"
,
20.0
,
1
5.5
);
verifyStrength
(
Piece
.
createPawn
(
White
),
"h3"
,
18.5
,
16
.0
);
verifyStrength
(
Piece
.
createPawn
(
Black
),
"b6"
,
20.0
,
1
6.0
);
verifyStrength
(
Piece
.
createPawn
(
White
),
"h3"
,
20.0
,
17
.0
);
verifyStrength
(
Piece
.
createKnight
(
White
),
"f4"
,
18.5
,
18
.5
);
verifyStrength
(
Piece
.
createKnight
(
White
),
"f4"
,
20.0
,
19
.5
);
assertEquals
(
".KR..... 8\n"
+
...
...
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