Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
agile-java
/
Chess
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
450db60e
authored
Feb 26, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More refactoring in Position class: introduced Coordinate and inheriting classes
parent
a5d90626
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
133 additions
and
26 deletions
src/main/com/paktalin/chess/Position.java
src/main/com/paktalin/chess/coordinates/Column.java
src/main/com/paktalin/chess/coordinates/Coordinate.java
src/main/com/paktalin/chess/coordinates/Row.java
src/test/com/paktalin/chess/PositionTest.java
src/test/com/paktalin/chess/coordinates/ColumnTest.java
src/test/com/paktalin/chess/coordinates/RowTest.java
src/main/com/paktalin/chess/Position.java
View file @
450db60e
package
com
.
paktalin
.
chess
;
import
com.paktalin.chess.coordinates.Column
;
import
com.paktalin.chess.coordinates.Row
;
import
com.paktalin.chess.coordinates.*
;
/**
* Created by Paktalin on 31/05/2018.
...
...
@@ -9,8 +8,7 @@ import com.paktalin.chess.coordinates.Row;
public
class
Position
{
private
Column
column
;
private
Row
row
;
private
Coordinate
column
,
row
;
private
Position
(
Row
row
,
Column
column
)
{
this
.
row
=
row
;
...
...
@@ -19,7 +17,7 @@ public class Position {
public
static
Position
create
(
String
positionString
)
{
char
column
=
positionString
.
charAt
(
0
);
int
row
=
Character
.
getNumericValue
(
positionString
.
charAt
(
1
))
-
1
;
char
row
=
positionString
.
charAt
(
1
)
;
return
new
Position
(
new
Row
(
row
),
new
Column
(
column
));
}
...
...
@@ -36,6 +34,10 @@ public class Position {
return
row
.
getIntCode
();
}
char
getCharRow
()
{
return
row
.
getCharCode
();
}
public
char
getColumn
()
{
return
column
.
getCharCode
();
}
...
...
src/main/com/paktalin/chess/coordinates/Column.java
View file @
450db60e
package
com
.
paktalin
.
chess
.
coordinates
;
public
class
Column
extends
Row
{
private
char
charCode
;
public
class
Column
extends
Coordinate
{
public
Column
(
int
intCode
)
{
super
(
intCode
);
this
.
charCode
=
generateCharCodeFromInt
(
intCode
);
}
public
Column
(
char
charCode
)
{
super
();
this
.
charCode
=
charCode
;
this
.
intCode
=
generateIntCodeFromChar
(
charCode
);
super
(
charCode
);
}
private
int
generateIntCodeFromChar
(
char
c
)
{
@Override
int
generateIntCode
(
char
charCode
)
{
char
firstColumnLetter
=
'a'
;
return
(
int
)
c
-
(
int
)
firstColumnLetter
;
return
(
int
)
c
harCode
-
(
int
)
firstColumnLetter
;
}
private
char
generateCharCodeFromInt
(
int
i
)
{
return
(
char
)(
i
+
'a'
);
}
public
char
getCharCode
()
{
return
charCode
;
@Override
char
generateCharCode
(
int
intCode
)
{
return
(
char
)(
intCode
+
'a'
);
}
}
src/main/com/paktalin/chess/coordinates/Coordinate.java
0 → 100644
View file @
450db60e
package
com
.
paktalin
.
chess
.
coordinates
;
public
abstract
class
Coordinate
{
private
char
charCode
;
private
int
intCode
;
Coordinate
(
int
intCode
)
{
this
.
intCode
=
intCode
;
this
.
charCode
=
generateCharCode
(
intCode
);
}
Coordinate
(
char
charCode
)
{
this
.
charCode
=
charCode
;
this
.
intCode
=
generateIntCode
(
charCode
);
}
abstract
int
generateIntCode
(
char
charCode
);
abstract
char
generateCharCode
(
int
intCode
);
public
char
getCharCode
()
{
return
charCode
;
}
public
int
getIntCode
()
{
return
intCode
;
}
}
src/main/com/paktalin/chess/coordinates/Row.java
View file @
450db60e
package
com
.
paktalin
.
chess
.
coordinates
;
public
class
Row
{
int
intCode
;
public
class
Row
extends
Coordinate
{
public
Row
(
int
intCode
)
{
super
(
intCode
);
}
Row
()
{}
public
Row
(
char
charCode
)
{
super
(
charCode
);
}
public
Row
(
int
intCode
)
{
this
.
intCode
=
intCode
;
@Override
int
generateIntCode
(
char
charCode
)
{
return
Character
.
getNumericValue
(
charCode
)
-
1
;
}
public
int
getIntCode
()
{
return
intCode
;
@Override
char
generateCharCode
(
int
intCode
)
{
return
(
char
)
(
'1'
+
intCode
);
}
}
src/test/com/paktalin/chess/PositionTest.java
View file @
450db60e
...
...
@@ -3,6 +3,7 @@ package com.paktalin.chess;
import
com.paktalin.chess.pieces.Bishop
;
import
com.paktalin.chess.pieces.Pawn
;
import
com.paktalin.chess.pieces.Piece
;
import
javafx.geometry.Pos
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -41,4 +42,34 @@ class PositionTest {
piece
=
board
.
getPieceAtPosition
(
position
);
assertEquals
(
strength
,
piece
.
getStrength
());
}
@Test
void
create
()
{
Position
position
=
Position
.
create
(
"b4"
);
assertEquals
(
'b'
,
position
.
getColumn
());
assertEquals
(
1
,
position
.
getIntColumn
());
assertEquals
(
'4'
,
position
.
getCharRow
());
assertEquals
(
3
,
position
.
getRow
());
}
// TODO: 2/26/2019 finish the test methods
@Test
void
create1
()
{
}
@Test
void
toStringTest
()
{
}
@Test
void
getRow
()
{
}
@Test
void
getColumn
()
{
}
@Test
void
getIntColumn
()
{
}
}
src/test/com/paktalin/chess/coordinates/ColumnTest.java
0 → 100644
View file @
450db60e
package
com
.
paktalin
.
chess
.
coordinates
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
class
ColumnTest
{
private
Column
column
;
@Test
void
generateIntCode
()
{
column
=
new
Column
(
'd'
);
assertEquals
(
3
,
column
.
getIntCode
());
}
@Test
void
generateCharCode
()
{
column
=
new
Column
(
2
);
assertEquals
(
'c'
,
column
.
getCharCode
());
}
}
\ No newline at end of file
src/test/com/paktalin/chess/coordinates/RowTest.java
0 → 100644
View file @
450db60e
package
com
.
paktalin
.
chess
.
coordinates
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
class
RowTest
{
private
Row
row
;
@Test
void
generateIntCode
()
{
row
=
new
Row
(
'2'
);
assertEquals
(
1
,
row
.
getIntCode
());
}
@Test
void
generateCharCode
()
{
row
=
new
Row
(
3
);
assertEquals
(
'4'
,
row
.
getCharCode
());
}
}
\ No newline at end of file
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