replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
- Some of the terminology you're using is unusual. I would say
Piece
orMan
instead ofFigure
, and "castling" instead of "Rochade".GetValidTurns
should probably be calledGetValidMoves
. - As Eric Lippert suggests on your other question your other question, you should probably create a struct called
BoardPosition
which contains a row and a column asint
s. - The code for
BoardPosition
should contain comments indicating how the ranks and files are numbered. Maybe the constructor should check that the given numbers are in range. - It would be useful for
BoardPosition
to have a methodpublic BoardPosition Move(int right, int up)
which returns a newBoardPosition
with the coordinates altered appropriately. - If you wanted, you could make
GetValidTurns
onQueenPiece
just a single line:return GetRookMoves().Concat(GetBishopMoves()).ToList();
- The methods
GetValidTurns
onRookPiece
andGetRookMoves
onQueenPiece
are very similar. Consider replacing these two methods with a singleGetRookMoves
method. You might have this method as a protected method in theFigure
class, or perhaps as a static method in a new static class, called something likeChessMoves
or (Eric's suggestion)Rulebook
. - In
GetRookMoves
, the while-loops forrightMove
,topMove
,leftMove
, anddownMove
are all very similar. See if you can combine these four pieces of code into one. - I find the method call
WillCollideWithEnemy(rightMove, PieceColor).Item1
to be confusing. Given the nameWillCollideWithEnemy
, I would expect that method to return abool
, but abool
doesn't have anItem1
. Consider doing the following instead: - Create a method
public Figure GetEnemyAt(boardPosition, pieceColor)
, which returnsnull
if the square atboardPosition
is empty or contains an allied piece. - Create a separate method
public bool ContainsEnemy(boardPosition, pieceColor)
, which merely checks if the square contains an enemy or not and returnstrue
orfalse
. (This method could be implemented as a one-liner:return (GetEnemyAt(boardPosition, pieceColor) != null);
.) - For the while-loops in
GetRookMoves
, the logic seems a little more complicated than necessary. - The
startingMoves
variable isn't necessary. Remove it, and initializevalidMoves
as the empty list. - The implementation of the while-loops could be something like the following:
- Some of the terminology you're using is unusual. I would say
Piece
orMan
instead ofFigure
, and "castling" instead of "Rochade".GetValidTurns
should probably be calledGetValidMoves
. - As Eric Lippert suggests on your other question, you should probably create a struct called
BoardPosition
which contains a row and a column asint
s. - The code for
BoardPosition
should contain comments indicating how the ranks and files are numbered. Maybe the constructor should check that the given numbers are in range. - It would be useful for
BoardPosition
to have a methodpublic BoardPosition Move(int right, int up)
which returns a newBoardPosition
with the coordinates altered appropriately. - If you wanted, you could make
GetValidTurns
onQueenPiece
just a single line:return GetRookMoves().Concat(GetBishopMoves()).ToList();
- The methods
GetValidTurns
onRookPiece
andGetRookMoves
onQueenPiece
are very similar. Consider replacing these two methods with a singleGetRookMoves
method. You might have this method as a protected method in theFigure
class, or perhaps as a static method in a new static class, called something likeChessMoves
or (Eric's suggestion)Rulebook
. - In
GetRookMoves
, the while-loops forrightMove
,topMove
,leftMove
, anddownMove
are all very similar. See if you can combine these four pieces of code into one. - I find the method call
WillCollideWithEnemy(rightMove, PieceColor).Item1
to be confusing. Given the nameWillCollideWithEnemy
, I would expect that method to return abool
, but abool
doesn't have anItem1
. Consider doing the following instead: - Create a method
public Figure GetEnemyAt(boardPosition, pieceColor)
, which returnsnull
if the square atboardPosition
is empty or contains an allied piece. - Create a separate method
public bool ContainsEnemy(boardPosition, pieceColor)
, which merely checks if the square contains an enemy or not and returnstrue
orfalse
. (This method could be implemented as a one-liner:return (GetEnemyAt(boardPosition, pieceColor) != null);
.) - For the while-loops in
GetRookMoves
, the logic seems a little more complicated than necessary. - The
startingMoves
variable isn't necessary. Remove it, and initializevalidMoves
as the empty list. - The implementation of the while-loops could be something like the following:
- Some of the terminology you're using is unusual. I would say
Piece
orMan
instead ofFigure
, and "castling" instead of "Rochade".GetValidTurns
should probably be calledGetValidMoves
. - As Eric Lippert suggests on your other question, you should probably create a struct called
BoardPosition
which contains a row and a column asint
s. - The code for
BoardPosition
should contain comments indicating how the ranks and files are numbered. Maybe the constructor should check that the given numbers are in range. - It would be useful for
BoardPosition
to have a methodpublic BoardPosition Move(int right, int up)
which returns a newBoardPosition
with the coordinates altered appropriately. - If you wanted, you could make
GetValidTurns
onQueenPiece
just a single line:return GetRookMoves().Concat(GetBishopMoves()).ToList();
- The methods
GetValidTurns
onRookPiece
andGetRookMoves
onQueenPiece
are very similar. Consider replacing these two methods with a singleGetRookMoves
method. You might have this method as a protected method in theFigure
class, or perhaps as a static method in a new static class, called something likeChessMoves
or (Eric's suggestion)Rulebook
. - In
GetRookMoves
, the while-loops forrightMove
,topMove
,leftMove
, anddownMove
are all very similar. See if you can combine these four pieces of code into one. - I find the method call
WillCollideWithEnemy(rightMove, PieceColor).Item1
to be confusing. Given the nameWillCollideWithEnemy
, I would expect that method to return abool
, but abool
doesn't have anItem1
. Consider doing the following instead: - Create a method
public Figure GetEnemyAt(boardPosition, pieceColor)
, which returnsnull
if the square atboardPosition
is empty or contains an allied piece. - Create a separate method
public bool ContainsEnemy(boardPosition, pieceColor)
, which merely checks if the square contains an enemy or not and returnstrue
orfalse
. (This method could be implemented as a one-liner:return (GetEnemyAt(boardPosition, pieceColor) != null);
.) - For the while-loops in
GetRookMoves
, the logic seems a little more complicated than necessary. - The
startingMoves
variable isn't necessary. Remove it, and initializevalidMoves
as the empty list. - The implementation of the while-loops could be something like the following:
- Some of the terminology you're using is unusual. I would say
Piece
orMan
instead ofFigure
, and "castling" instead of "Rochade".GetValidTurns
should probably be calledGetValidMoves
. - As Eric Lippert suggests on your other question, you should probably create a struct called
BoardPosition
which contains a row and a column asint
s. - The code for
BoardPosition
should contain comments indicating how the ranks and files are numbered. Maybe the constructor should check that the given numbers are in range. - It would be useful for
BoardPosition
to have a methodpublic BoardPosition Move(int right, int up)
which returns a newBoardPosition
with the coordinates altered appropriately. - If you wanted, you could make
GetValidTurns
onQueenPiece
just a single line:return GetRookMoves().Concat(GetBishopMoves()).ToList();
- The methods
GetValidTurns
onRookPiece
andGetRookMoves
onQueenPiece
are very similar. Consider replacing these two methods with a singleGetRookMoves
method. You might have this method as a protected method in theFigure
class, or perhaps as a static method in a new static class, called something likeChessMoves
or (Eric's suggestion)Rulebook
. - In
GetRookMoves
, the while-loops forrightMove
,topMove
,leftMove
, anddownMove
are all very similar. See if you can combine these four pieces of code into one. - I find the method call
WillCollideWithEnemy(rightMove, PieceColor).Item1
to be confusing. Given the nameWillCollideWithEnemy
, I would expect that method to return abool
, but abool
doesn't have anItem1
. Consider doing the following instead: - Create a method
public Figure GetEnemyAt(boardPosition, pieceColor)
, which returnsnull
if the square atboardPosition
is empty or contains an allied piece. - Create a separate method
public bool ContainsEnemy(boardPosition, pieceColor)
, which merely checks if the square contains an enemy or not and returnstrue
orfalse
. (This method could be implemented as a one-liner:return (GetEnemyAt(boardPosition, pieceColor) != null);
.) - For the while-loops in
GetRookMoves
, the logic seems a little more complicated than necessary. - The
startingMoves
variable isn't necessary. Remove it, and initializevalidMoves
as the empty list. - The implementation of the while-loops could be something like the following:
—
BoardPosition destination = CurrentPosition;
while(true)
{
destination = destination.Move(right: 1, up: 0);
if (IsOutOfBounds(destination) || WillCollideWithAlly(destination, PieceColor))
{
break;
}
validMoves.Add(destination);
if (ContainsEnemy(destination, PieceColor))
{
break;
}
}
- Consider making all of the members of
ImagePaths
const
instead ofstatic
. You should be able to use definitions such aspublic const string BlackPawnImagePath = assetsPath + @"Black\b-peshka.png";
. (MakingImagePaths
a static class was a good idea.) - Consider making
Rochade
a static class and turning all of its non-constant properties (includingnewKingMove
) into parameters and/or local variables of the methods. - In the
PassedTurns
class, shouldn'tActions
,Positions
, andPieceTypes
all be lists?
lang-cs