mirror of
https://github.com/jie65535/ChineseChess.git
synced 2024-07-27 18:55:00 +08:00
1. 完善 棋盘坐标类功能
This commit is contained in:
parent
f0b664e2a6
commit
c6bdd63d2e
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user