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
a00c86ad
authored
6 years ago
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lesson 5 in progress
parent
445de99b
master
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
71 deletions
app/proguard-rules.pro
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/test/java/com/example/paktalin/agilejava_exercises/PieceTest.java
app/proguard-rules.pro
View file @
a00c86ad
...
...
@@ -6,7 +6,7 @@
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class
nam
e to the JavaScript interface
# and specify the fully qualified class
typ
e to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
...
...
@@ -17,5 +17,5 @@
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file
nam
e.
# hide the original source file
typ
e.
#-renamesourcefileattribute SourceFile
This diff is collapsed.
Click to expand it.
app/src/main/java/com/example/paktalin/agilejava_exercises/Board.java
View file @
a00c86ad
...
...
@@ -15,32 +15,32 @@ class Board {
void
initialize
()
{
fillFirstRank
();
for
(
int
i
=
0
;
i
<
8
;
i
++)
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Nam
e
.
Pawn
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Typ
e
.
Pawn
));
for
(
int
i
=
0
;
i
<
8
;
i
++)
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Nam
e
.
Pawn
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Typ
e
.
Pawn
));
fillEightRank
();
}
private
void
fillFirstRank
()
{
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Nam
e
.
Rook
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Nam
e
.
Knight
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Nam
e
.
Bishop
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Nam
e
.
Queen
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Nam
e
.
King
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Nam
e
.
Bishop
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Nam
e
.
Knight
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Nam
e
.
Rook
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Typ
e
.
Rook
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Typ
e
.
Knight
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Typ
e
.
Bishop
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Typ
e
.
Queen
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Typ
e
.
King
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Typ
e
.
Bishop
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Typ
e
.
Knight
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Typ
e
.
Rook
));
}
private
void
fillEightRank
()
{
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Nam
e
.
Rook
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Nam
e
.
Knight
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Nam
e
.
Bishop
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Nam
e
.
Queen
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Nam
e
.
King
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Nam
e
.
Bishop
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Nam
e
.
Knight
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Nam
e
.
Rook
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Typ
e
.
Rook
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Typ
e
.
Knight
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Typ
e
.
Bishop
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Typ
e
.
Queen
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Typ
e
.
King
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Typ
e
.
Bishop
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Typ
e
.
Knight
));
pieces
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Typ
e
.
Rook
));
}
int
pieceCount
()
{
...
...
@@ -58,7 +58,7 @@ class Board {
String
printRank
(
int
from
)
{
StringBuilder
buffer
=
new
StringBuilder
();
for
(
int
i
=
from
;
i
<
from
+
8
;
i
++)
buffer
.
append
(
pieces
.
get
(
i
).
print
());
buffer
.
append
(
pieces
.
get
(
i
).
getRepresentation
());
return
buffer
.
toString
();
}
...
...
@@ -76,4 +76,12 @@ class Board {
return
buffer
.
toString
();
}
int
getCount
(
Piece
.
Type
type
,
Piece
.
Color
color
)
{
int
count
=
0
;
for
(
Piece
piece
:
pieces
)
if
(
piece
.
getType
()
==
type
&&
piece
.
getColor
()
==
color
)
count
++;
return
count
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/src/main/java/com/example/paktalin/agilejava_exercises/Piece.java
View file @
a00c86ad
...
...
@@ -5,53 +5,45 @@ package com.example.paktalin.agilejava_exercises;
*/
public
class
Piece
{
enum
Nam
e
{
Pawn
,
Knight
,
Rook
,
Bishop
,
Queen
,
King
}
enum
Typ
e
{
Pawn
,
Knight
,
Rook
,
Bishop
,
Queen
,
King
}
enum
Color
{
White
,
Black
}
private
Name
nam
e
;
private
Type
typ
e
;
private
Color
color
;
private
Piece
()
{}
Piece
(
final
Color
color
,
final
Name
nam
e
)
{
Piece
(
final
Color
color
,
final
Type
typ
e
)
{
this
.
color
=
color
;
this
.
name
=
nam
e
;
this
.
type
=
typ
e
;
}
public
Color
getColor
()
{
return
color
;
}
public
Name
getName
()
{
return
name
;
}
String
print
()
{
String
letter
=
""
;
switch
(
name
)
{
case
King:
letter
=
"k"
;
break
;
case
Queen:
letter
=
"q"
;
break
;
case
Pawn:
letter
=
"p"
;
break
;
case
Rook:
letter
=
"r"
;
break
;
case
Bishop:
letter
=
"b"
;
break
;
case
Knight:
letter
=
"n"
;
break
;
}
if
(
color
==
Color
.
Black
)
return
letter
.
toUpperCase
();
return
letter
;
public
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'
;
if
(
this
.
isBlack
())
return
Character
.
toUpperCase
(
representation
);
return
representation
;
}
boolean
isWhite
()
{
...
...
@@ -61,4 +53,46 @@ public class Piece {
boolean
isBlack
()
{
return
this
.
color
==
Color
.
Black
;
}
static
Piece
createWhitePawn
()
{
return
new
Piece
(
Color
.
White
,
Type
.
Pawn
);
}
static
Piece
createBlackPawn
()
{
return
new
Piece
(
Color
.
Black
,
Type
.
Pawn
);
}
static
Piece
createWhiteKing
()
{
return
new
Piece
(
Color
.
White
,
Type
.
King
);
}
static
Piece
createBlackKing
()
{
return
new
Piece
(
Color
.
Black
,
Type
.
King
);
}
static
Piece
createWhiteBishop
()
{
return
new
Piece
(
Color
.
White
,
Type
.
Bishop
);
}
static
Piece
createBlackBishop
()
{
return
new
Piece
(
Color
.
Black
,
Type
.
Bishop
);
}
static
Piece
createWhiteRook
()
{
return
new
Piece
(
Color
.
White
,
Type
.
Rook
);
}
static
Piece
createBlackRook
()
{
return
new
Piece
(
Color
.
Black
,
Type
.
Rook
);
}
static
Piece
createWhiteKnight
()
{
return
new
Piece
(
Color
.
White
,
Type
.
Knight
);
}
static
Piece
createBlackKnight
()
{
return
new
Piece
(
Color
.
Black
,
Type
.
Knight
);
}
static
Piece
createWhiteQueen
()
{
return
new
Piece
(
Color
.
White
,
Type
.
Queen
);
}
static
Piece
createBlackQueen
()
{
return
new
Piece
(
Color
.
Black
,
Type
.
Queen
);
}
}
This diff is collapsed.
Click to expand it.
app/src/test/java/com/example/paktalin/agilejava_exercises/BoardTest.java
View file @
a00c86ad
...
...
@@ -31,4 +31,15 @@ public class BoardTest extends TestCase {
assertEquals
(
16
,
board
.
colorCount
(
Piece
.
Color
.
Black
));
assertEquals
(
16
,
board
.
colorCount
(
Piece
.
Color
.
White
));
}
public
void
testCountPieces
()
{
board
.
initialize
();
assertEquals
(
8
,
board
.
getCount
(
Piece
.
Type
.
Pawn
,
Piece
.
Color
.
White
));
assertEquals
(
1
,
board
.
getCount
(
Piece
.
Type
.
King
,
Piece
.
Color
.
Black
));
assertEquals
(
1
,
board
.
getCount
(
Piece
.
Type
.
Queen
,
Piece
.
Color
.
White
));
assertEquals
(
2
,
board
.
getCount
(
Piece
.
Type
.
Bishop
,
Piece
.
Color
.
Black
));
assertEquals
(
2
,
board
.
getCount
(
Piece
.
Type
.
Knight
,
Piece
.
Color
.
White
));
assertEquals
(
2
,
board
.
getCount
(
Piece
.
Type
.
Rook
,
Piece
.
Color
.
Black
));
}
}
This diff is collapsed.
Click to expand it.
app/src/test/java/com/example/paktalin/agilejava_exercises/PieceTest.java
View file @
a00c86ad
...
...
@@ -8,23 +8,22 @@ import junit.framework.TestCase;
public
class
PieceTest
extends
TestCase
{
private
Piece
blackPawn
,
whitePawn
;
public
void
setUp
()
{
blackPawn
=
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Name
.
Pawn
);
whitePawn
=
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Name
.
Pawn
);
public
void
testCreate
()
{
verifyCreation
(
Piece
.
createWhitePawn
(),
Piece
.
createBlackPawn
(),
Piece
.
Type
.
Pawn
,
'p'
);
verifyCreation
(
Piece
.
createWhiteKing
(),
Piece
.
createBlackKing
(),
Piece
.
Type
.
King
,
'k'
);
verifyCreation
(
Piece
.
createWhiteBishop
(),
Piece
.
createBlackBishop
(),
Piece
.
Type
.
Bishop
,
'b'
);
verifyCreation
(
Piece
.
createWhiteRook
(),
Piece
.
createBlackRook
(),
Piece
.
Type
.
Rook
,
'r'
);
verifyCreation
(
Piece
.
createWhiteKnight
(),
Piece
.
createBlackKnight
(),
Piece
.
Type
.
Knight
,
'n'
);
verifyCreation
(
Piece
.
createWhiteQueen
(),
Piece
.
createBlackQueen
(),
Piece
.
Type
.
Queen
,
'q'
);
}
public
void
testPawnColor
()
{
assertEquals
(
Piece
.
Color
.
White
,
whitePawn
.
getColor
());
assertEquals
(
Piece
.
Color
.
Black
,
blackPawn
.
getColor
());
assertTrue
(
whitePawn
.
isWhite
());
assertFalse
(
blackPawn
.
isWhite
());
}
private
void
verifyCreation
(
Piece
whitePiece
,
Piece
blackPiece
,
Piece
.
Type
type
,
char
representation
)
{
assertTrue
(
whitePiece
.
isWhite
());
assertEquals
(
type
,
whitePiece
.
getType
());
assertEquals
(
representation
,
whitePiece
.
getRepresentation
());
public
void
testPawnRepresentation
()
{
assertEquals
(
"P"
,
blackPawn
.
print
());
assertEquals
(
"p"
,
whitePawn
.
print
());
assertTrue
(
blackPiece
.
isBlack
());
assertEquals
(
type
,
blackPiece
.
getType
());
assertEquals
(
Character
.
toUpperCase
(
representation
),
blackPiece
.
getRepresentation
());
}
}
This diff is collapsed.
Click to expand it.
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