Code smells

This commit is contained in:
2021-03-04 20:35:23 -06:00
parent e64f75e3cc
commit 7ed771d467
31 changed files with 310 additions and 339 deletions

View File

@@ -1,34 +1,32 @@
using PathFinding;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace Gameboard.ShogiUI.BoardState.Pieces
{
public class Bishop : Piece
{
private static readonly List<Path> MoveSet = new List<Path>(4)
private static readonly List<PathFinding.Move> Moves = new(4)
{
new Path(Direction.UpLeft, Distance.MultiStep),
new Path(Direction.UpRight, Distance.MultiStep),
new Path(Direction.DownLeft, Distance.MultiStep),
new Path(Direction.DownRight, Distance.MultiStep)
new PathFinding.Move(Direction.UpLeft, Distance.MultiStep),
new PathFinding.Move(Direction.UpRight, Distance.MultiStep),
new PathFinding.Move(Direction.DownLeft, Distance.MultiStep),
new PathFinding.Move(Direction.DownRight, Distance.MultiStep)
};
private static readonly List<Path> PromotedMoveSet = new List<Path>(8)
private static readonly List<PathFinding.Move> PromotedMoves = new(8)
{
new Path(Direction.Up),
new Path(Direction.Left),
new Path(Direction.Right),
new Path(Direction.Down),
new Path(Direction.UpLeft, Distance.MultiStep),
new Path(Direction.UpRight, Distance.MultiStep),
new Path(Direction.DownLeft, Distance.MultiStep),
new Path(Direction.DownRight, Distance.MultiStep)
new PathFinding.Move(Direction.Up),
new PathFinding.Move(Direction.Left),
new PathFinding.Move(Direction.Right),
new PathFinding.Move(Direction.Down),
new PathFinding.Move(Direction.UpLeft, Distance.MultiStep),
new PathFinding.Move(Direction.UpRight, Distance.MultiStep),
new PathFinding.Move(Direction.DownLeft, Distance.MultiStep),
new PathFinding.Move(Direction.DownRight, Distance.MultiStep)
};
public Bishop(WhichPlayer owner) : base(WhichPiece.Bishop, owner)
{
// TODO: If this strat works out, we can do away with the Direction class entirely.
PromotedMoveSet.AddRange(MoveSet);
moveSet = new MoveSet(this, Moves);
promotedMoveSet = new MoveSet(this, PromotedMoves);
}
public override Piece DeepClone()
@@ -37,11 +35,5 @@ namespace Gameboard.ShogiUI.BoardState.Pieces
if (IsPromoted) clone.Promote();
return clone;
}
public override ICollection<Path> GetPaths()
{
var moveSet = IsPromoted ? PromotedMoveSet : MoveSet;
return Owner == WhichPlayer.Player1 ? moveSet : moveSet.Select(_ => new Path(Vector2.Negate(_.Direction), _.Distance)).ToList();
}
}
}