本文整理汇总了C#中Piece.MovePosition方法的典型用法代码示例。如果您正苦于以下问题:C# Piece.MovePosition方法的具体用法?C# Piece.MovePosition怎么用?C# Piece.MovePosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piece
的用法示例。
在下文中一共展示了Piece.MovePosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsTheKingPutInCheck
List<Vector2> IsTheKingPutInCheck(List<Vector2> moves, Piece piece)
{
//In this method I am going to simulate the board state and then
//Move the piece in question to see if its movement will open
//an attack route to the king, if it does the move will be prohibited.
List<Vector2> allowedMoves = new List<Vector2>();
Tile[,] clonedTiles = MakeVirtualTiles(tiles);
Piece[] clonedPieces = MakeVirtualPieces(pieces);
Piece pieceClone = new Piece();
//Deep Clones the Peice so I can move it around.
foreach (Piece clonedPiece in clonedPieces)
{
if (clonedPiece.MyCoordinates() == piece.MyCoordinates())
{
pieceClone = clonedPiece;
}
}
Vector2 origin = piece.MyCoordinates();
foreach (Vector2 move in moves)
{
pieceClone.MovePosition(move);
//These did not help
clonedTiles[(int)origin.x, (int)origin.y].occupied = false;
clonedTiles[(int)move.x, (int)move.y].occupied = true;
ThreatCheck(clonedTiles, clonedPieces);
if (!CheckCheck(pieceClone.player, clonedPieces, clonedTiles))
{
allowedMoves.Add(move);
}
pieceClone.MovePosition(origin);
clonedTiles[(int)origin.x, (int)origin.y].occupied = true;
clonedTiles[(int)move.x, (int)move.y].occupied = false;
}
return allowedMoves;
}
示例2: GetOutOfCheck
List<Vector2> GetOutOfCheck(List<Vector2> moves, Piece piece)
{
//NOTE problem with pawns captureing other pawns to remove the king from check
//By the time I get here I get 6 make Virtual Piece calls gotta fix that. (Should be 4) TODO
// The way I do this will be horribly inneficent I think. If performance becomes an issue
//I should head here first. Most notably if I pass a list instead of a single peice when
//Used to determin checkmate it will reduce the generation of virtual stuff to once
//Instead of once per piece.
//TODO we gotta add captures to the equation.
List<Vector2> allowedMoves = new List<Vector2>();
Tile[,] virtualTiles = MakeVirtualTiles(tiles);
Piece[] virtualPieces = MakeVirtualPieces(pieces);
Piece virtualPiece = new Piece();
//Clones the piece in question
foreach (Piece vPiece in virtualPieces)
{
if (piece.MyCoordinates() == vPiece.MyCoordinates())
{
virtualPiece = vPiece;
}
}
Vector2 origin = virtualPiece.MyCoordinates();
Debug.Log(moves.Count + " moves to check");
foreach (Vector2 move in moves)
{
foreach (Piece vPiece in virtualPieces)
{
if (vPiece.MyCoordinates() == move)
{
Debug.Log("Captured @ " + move);
vPiece.captured = true;
}
}
virtualPiece.MovePosition(move);
UpdateTileOccupation(virtualTiles, virtualPieces);
ClearThreats(virtualTiles);
ThreatCheck(virtualTiles, virtualPieces);
if (!CheckCheck(virtualPiece.player, virtualPieces, virtualTiles))
{
allowedMoves.Add(move);
}
//Return Peice to location and try next move.
virtualPiece.MovePosition(origin);
}
return allowedMoves;
}