1. 完善 棋盘坐标类功能

This commit is contained in:
筱傑 2021-05-10 22:06:10 +08:00
parent f0b664e2a6
commit c6bdd63d2e

View File

@ -2,7 +2,52 @@
{
public struct ChessboardPosition
{
public byte Col;
public byte Row;
public int Col;
public int Row;
public ChessboardPosition(int col, int row)
{
Col=col;
Row=row;
}
public override bool Equals(object obj)
{
return obj is ChessboardPosition pos
&& pos.Col == this.Col
&& pos.Row == this.Row;
}
public override int GetHashCode()
{
return Col ^ Row;
}
public override string ToString()
{
return $"({Row}, {Col})";
}
public static bool operator ==(ChessboardPosition left, ChessboardPosition right)
{
return left.Equals(right);
}
public static bool operator !=(ChessboardPosition left, ChessboardPosition right)
{
return !(left==right);
}
public static ChessboardPosition operator +(ChessboardPosition left, ChessboardPosition right)
{
return new ChessboardPosition(left.Col + right.Col, left.Row + right.Row);
}
public static ChessboardPosition operator -(ChessboardPosition left, ChessboardPosition right)
{
return new ChessboardPosition(left.Col - right.Col, left.Row - right.Row);
}
}
}