Skip to content

Commit

Permalink
ValidateMove -> ValidateDiagonalMove
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyPatten committed Jun 23, 2022
1 parent 8018db3 commit 99c09b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Projects/Checkers/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ public List<Move> GetPossibleMoves(PieceColor color)
public List<Move> GetPossibleMoves(Piece piece)
{
List<Move> moves = new();
ValidateMove(-1, -1);
ValidateMove(-1, 1);
ValidateMove(1, -1);
ValidateMove(1, 1);
ValidateDiagonalMove(-1, -1);
ValidateDiagonalMove(-1, 1);
ValidateDiagonalMove( 1, -1);
ValidateDiagonalMove( 1, 1);
return moves.Any(move => move.PieceToCapture is not null)
? moves.Where(move => move.PieceToCapture is not null).ToList()
: moves;

void ValidateMove(int dx, int dy)
void ValidateDiagonalMove(int dx, int dy)
{
if (!piece.Promoted && piece.Color is Black && dy is -1) return;
if (!piece.Promoted && piece.Color is White && dy is 1) return;
Expand Down
10 changes: 5 additions & 5 deletions Projects/Website/Games/Checkers/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ public List<Move> GetPossibleMoves(PieceColor color)
public List<Move> GetPossibleMoves(Piece piece)
{
List<Move> moves = new();
ValidateMove(-1, -1);
ValidateMove(-1, 1);
ValidateMove(1, -1);
ValidateMove(1, 1);
ValidateDiagonalMove(-1, -1);
ValidateDiagonalMove(-1, 1);
ValidateDiagonalMove( 1, -1);
ValidateDiagonalMove( 1, 1);
return moves.Any(move => move.PieceToCapture is not null)
? moves.Where(move => move.PieceToCapture is not null).ToList()
: moves;

void ValidateMove(int dx, int dy)
void ValidateDiagonalMove(int dx, int dy)
{
if (!piece.Promoted && piece.Color is Black && dy is -1) return;
if (!piece.Promoted && piece.Color is White && dy is 1) return;
Expand Down

0 comments on commit 99c09b1

Please sign in to comment.