feat(重构): 重构棋盘和棋子的逻辑
- 重构了 ChessBoard 和 ChessPiece 类的逻辑 - 添加了新版本的 ChineseChess 库 - 删除了旧版本的 VirtualBoard 和 VirtualPiece 类 - 更新了相关的场景和脚本
This commit is contained in:
133
Scripts/Src/Vector.cs
Normal file
133
Scripts/Src/Vector.cs
Normal file
@ -0,0 +1,133 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Vector;
|
||||
|
||||
public class Vector2I {
|
||||
public Vector2I() {
|
||||
X = 0;
|
||||
Y = 0;
|
||||
}
|
||||
|
||||
public Vector2I(int x, int y) {
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public Vector2I(Vector2I other) {
|
||||
X = other.X;
|
||||
Y = other.Y;
|
||||
}
|
||||
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
|
||||
public static bool operator ==(Vector2I a, Vector2I b) {
|
||||
return a?.X == b?.X && a?.Y == b?.Y;
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector2I a, Vector2I b) {
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public static Vector2I operator +(Vector2I left, Vector2I right) {
|
||||
return new (
|
||||
left.X + right.X,
|
||||
left.Y + right.Y);
|
||||
}
|
||||
|
||||
public static Vector2I operator -(Vector2I left, Vector2I right) {
|
||||
return new (
|
||||
left.X - right.X,
|
||||
left.Y - right.Y);
|
||||
}
|
||||
|
||||
public static Vector2I operator *(Vector2I left, Vector2I right) {
|
||||
return new (
|
||||
left.X * right.X,
|
||||
left.Y * right.Y);
|
||||
}
|
||||
|
||||
public int Dot(Vector2I with) {
|
||||
return X * with.X + Y * with.Y;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
if (obj is Vector2I other) {
|
||||
return this == other;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return System.HashCode.Combine(X, Y);
|
||||
}
|
||||
|
||||
public static readonly Vector2I MaxValue = new(int.MaxValue, int.MinValue);
|
||||
public static readonly Vector2I MinValue = new (int.MinValue, int.MaxValue);
|
||||
public static readonly Vector2I Zero = new(0, 0);
|
||||
|
||||
public static readonly Vector2I Up = new(0, 1);
|
||||
public static readonly Vector2I Down = new(0, -1);
|
||||
public static readonly Vector2I Left = new(-1, 0);
|
||||
public static readonly Vector2I Right = new(1, 0);
|
||||
|
||||
public override string ToString() {
|
||||
return $"({X},{Y})";
|
||||
}
|
||||
}
|
||||
|
||||
public class Trans2DI {
|
||||
public Vector2I XAxis { get; set; } // x axis , first column
|
||||
public Vector2I YAxis { get; set; } // y axis , second column
|
||||
public Vector2I Origin { get; set; } // origin point
|
||||
public Trans2DI() {
|
||||
XAxis = new Vector2I(1, 0);
|
||||
YAxis = new Vector2I(0, 1);
|
||||
Origin = new Vector2I(0, 0);
|
||||
}
|
||||
|
||||
public Trans2DI(Vector2I xAxis, Vector2I yAxis, Vector2I origin) {
|
||||
XAxis = xAxis;
|
||||
YAxis = yAxis;
|
||||
Origin = origin;
|
||||
}
|
||||
|
||||
public Trans2DI(Trans2DI other) {
|
||||
XAxis = other.XAxis;
|
||||
YAxis = other.YAxis;
|
||||
Origin = other.Origin;
|
||||
}
|
||||
|
||||
public Trans2DI(int xx, int xy, int yx, int yy, int ox, int oy) {
|
||||
XAxis = new Vector2I(xx, xy);
|
||||
YAxis = new Vector2I(yx, yy);
|
||||
Origin = new Vector2I(ox, oy);
|
||||
}
|
||||
|
||||
public static Trans2DI Identity => new();
|
||||
|
||||
/**
|
||||
* X.x Y.x * v.x + O.x = X.x * v.x + Y.x * v.y + O.x
|
||||
* X.y Y.y v.y O.y X.y * v.x + Y.y * v.y + O.y
|
||||
*/
|
||||
public static Vector2I operator *(in Trans2DI trans, in Vector2I vec) {
|
||||
return new Vector2I(
|
||||
trans.XAxis.X * vec.X + trans.XAxis.Y * vec.Y,
|
||||
trans.YAxis.X * vec.X + trans.YAxis.Y * vec.Y) + trans.Origin;
|
||||
}
|
||||
|
||||
public static Vector2I operator *(in Vector2I vec, in Trans2DI trans) {
|
||||
Vector2I with = vec - trans.Origin;
|
||||
return new Vector2I(
|
||||
trans.XAxis.X * with.X + trans.XAxis.Y * with.Y,
|
||||
trans.YAxis.X * with.X + trans.YAxis.Y * with.Y);
|
||||
}
|
||||
|
||||
public static Trans2DI operator *(Trans2DI a, Trans2DI b) {
|
||||
return new Trans2DI();
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return $"[{XAxis}, {YAxis}, {Origin}]";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user