本文整理汇总了C#中Chess.Piece.GetPieceType方法的典型用法代码示例。如果您正苦于以下问题:C# Piece.GetPieceType方法的具体用法?C# Piece.GetPieceType怎么用?C# Piece.GetPieceType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chess.Piece
的用法示例。
在下文中一共展示了Piece.GetPieceType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseLine
public static bool ParseLine(String line, out String message)
{
string placingPattern = "^([KQBNRP])([ld])([a-h, A-H][1-8])$";
string movingPattern = "^([a-h,A-H][1-8])\\s([a-h,A-H][1-8])$";
string doubleMovePattern = "^([a-h,A-H][1-8])\\s([a-h,A-H][1-8])\\s([a-h,A-H][1-8])\\s([a-h,A-H][1-8])$";
message = "";
if (Regex.IsMatch(line, placingPattern))
{
char piece = line.ElementAt(0);
char color = line.ElementAt(1);
char rank = line.ElementAt(2);
char file = line.ElementAt(3);
Piece p = new Piece(piece, color);
message = string.Concat("Place the ", p.GetColor(), " ", p.GetPieceType(), " at ", rank, file, "\n");
validPlacements.Add(line);
return true;
}
else if (Regex.IsMatch(line, movingPattern))
{
char startingRank = line.ElementAt(0);
char startingFile = line.ElementAt(1);
char endingRank = line.ElementAt(3);
char endingFile = line.ElementAt(4);
message = string.Concat("Move the piece at ", startingRank, startingFile, " to ", endingRank, endingFile, "\n");
validMoves.Add(line);
return true;
}
else if (Regex.IsMatch(line, doubleMovePattern))
{
char firstStartingRank = line.ElementAt(0);
char firstStartingFile = line.ElementAt(1);
char firstEndingRank = line.ElementAt(3);
char firstEndingFile = line.ElementAt(4);
char secondStartingRank = line.ElementAt(6);
char secondStartingFile = line.ElementAt(7);
char secondEndingRank = line.ElementAt(9);
char secondEndingFile = line.ElementAt(10);
message = string.Concat("Move the piece at ", firstStartingRank, firstStartingFile, " to ", firstEndingRank, firstEndingFile, " and the piece at ", secondStartingRank, secondStartingFile, " to ", secondEndingRank, secondEndingFile,"\n");
validMoves.Add(line);
return true;
}
else if (!Regex.IsMatch(line, "^($)"))
{
PrintInfo(line, "This line is invalid input.");
return false;
}
return false;
}