UTests pass with Pathfinder2D
This commit is contained in:
47
Gameboard.ShogiUI.BoardState/Pieces/Bishop.cs
Normal file
47
Gameboard.ShogiUI.BoardState/Pieces/Bishop.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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)
|
||||
{
|
||||
new Path(Direction.UpLeft, Distance.MultiStep),
|
||||
new Path(Direction.UpRight, Distance.MultiStep),
|
||||
new Path(Direction.DownLeft, Distance.MultiStep),
|
||||
new Path(Direction.DownRight, Distance.MultiStep)
|
||||
};
|
||||
private static readonly List<Path> PromotedMoveSet = new List<Path>(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)
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
public override Piece DeepClone()
|
||||
{
|
||||
var clone = new Bishop(Owner);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Gameboard.ShogiUI.BoardState/Pieces/GoldGeneral.cs
Normal file
34
Gameboard.ShogiUI.BoardState/Pieces/GoldGeneral.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using PathFinding;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Gameboard.ShogiUI.BoardState.Pieces
|
||||
{
|
||||
public class GoldenGeneral : Piece
|
||||
{
|
||||
public static readonly List<Path> MoveSet = new List<Path>(6)
|
||||
{
|
||||
new Path(Direction.Up),
|
||||
new Path(Direction.UpLeft),
|
||||
new Path(Direction.UpRight),
|
||||
new Path(Direction.Left),
|
||||
new Path(Direction.Right),
|
||||
new Path(Direction.Down)
|
||||
};
|
||||
public GoldenGeneral(WhichPlayer owner) : base(WhichPiece.GoldenGeneral, owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override Piece DeepClone()
|
||||
{
|
||||
var clone = new GoldenGeneral(Owner);
|
||||
if (IsPromoted) clone.Promote();
|
||||
return clone;
|
||||
}
|
||||
|
||||
public override ICollection<Path> GetPaths() => Owner == WhichPlayer.Player1
|
||||
? MoveSet
|
||||
: MoveSet.Select(_ => new Path(Vector2.Negate(_.Direction), _.Distance)).ToList();
|
||||
}
|
||||
}
|
||||
35
Gameboard.ShogiUI.BoardState/Pieces/King.cs
Normal file
35
Gameboard.ShogiUI.BoardState/Pieces/King.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using PathFinding;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Gameboard.ShogiUI.BoardState.Pieces
|
||||
{
|
||||
public class King : Piece
|
||||
{
|
||||
private static readonly List<Path> MoveSet = new List<Path>(8)
|
||||
{
|
||||
new Path(Direction.Up),
|
||||
new Path(Direction.Left),
|
||||
new Path(Direction.Right),
|
||||
new Path(Direction.Down),
|
||||
new Path(Direction.UpLeft),
|
||||
new Path(Direction.UpRight),
|
||||
new Path(Direction.DownLeft),
|
||||
new Path(Direction.DownRight)
|
||||
};
|
||||
public King(WhichPlayer owner) : base(WhichPiece.King, owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override Piece DeepClone()
|
||||
{
|
||||
var clone = new King(Owner);
|
||||
if (IsPromoted) clone.Promote();
|
||||
return clone;
|
||||
}
|
||||
public override ICollection<Path> GetPaths() => Owner == WhichPlayer.Player1
|
||||
? MoveSet
|
||||
: MoveSet.Select(_ => new Path(Vector2.Negate(_.Direction), _.Distance)).ToList();
|
||||
}
|
||||
}
|
||||
33
Gameboard.ShogiUI.BoardState/Pieces/Knight.cs
Normal file
33
Gameboard.ShogiUI.BoardState/Pieces/Knight.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using PathFinding;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Gameboard.ShogiUI.BoardState.Pieces
|
||||
{
|
||||
public class Knight : Piece
|
||||
{
|
||||
private static readonly List<Path> MoveSet = new List<Path>(2)
|
||||
{
|
||||
new Path(Direction.KnightLeft),
|
||||
new Path(Direction.KnightRight)
|
||||
};
|
||||
|
||||
public Knight(WhichPlayer owner) : base(WhichPiece.Knight, owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override Piece DeepClone()
|
||||
{
|
||||
var clone = new Knight(Owner);
|
||||
if (IsPromoted) clone.Promote();
|
||||
return clone;
|
||||
}
|
||||
|
||||
public override ICollection<Path> GetPaths()
|
||||
{
|
||||
var moveSet = IsPromoted ? GoldenGeneral.MoveSet : MoveSet;
|
||||
return Owner == WhichPlayer.Player1 ? moveSet : moveSet.Select(_ => new Path(Vector2.Negate(_.Direction), _.Distance)).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Gameboard.ShogiUI.BoardState/Pieces/Lance.cs
Normal file
32
Gameboard.ShogiUI.BoardState/Pieces/Lance.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using PathFinding;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Gameboard.ShogiUI.BoardState.Pieces
|
||||
{
|
||||
public class Lance : Piece
|
||||
{
|
||||
private static readonly List<Path> MoveSet = new List<Path>(1)
|
||||
{
|
||||
new Path(Direction.Up, Distance.MultiStep),
|
||||
};
|
||||
|
||||
public Lance(WhichPlayer owner) : base(WhichPiece.Lance, owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override Piece DeepClone()
|
||||
{
|
||||
var clone = new Lance(Owner);
|
||||
if (IsPromoted) clone.Promote();
|
||||
return clone;
|
||||
}
|
||||
|
||||
public override ICollection<Path> GetPaths()
|
||||
{
|
||||
var moveSet = IsPromoted ? GoldenGeneral.MoveSet : MoveSet;
|
||||
return Owner == WhichPlayer.Player1 ? moveSet : moveSet.Select(_ => new Path(Vector2.Negate(_.Direction), _.Distance)).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Gameboard.ShogiUI.BoardState/Pieces/Pawn.cs
Normal file
32
Gameboard.ShogiUI.BoardState/Pieces/Pawn.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using PathFinding;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Gameboard.ShogiUI.BoardState.Pieces
|
||||
{
|
||||
public class Pawn : Piece
|
||||
{
|
||||
private static readonly List<Path> MoveSet = new List<Path>(1)
|
||||
{
|
||||
new Path(Direction.Up)
|
||||
};
|
||||
|
||||
public Pawn(WhichPlayer owner) : base(WhichPiece.Pawn, owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override Piece DeepClone()
|
||||
{
|
||||
var clone = new Pawn(Owner);
|
||||
if (IsPromoted) clone.Promote();
|
||||
return clone;
|
||||
}
|
||||
|
||||
public override ICollection<Path> GetPaths()
|
||||
{
|
||||
var moveSet = IsPromoted ? GoldenGeneral.MoveSet : MoveSet;
|
||||
return Owner == WhichPlayer.Player1 ? moveSet : moveSet.Select(_ => new Path(Vector2.Negate(_.Direction), _.Distance)).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
44
Gameboard.ShogiUI.BoardState/Pieces/Rook.cs
Normal file
44
Gameboard.ShogiUI.BoardState/Pieces/Rook.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using PathFinding;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Gameboard.ShogiUI.BoardState.Pieces
|
||||
{
|
||||
public class Rook : Piece
|
||||
{
|
||||
private static readonly List<Path> MoveSet = new List<Path>(4)
|
||||
{
|
||||
new Path(Direction.Up, Distance.MultiStep),
|
||||
new Path(Direction.Left, Distance.MultiStep),
|
||||
new Path(Direction.Right, Distance.MultiStep),
|
||||
new Path(Direction.Down, Distance.MultiStep)
|
||||
};
|
||||
private static readonly List<Path> PromotedMoveSet = new List<Path>(8)
|
||||
{
|
||||
new Path(Direction.Up, Distance.MultiStep),
|
||||
new Path(Direction.Left, Distance.MultiStep),
|
||||
new Path(Direction.Right, Distance.MultiStep),
|
||||
new Path(Direction.Down, Distance.MultiStep),
|
||||
new Path(Direction.UpLeft),
|
||||
new Path(Direction.UpRight),
|
||||
new Path(Direction.DownLeft),
|
||||
new Path(Direction.DownRight)
|
||||
};
|
||||
public Rook(WhichPlayer owner) : base(WhichPiece.Rook, owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override Piece DeepClone()
|
||||
{
|
||||
var clone = new Rook(Owner);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Gameboard.ShogiUI.BoardState/Pieces/SilverGeneral.cs
Normal file
35
Gameboard.ShogiUI.BoardState/Pieces/SilverGeneral.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using PathFinding;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Gameboard.ShogiUI.BoardState.Pieces
|
||||
{
|
||||
public class SilverGeneral : Piece
|
||||
{
|
||||
private static readonly List<Path> MoveSet = new List<Path>(4)
|
||||
{
|
||||
new Path(Direction.Up),
|
||||
new Path(Direction.UpLeft),
|
||||
new Path(Direction.UpRight),
|
||||
new Path(Direction.DownLeft),
|
||||
new Path(Direction.DownRight)
|
||||
};
|
||||
public SilverGeneral(WhichPlayer owner) : base(WhichPiece.SilverGeneral, owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override Piece DeepClone()
|
||||
{
|
||||
var clone = new SilverGeneral(Owner);
|
||||
if (IsPromoted) clone.Promote();
|
||||
return clone;
|
||||
}
|
||||
|
||||
public override ICollection<Path> GetPaths()
|
||||
{
|
||||
var moveSet = IsPromoted ? GoldenGeneral.MoveSet : MoveSet;
|
||||
return Owner == WhichPlayer.Player1 ? moveSet : moveSet.Select(_ => new Path(Vector2.Negate(_.Direction), _.Distance)).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user