本文整理汇总了C#中Chess.Piece类的典型用法代码示例。如果您正苦于以下问题:C# Piece类的具体用法?C# Piece怎么用?C# Piece使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Piece类属于Chess命名空间,在下文中一共展示了Piece类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetPiece
private void SetPiece(Piece piece, Player player, int letter, int number)
{
// if a thread called this, invoke recursion
if (this.InvokeRequired)
{
this.Invoke(new Action(() => SetPiece(piece, player, letter, number)));
return;
}
// out of bounds
if (letter < 0 || letter > 7 || number < 0 || number > 7)
return; // throw new IndexOutOfRangeException("Chess board letter or number out of range");
// clear tile
if (piece == Piece.NONE)
{
Board[number][letter].Image = null;
Board[number][letter].Invalidate();
return;
}
// update our render
Board[number][letter].Image = graphics.Pieces[player][piece];
Board[number][letter].Invalidate();
}
示例2: isThreatened
public bool isThreatened(int row, int col, Piece.Colour threatenedBy, Piece[,] board)
{
bool threatened = false;
List<int[]> covered = new List<int[]>();
List<int[]> filler = new List<int[]>();
for (int rows = 0; rows < Board.Rows; rows++)
{
for (int cols = 0; cols < Board.Cols; cols++)
{
if (board[rows, cols].PieceColour == threatenedBy)
{
thm.highlightThreatened(board[rows, cols], rows, cols, covered, filler, board, false);
}
}
}
foreach (int[] pair in covered)
{
if (pair[0] == row && pair[1] == col)
{
threatened = true;
break;
}
}
return threatened;
}
示例3: checkForCheck
public void checkForCheck(Piece[,] board, Piece.Colour colour)
{
if (cf.isThreatened(uf.FindKing(uf.OtherColour(colour), board), colour, board))
df.Check();
else
df.Clear();
}
示例4: pawnThreatenHighlight
void pawnThreatenHighlight(Piece piece, int row, int col, List<int[]> threatened, Piece[,] board, List<int[]> enPassant)
{
//capturing
if (piece.PieceColour == Piece.Colour.Black)
{
addThreatened(piece.PieceColour, piece.Row, piece.Col, 1, 1, threatened);
addThreatened(piece.PieceColour, piece.Row, piece.Col, 1, -1, threatened);
}
if (piece.PieceColour == Piece.Colour.White)
{
addThreatened(piece.PieceColour, piece.Row, piece.Col, -1, 1, threatened);
addThreatened(piece.PieceColour, piece.Row, piece.Col, -1, -1, threatened);
}
//en passant
if (piece.PieceColour == Piece.Colour.Black)
{
addEnPassant(piece.PieceColour, piece.Row, piece.Col, 1, 1, enPassant, board);
addEnPassant(piece.PieceColour, piece.Row, piece.Col, 1, -1, enPassant, board);
}
if (piece.PieceColour == Piece.Colour.White)
{
addEnPassant(piece.PieceColour, piece.Row, piece.Col, -1, 1, enPassant, board);
addEnPassant(piece.PieceColour, piece.Row, piece.Col, -1, -1, enPassant, board);
}
}
示例5: rookThreatenHighlight
void rookThreatenHighlight(Piece.Colour colour, int row, int col, List<int[]> threatened, Piece[,] board)
{
int i = 1;
//check down
while (addThreatened(colour, row, col, i, 0, threatened))
{
if (board[row + i, col].Exists)
break;
i++;
}
//check up
i = 1;
while (addThreatened(colour, row, col, -i, 0, threatened))
{
if (board[row - i, col].Exists)
break;
i++;
}
//check right
i = 1;
while (addThreatened(colour, row, col, 0, i, threatened))
{
if (board[row, col + i].Exists)
break;
i++;
}
//check left
i = 1;
while (addThreatened(colour, row, col, 0, -i, threatened))
{
if (board[row, col - i].Exists)
break;
i++;
}
}
示例6: performEnPassant
public void performEnPassant(int row, int col, Piece[,] Playfield)
{
if (row == Board.FirstRow + 2)
Playfield[Board.FirstRow + 3, col] = new Piece();
if (row == Board.LastRow - 2)
Playfield[Board.LastRow - 3, col] = new Piece();
}
示例7: addTaken
void addTaken(Piece piece, Piece[,] takenGrid, int[] takenIndeces)
{
takenGrid[takenIndeces[0], takenIndeces[1]] = piece;
takenIndeces[1]++;
takenIndeces[0] += takenIndeces[1] / 2;
takenIndeces[1] %= 2;
}
示例8: bishopThreatenHighlight
void bishopThreatenHighlight(string colour, int row, int col, List<int[]> threatened, Piece[,] board)
{
int i = 1;
//check down right
while (addThreatened(colour, row, col, i, i, threatened))
{
if (board[row + i, col + i].Exists)
break;
i++;
}
//check up right
i = 1;
while (addThreatened(colour, row, col, -i, i, threatened))
{
if (board[row - i, col + i].Exists)
break;
i++;
}
//check up left
i = 1;
while (addThreatened(colour, row, col, -i, -i, threatened))
{
if (board[row - i, col - i].Exists)
break;
i++;
}
//check down left
i = 1;
while (addThreatened(colour, row, col, i, -i, threatened))
{
if (board[row + i, col - i].Exists)
break;
i++;
}
}
示例9: performEnPassant
public void performEnPassant(int row, int col, Piece[,] Playfield)
{
if (row == 2)
Playfield[3, col] = new Piece();
if (row == 5)
Playfield[4, col] = new Piece();
}
示例10: Piece
// Copy-constructor
public Piece(Piece origin)
{
this.empty = origin.empty;
this.team = origin.team;
this.type = origin.type;
this.row = origin.row;
this.column = origin.column;
}
示例11: PieceMove
public PieceMove(Piece piece, Square target, Piece capturedPiece = null)
{
this.Piece = piece;
this.Source = piece.Square;
this.Target = target;
this.CanCapture = true;
this.CapturedPiece = capturedPiece ?? this.Board[target];
}
示例12: TakeTurn
public void TakeTurn(Piece[,] board, Piece[,] WhiteTaken, Piece[,] BlackTaken, int[] whiteTakenIndeces, int[] blackTakenIndeces, int depth)
{
topNode = new MoveNode(board);
think(depth, topNode);
bool mate = false;
AvailableMove move = selectMove(allMovesList, board, ref mate, currentColour);
if (!mate)
makeMove(move, board, WhiteTaken, BlackTaken, whiteTakenIndeces, blackTakenIndeces);
}
示例13: AddPiece
public void AddPiece(Piece piece, BoardCoordinate moveTarget)
{
if (piece == null)
throw new ArgumentNullException("piece");
if (!moveTarget.IsCoordinateValidForBoardSize(_boardSize))
throw new ArgumentException("moveTarget");
SetPiece(piece, moveTarget);
}
示例14: GetSquareImage
internal static Image GetSquareImage(Square square, Piece piece = null)
{
if (piece == null)
return boardImageCache["Empty"][square.GetSquareColor()];
var squareColor = square.GetSquareColor();
var key = piece.Player + piece.GetType().Name;
return boardImageCache[key][squareColor];
}
示例15: addEnPassant
void addEnPassant(string colour, int row, int col, int rowOffset, int colOffset, List<int[]> enPassant, Piece[,] board)
{
int destinationRow = row + rowOffset;
int destinationCol = col + colOffset;
if (destinationRow >= 0 && destinationRow <= 7 && destinationCol >= 0 && destinationCol <= 7 && board[row, col + colOffset].EnPassant)
{
enPassant.Add(new int[] { destinationRow, destinationCol });
}
}