本文整理汇总了C#中Chess.Piece类的典型用法代码示例。如果您正苦于以下问题:C# Piece类的具体用法?C# Piece怎么用?C# Piece使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Piece类属于Chess命名空间,在下文中一共展示了Piece类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:bdidemus,项目名称:chess,代码行数:25,代码来源:MainFormBoard.cs
示例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;
}
开发者ID:georgelbaxter,项目名称:chess,代码行数:25,代码来源:CheckFunctions.cs
示例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();
}
开发者ID:georgelbaxter,项目名称:chess,代码行数:7,代码来源:CheckDisplayFunctions.cs
示例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);
}
}
开发者ID:georgelbaxter,项目名称:chess,代码行数:25,代码来源:ThreatenHighlightFunctions.cs
示例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++;
}
}
开发者ID:georgelbaxter,项目名称:chess,代码行数:35,代码来源:ThreatenHighlightFunctions.cs
示例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();
}
开发者ID:georgelbaxter,项目名称:chess,代码行数:7,代码来源:MovementFunctions.cs
示例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;
}
开发者ID:georgelbaxter,项目名称:chess,代码行数:7,代码来源:DisplayFunctions.cs
示例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++;
}
}
开发者ID:georgelbaxter,项目名称:chessAI,代码行数:35,代码来源:ThreatenHighlightFunctions.cs
示例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();
}
开发者ID:georgelbaxter,项目名称:chessAI,代码行数:7,代码来源:MovementFunctions.cs
示例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;
}
开发者ID:mapplet,项目名称:Chess,代码行数:9,代码来源:Piece.cs
示例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];
}
开发者ID:hcesar,项目名称:Chess,代码行数:8,代码来源:PieceMove.cs
示例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);
}
开发者ID:georgelbaxter,项目名称:chessAI,代码行数:9,代码来源:AI.cs
示例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);
}
开发者ID:chnicholas,项目名称:ChessTDD,代码行数:9,代码来源:Board.cs
示例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];
}
开发者ID:hcesar,项目名称:Chess,代码行数:9,代码来源:Images.cs
示例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 });
}
}
开发者ID:georgelbaxter,项目名称:chessAI,代码行数:9,代码来源:ThreatenHighlightFunctions.cs
示例16: Rules
public List<Tuple<int, int>> Rules(Piece currentPiece, Gameboard gameboard)
{
this.moves_dia = get_diagonal.Rules(currentPiece, gameboard);
this.moves_str = get_straight.Rules(currentPiece, gameboard);
moves_str = moves_str.Concat(moves_dia).ToList();
return moves_str;
}
开发者ID:mapplet,项目名称:Chess,代码行数:9,代码来源:Queen.cs
示例17: Piece
public Piece(Piece piece)
{
Colour = piece.Colour;
Type = piece.Type;
Exists = piece.Exists;
HasMoved = piece.HasMoved;
EnPassant = piece.EnPassant;
Row = piece.Row;
Col = piece.Col;
}
开发者ID:georgelbaxter,项目名称:chessAI,代码行数:10,代码来源:Piece.cs
示例18: Rules
public List<Tuple<int, int>> Rules(Piece current_piece, Gameboard gameboard)
{
this.gameboard = gameboard;
this.current_piece = current_piece;
if (current_piece.column > min && current_piece.row > min + 1)
{
next_piece = gameboard.getPiece(current_piece.row - 2, current_piece.column - 1);
if (next_piece.empty == true || next_piece.team != current_piece.team)
valid_destinations.Add(new Tuple<int, int>(current_piece.row - 2, current_piece.column - 1)); // up left
}
if (current_piece.column < max && current_piece.row > min + 1)
{
Piece next_piece = gameboard.getPiece(current_piece.row - 2, current_piece.column + 1);
if (next_piece.empty == true || next_piece.team != current_piece.team)
valid_destinations.Add(new Tuple<int, int>(current_piece.row -2, current_piece.column + 1)); // up right
}
if (current_piece.column < max - 1 && current_piece.row > min)
{
Piece next_piece = gameboard.getPiece(current_piece.row - 1, current_piece.column + 2);
if (next_piece.empty == true || next_piece.team != current_piece.team)
valid_destinations.Add(new Tuple<int, int>(current_piece.row - 1, current_piece.column + 2)); // right up
}
if (current_piece.column < max - 1 && current_piece.row < max)
{
Piece next_piece = gameboard.getPiece(current_piece.row + 1, current_piece.column + 2);
if (next_piece.empty == true || next_piece.team != current_piece.team)
valid_destinations.Add(new Tuple<int, int>(current_piece.row + 1, current_piece.column + 2)); // right down
}
if (current_piece.column < max && current_piece.row < max - 1)
{
Piece next_piece = gameboard.getPiece(current_piece.row + 2, current_piece.column + 1);
if (next_piece.empty == true || next_piece.team != current_piece.team)
valid_destinations.Add(new Tuple<int, int>(current_piece.row + 2, current_piece.column + 1)); // down right
}
if (current_piece.column > min && current_piece.row < max - 1)
{
Piece next_piece = gameboard.getPiece(current_piece.row + 2, current_piece.column - 1);
if (next_piece.empty == true || next_piece.team != current_piece.team)
valid_destinations.Add(new Tuple<int, int>(current_piece.row + 2, current_piece.column - 1)); // down left
}
if (current_piece.column > min + 1 && current_piece.row < max)
{
Piece next_piece = gameboard.getPiece(current_piece.row + 1, current_piece.column - 2);
if (next_piece.empty == true || next_piece.team != current_piece.team)
valid_destinations.Add(new Tuple<int, int>(current_piece.row + 1, current_piece.column - 2)); // left down
}
if (current_piece.column > min + 1 && current_piece.row > min)
{
Piece next_piece = gameboard.getPiece(current_piece.row - 1, current_piece.column - 2);
if (next_piece.empty == true || next_piece.team != current_piece.team)
valid_destinations.Add(new Tuple<int, int>(current_piece.row - 1, current_piece.column - 2)); // left up
}
return valid_destinations;
}
开发者ID:mapplet,项目名称:Chess,代码行数:55,代码来源:Knight.cs
示例19: OtherColour
public Piece.Colour OtherColour(Piece.Colour colour)
{
Piece.Colour otherColour;
if (colour == Piece.Colour.Black)
otherColour = Piece.Colour.White;
else if (colour == Piece.Colour.White)
otherColour = Piece.Colour.Black;
else
otherColour = Piece.Colour.Empty;
return otherColour;
}
开发者ID:georgelbaxter,项目名称:chess,代码行数:11,代码来源:UtilityFunctions.cs
示例20: AddTaken
//Methods
public void AddTaken(Piece piece, Piece[,] whiteTaken, Piece[,] blackTaken, int[] whiteTakenIndeces, int[] blackTakenIndeces)
{
if (piece.PieceColour == Piece.Colour.White)
{
addTaken(piece, whiteTaken, whiteTakenIndeces);
}
if (piece.PieceColour == Piece.Colour.Black)
{
addTaken(piece, blackTaken, blackTakenIndeces);
}
}
开发者ID:georgelbaxter,项目名称:chess,代码行数:12,代码来源:DisplayFunctions.cs
注:本文中的Chess.Piece类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论