-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChessMove.cs
95 lines (71 loc) · 2.42 KB
/
ChessMove.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chess___netanel
{
class ChessMove
{
public ChessPiece MovingPiece { get; set; }
public ChessPiece RemovedPiece { get; set; }
public Point RankAndFileFinal { get; set; }
public Point RankAndFileCurrent { get; set; }
public bool IsEat { get; set; }
public bool IsCheck { get; set; }
public bool IsDoubleCheck { get; set; }
public bool IsEndGameInfo { get; set; }
public string EndGameInfo { get; set; }
public string PromotedTo { get; set; } = "_";
public ChessMoveTag Tag { get; set; }
public override string ToString()
{
if (IsEndGameInfo)
return EndGameInfo;
if (Tag == ChessMoveTag.KingSideCastle)
return "0-0";
if (Tag == ChessMoveTag.QueenSideCastle)
return "0-0-0";
string result = "";
switch (MovingPiece.Type)
{
case PieceType.Pawn:
result = "";
break;
case PieceType.Knight:
result = "N";
break;
default:
result = Enum.GetName(typeof(PieceType), MovingPiece.Type)[0] + "";
break;
}
Point current = RankAndFileCurrent;
result += ChessUtilities.ConvertIndicesToRankAndFile(current.X, current.Y);
if (IsEat)
result += "x";
else
result += "->";
Point final = RankAndFileFinal;
result += ChessUtilities.ConvertIndicesToRankAndFile(final.X, final.Y);
if (Tag == ChessMoveTag.EnPassant)
result += "e.p.";
if (IsCheck)
result += "+";
if (IsDoubleCheck)
result += "+";
switch (PromotedTo)
{
case "K":
result += "N";
break;
default:
if(PromotedTo!="_")
result += PromotedTo;
break;
}
return result;
}
}
enum ChessMoveTag { DoublePawnMove = 1, PawnPromotion, EnPassant, KingSideCastle, QueenSideCastle }
}