before deleting Rules

This commit is contained in:
2021-05-08 10:26:04 -05:00
parent 05a9c71499
commit f8f779e84c
80 changed files with 1109 additions and 832 deletions

View File

@@ -0,0 +1,39 @@
using PathFinding;
using System.Collections.Generic;
namespace Gameboard.ShogiUI.Rules.Pieces
{
public class Bishop : Piece
{
private static readonly List<PathFinding.Move> Moves = new(4)
{
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<PathFinding.Move> PromotedMoves = new(8)
{
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)
{
moveSet = new MoveSet(this, Moves);
promotedMoveSet = new MoveSet(this, PromotedMoves);
}
public override Piece DeepClone()
{
var clone = new Bishop(Owner);
if (IsPromoted) clone.Promote();
return clone;
}
}
}

View File

@@ -0,0 +1,30 @@
using PathFinding;
using System.Collections.Generic;
namespace Gameboard.ShogiUI.Rules.Pieces
{
public class GoldenGeneral : Piece
{
public static readonly List<PathFinding.Move> Moves = new(6)
{
new PathFinding.Move(Direction.Up),
new PathFinding.Move(Direction.UpLeft),
new PathFinding.Move(Direction.UpRight),
new PathFinding.Move(Direction.Left),
new PathFinding.Move(Direction.Right),
new PathFinding.Move(Direction.Down)
};
public GoldenGeneral(WhichPlayer owner) : base(WhichPiece.GoldGeneral, owner)
{
moveSet = new MoveSet(this, Moves);
promotedMoveSet = new MoveSet(this, Moves);
}
public override Piece DeepClone()
{
var clone = new GoldenGeneral(Owner);
if (IsPromoted) clone.Promote();
return clone;
}
}
}

View File

@@ -0,0 +1,32 @@
using PathFinding;
using System.Collections.Generic;
namespace Gameboard.ShogiUI.Rules.Pieces
{
public class King : Piece
{
private static readonly List<PathFinding.Move> Moves = new(8)
{
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),
new PathFinding.Move(Direction.UpRight),
new PathFinding.Move(Direction.DownLeft),
new PathFinding.Move(Direction.DownRight)
};
public King(WhichPlayer owner) : base(WhichPiece.King, owner)
{
moveSet = new MoveSet(this, Moves);
promotedMoveSet = new MoveSet(this, Moves);
}
public override Piece DeepClone()
{
var clone = new King(Owner);
if (IsPromoted) clone.Promote();
return clone;
}
}
}

View File

@@ -0,0 +1,27 @@
using PathFinding;
using System.Collections.Generic;
namespace Gameboard.ShogiUI.Rules.Pieces
{
public class Knight : Piece
{
private static readonly List<PathFinding.Move> Moves = new(2)
{
new PathFinding.Move(Direction.KnightLeft),
new PathFinding.Move(Direction.KnightRight)
};
public Knight(WhichPlayer owner) : base(WhichPiece.Knight, owner)
{
moveSet = new MoveSet(this, Moves);
promotedMoveSet = new MoveSet(this, GoldenGeneral.Moves);
}
public override Piece DeepClone()
{
var clone = new Knight(Owner);
if (IsPromoted) clone.Promote();
return clone;
}
}
}

View File

@@ -0,0 +1,26 @@
using PathFinding;
using System.Collections.Generic;
namespace Gameboard.ShogiUI.Rules.Pieces
{
public class Lance : Piece
{
private static readonly List<PathFinding.Move> Moves = new(1)
{
new PathFinding.Move(Direction.Up, Distance.MultiStep),
};
public Lance(WhichPlayer owner) : base(WhichPiece.Lance, owner)
{
moveSet = new MoveSet(this, Moves);
promotedMoveSet = new MoveSet(this, GoldenGeneral.Moves);
}
public override Piece DeepClone()
{
var clone = new Lance(Owner);
if (IsPromoted) clone.Promote();
return clone;
}
}
}

View File

@@ -0,0 +1,26 @@
using PathFinding;
using System.Collections.Generic;
namespace Gameboard.ShogiUI.Rules.Pieces
{
public class Pawn : Piece
{
private static readonly List<PathFinding.Move> Moves = new(1)
{
new PathFinding.Move(Direction.Up)
};
public Pawn(WhichPlayer owner) : base(WhichPiece.Pawn, owner)
{
moveSet = new MoveSet(this, Moves);
promotedMoveSet = new MoveSet(this, GoldenGeneral.Moves);
}
public override Piece DeepClone()
{
var clone = new Pawn(Owner);
if (IsPromoted) clone.Promote();
return clone;
}
}
}

View File

@@ -0,0 +1,47 @@
using PathFinding;
using System.Diagnostics;
namespace Gameboard.ShogiUI.Rules.Pieces
{
[DebuggerDisplay("{WhichPiece} {Owner}")]
public abstract class Piece : IPlanarElement
{
protected MoveSet promotedMoveSet;
protected MoveSet moveSet;
public MoveSet MoveSet => IsPromoted ? promotedMoveSet : moveSet;
public abstract Piece DeepClone();
public WhichPiece WhichPiece { get; }
public WhichPlayer Owner { get; private set; }
public bool IsPromoted { get; private set; }
public bool IsUpsideDown => Owner == WhichPlayer.Player2;
public Piece(WhichPiece piece, WhichPlayer owner)
{
WhichPiece = piece;
Owner = owner;
IsPromoted = false;
}
public bool CanPromote => !IsPromoted
&& WhichPiece != WhichPiece.King
&& WhichPiece != WhichPiece.GoldGeneral;
public void ToggleOwnership()
{
Owner = Owner == WhichPlayer.Player1
? WhichPlayer.Player2
: WhichPlayer.Player1;
}
public void Promote() => IsPromoted = CanPromote;
public void Demote() => IsPromoted = false;
public void Capture()
{
ToggleOwnership();
Demote();
}
}
}

View File

@@ -0,0 +1,39 @@
using PathFinding;
using System.Collections.Generic;
namespace Gameboard.ShogiUI.Rules.Pieces
{
public class Rook : Piece
{
private static readonly List<PathFinding.Move> Moves = new(4)
{
new PathFinding.Move(Direction.Up, Distance.MultiStep),
new PathFinding.Move(Direction.Left, Distance.MultiStep),
new PathFinding.Move(Direction.Right, Distance.MultiStep),
new PathFinding.Move(Direction.Down, Distance.MultiStep)
};
private static readonly List<PathFinding.Move> PromotedMoves = new(8)
{
new PathFinding.Move(Direction.Up, Distance.MultiStep),
new PathFinding.Move(Direction.Left, Distance.MultiStep),
new PathFinding.Move(Direction.Right, Distance.MultiStep),
new PathFinding.Move(Direction.Down, Distance.MultiStep),
new PathFinding.Move(Direction.UpLeft),
new PathFinding.Move(Direction.UpRight),
new PathFinding.Move(Direction.DownLeft),
new PathFinding.Move(Direction.DownRight)
};
public Rook(WhichPlayer owner) : base(WhichPiece.Rook, owner)
{
moveSet = new MoveSet(this, Moves);
promotedMoveSet = new MoveSet(this, PromotedMoves);
}
public override Piece DeepClone()
{
var clone = new Rook(Owner);
if (IsPromoted) clone.Promote();
return clone;
}
}
}

View File

@@ -0,0 +1,29 @@
using PathFinding;
using System.Collections.Generic;
namespace Gameboard.ShogiUI.Rules.Pieces
{
public class SilverGeneral : Piece
{
private static readonly List<PathFinding.Move> Moves = new(4)
{
new PathFinding.Move(Direction.Up),
new PathFinding.Move(Direction.UpLeft),
new PathFinding.Move(Direction.UpRight),
new PathFinding.Move(Direction.DownLeft),
new PathFinding.Move(Direction.DownRight)
};
public SilverGeneral(WhichPlayer owner) : base(WhichPiece.SilverGeneral, owner)
{
moveSet = new MoveSet(this, Moves);
promotedMoveSet = new MoveSet(this, GoldenGeneral.Moves);
}
public override Piece DeepClone()
{
var clone = new SilverGeneral(Owner);
if (IsPromoted) clone.Promote();
return clone;
}
}
}