forked from thomas-daniels/Chess.NET
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPiece.cs
62 lines (53 loc) · 1.75 KB
/
Piece.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.ObjectModel;
namespace ChessDotCore
{
public abstract class Piece
{
public abstract Player Owner
{
get;
set;
}
public abstract bool IsPromotionResult
{
get;
set;
}
public abstract Piece GetWithInvertedOwner();
public abstract Piece AsPromotion();
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
return true;
if (obj == null || GetType() != obj.GetType())
return false;
Piece piece1 = this;
Piece piece2 = (Piece)obj;
return piece1.Owner == piece2.Owner;
}
public override int GetHashCode()
{
return new { Piece = GetFenCharacter(), Owner }.GetHashCode();
}
public static bool operator ==(Piece piece1, Piece piece2)
{
if (ReferenceEquals(piece1, piece2))
return true;
if ((object)piece1 == null || (object)piece2 == null)
return false;
return piece1.Equals(piece2);
}
public static bool operator !=(Piece piece1, Piece piece2)
{
if (ReferenceEquals(piece1, piece2))
return false;
if ((object)piece1 == null || (object)piece2 == null)
return true;
return !piece1.Equals(piece2);
}
public abstract char GetFenCharacter();
public abstract bool IsValidMove(Move move, ChessGame game);
public abstract ReadOnlyCollection<Move> GetValidMoves(Position from, bool returnIfAny, ChessGame game, Func<Move, bool> gameMoveValidator);
}
}