From c6bdd63d2eb252c17a384ff688a63cd7eb799ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E5=82=91?= <840465812@qq.com> Date: Mon, 10 May 2021 22:06:10 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=AE=8C=E5=96=84=20=E6=A3=8B=E7=9B=98?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E7=B1=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChineseChess.Core/ChessboardPosition.cs | 49 ++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/ChineseChess.Core/ChessboardPosition.cs b/ChineseChess.Core/ChessboardPosition.cs index 616b848..1be8be5 100644 --- a/ChineseChess.Core/ChessboardPosition.cs +++ b/ChineseChess.Core/ChessboardPosition.cs @@ -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); + } + + } } \ No newline at end of file