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
6 years ago
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More refactoring in Position class: introduced Coordinate and inheriting classes
parent
a5d90626
master
Show 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
;
package
com
.
paktalin
.
chess
;
import
com.paktalin.chess.coordinates.Column
;
import
com.paktalin.chess.coordinates.*
;
import
com.paktalin.chess.coordinates.Row
;
/**
/**
* Created by Paktalin on 31/05/2018.
* Created by Paktalin on 31/05/2018.
...
@@ -9,8 +8,7 @@ import com.paktalin.chess.coordinates.Row;
...
@@ -9,8 +8,7 @@ import com.paktalin.chess.coordinates.Row;
public
class
Position
{
public
class
Position
{
private
Column
column
;
private
Coordinate
column
,
row
;
private
Row
row
;
private
Position
(
Row
row
,
Column
column
)
{
private
Position
(
Row
row
,
Column
column
)
{
this
.
row
=
row
;
this
.
row
=
row
;
...
@@ -19,7 +17,7 @@ public class Position {
...
@@ -19,7 +17,7 @@ public class Position {
public
static
Position
create
(
String
positionString
)
{
public
static
Position
create
(
String
positionString
)
{
char
column
=
positionString
.
charAt
(
0
);
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
));
return
new
Position
(
new
Row
(
row
),
new
Column
(
column
));
}
}
...
@@ -36,6 +34,10 @@ public class Position {
...
@@ -36,6 +34,10 @@ public class Position {
return
row
.
getIntCode
();
return
row
.
getIntCode
();
}
}
char
getCharRow
()
{
return
row
.
getCharCode
();
}
public
char
getColumn
()
{
public
char
getColumn
()
{
return
column
.
getCharCode
();
return
column
.
getCharCode
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/coordinates/Column.java
View file @
450db60e
package
com
.
paktalin
.
chess
.
coordinates
;
package
com
.
paktalin
.
chess
.
coordinates
;
public
class
Column
extends
Row
{
public
class
Column
extends
Coordinate
{
private
char
charCode
;
public
Column
(
int
intCode
)
{
public
Column
(
int
intCode
)
{
super
(
intCode
);
super
(
intCode
);
this
.
charCode
=
generateCharCodeFromInt
(
intCode
);
}
}
public
Column
(
char
charCode
)
{
public
Column
(
char
charCode
)
{
super
();
super
(
charCode
);
this
.
charCode
=
charCode
;
this
.
intCode
=
generateIntCodeFromChar
(
charCode
);
}
}
private
int
generateIntCodeFromChar
(
char
c
)
{
@Override
int
generateIntCode
(
char
charCode
)
{
char
firstColumnLetter
=
'a'
;
char
firstColumnLetter
=
'a'
;
return
(
int
)
c
-
(
int
)
firstColumnLetter
;
return
(
int
)
c
harCode
-
(
int
)
firstColumnLetter
;
}
}
private
char
generateCharCodeFromInt
(
int
i
)
{
@Override
return
(
char
)(
i
+
'a'
);
char
generateCharCode
(
int
intCode
)
{
}
return
(
char
)(
intCode
+
'a'
);
public
char
getCharCode
()
{
return
charCode
;
}
}
}
}
This diff is collapsed.
Click to expand it.
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
;
}
}
This diff is collapsed.
Click to expand it.
src/main/com/paktalin/chess/coordinates/Row.java
View file @
450db60e
package
com
.
paktalin
.
chess
.
coordinates
;
package
com
.
paktalin
.
chess
.
coordinates
;
public
class
Row
{
public
class
Row
extends
Coordinate
{
int
intCode
;
public
Row
(
int
intCode
)
{
super
(
intCode
);
}
Row
()
{}
public
Row
(
char
charCode
)
{
super
(
charCode
);
}
public
Row
(
int
intCode
)
{
@Override
this
.
intCode
=
intCode
;
int
generateIntCode
(
char
charCode
)
{
return
Character
.
getNumericValue
(
charCode
)
-
1
;
}
}
public
int
getIntCode
()
{
@Override
return
intCode
;
char
generateCharCode
(
int
intCode
)
{
return
(
char
)
(
'1'
+
intCode
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/test/com/paktalin/chess/PositionTest.java
View file @
450db60e
...
@@ -3,6 +3,7 @@ package com.paktalin.chess;
...
@@ -3,6 +3,7 @@ package com.paktalin.chess;
import
com.paktalin.chess.pieces.Bishop
;
import
com.paktalin.chess.pieces.Bishop
;
import
com.paktalin.chess.pieces.Pawn
;
import
com.paktalin.chess.pieces.Pawn
;
import
com.paktalin.chess.pieces.Piece
;
import
com.paktalin.chess.pieces.Piece
;
import
javafx.geometry.Pos
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
...
@@ -41,4 +42,34 @@ class PositionTest {
...
@@ -41,4 +42,34 @@ class PositionTest {
piece
=
board
.
getPieceAtPosition
(
position
);
piece
=
board
.
getPieceAtPosition
(
position
);
assertEquals
(
strength
,
piece
.
getStrength
());
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
()
{
}
}
}
This diff is collapsed.
Click to expand it.
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
This diff is collapsed.
Click to expand it.
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
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