本文整理汇总了C#中IBoard.GetFigureAtPosition方法的典型用法代码示例。如果您正苦于以下问题:C# IBoard.GetFigureAtPosition方法的具体用法?C# IBoard.GetFigureAtPosition怎么用?C# IBoard.GetFigureAtPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBoard
的用法示例。
在下文中一共展示了IBoard.GetFigureAtPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckIfFigureOnTheWay
public static void CheckIfFigureOnTheWay(IPosition position, IBoard board, string message)
{
if (board.GetFigureAtPosition(position) != null)
{
throw new ArgumentException(message);
}
}
示例2: KingWon
/// <summary>
/// Method that checks whether the king won or not
/// </summary>
/// <param name="players">The game players</param>
/// <param name="board">The game board</param>
/// <returns>Returns true if the king meets curtain conditions</returns>
public bool KingWon(IList<IPlayer> players, IBoard board)
{
var kingPlayer = players[0];
var pawnPlayer = players[1];
////check if king is on the first row
foreach (var figure in kingPlayer.Figures)
{
if (board.GetFigurePosition((IFigure)figure.Value).Row == 0)
{
return true;
}
}
//// check if all powns are on the last row
for (int i = 1; i < board.NumberOfRows; i += 2)
{
if (board.GetFigureAtPosition(new Position(board.NumberOfColumns - 1, i)) == null)
{
return false;
}
}
return true;
}
示例3: RenderBoard
public void RenderBoard(IBoard board)
{
this.PrintHorizontalNumbers();
for (int row = 0; row < board.NumberOfRows; row++)
{
Console.Write(row + "| ");
for (int column = 0; column < board.NumberOfColumns; column++)
{
Position position = new Position(row, column);
var figure = board.GetFigureAtPosition(position);
if (figure != null)
{
Console.Write(figure.DisplayName + " ");
}
else
{
this.PrintCell(position);
}
}
Console.Write("|");
Console.WriteLine();
}
this.PrintHorizontalLines();
}
示例4: CheckIfFigureOnTheWay
/// <summary>
/// Checks if the figure is on the way that the figures want to move
/// </summary>
/// <param name="position">Position on which the figure moves</param>
/// <param name="board">The game board</param>
/// <exception cref="InvalidPositionException"></exception>
public static void CheckIfFigureOnTheWay(IPosition position, IBoard board)
{
if (board.GetFigureAtPosition(position) != null)
{
throw new InvalidPositionException(GlobalErrorMessages.FigureOnTheWayErrorMessage);
}
}
示例5: CheckOtherFigureIfValid
private bool CheckOtherFigureIfValid(IBoard board, Position to, ChessColor color)
{
var otherFigure = board.GetFigureAtPosition(to);
if (otherFigure != null && otherFigure.Color == color)
{
return false;
}
return true;
}
示例6: ValidateMove
public void ValidateMove(IFigure figure, IBoard board, Move move)
{
var rowDistance = Math.Abs(move.From.Row - move.To.Row);
var colDistance = Math.Abs(move.From.Col - move.To.Col);
if (rowDistance != colDistance)
{
throw new InvalidOperationException(BishopInvalidMove);
}
var from = move.From;
var to = move.To;
int rowIndex = from.Row;
char colIndex = from.Col;
var other = figure.Color == ChessColor.White ? ChessColor.Black : ChessColor.White;
// top-right
while (true)
{
rowIndex++;
colIndex++;
if (to.Row == rowIndex && to.Col == colIndex)
{
var figureAtPosition = board.GetFigureAtPosition(to);
if (figureAtPosition != null && figureAtPosition.Color == figure.Color)
{
throw new InvalidOperationException("There is a figure on the way!");
}
else
{
return;
}
}
var position = Position.FromChessCoordinates(rowIndex, colIndex);
var figAtPosition = board.GetFigureAtPosition(position);
if (figAtPosition != null)
{
throw new InvalidOperationException("There is a figure on the way!");
}
}
}
示例7: DownChecker
private void DownChecker(IBoard board, Position from, Position to)
{
for (int i = from.Row; i > to.Row + 1; i--)
{
Position curentPosition = new Position(i - 1, from.Col);
var figureAtPosition = board.GetFigureAtPosition(curentPosition);
if (figureAtPosition != null)
{
throw new InvalidOperationException("Rook cannot move this way!");
}
}
}
示例8: CheckIfPositionIsEmpty
private bool CheckIfPositionIsEmpty(Position position, IBoard board)
{
if (this.CheckIfInsideTheBoard(position))
{
if (board.GetFigureAtPosition(position) == null)
{
return true;
}
}
return false;
}
示例9: RightChecker
private void RightChecker(IBoard board, Position from, Position to)
{
var currentCol = from.Col + 1;
for (int i = from.Col; i < to.Col - 1; i++)
{
Position curentPosition = new Position(from.Row, (char)currentCol);
var figureAtPosition = board.GetFigureAtPosition(curentPosition);
if (figureAtPosition != null)
{
throw new InvalidOperationException("Rook cannot move this way!");
}
currentCol++;
}
}
示例10: BoardToFen
public static string BoardToFen(IBoard board)
{
var fen = new StringBuilder();
var reversedRow = board.TotalRows;
for (int row = 1; row <= board.TotalRows; row++)
{
var empySpace = 0;
for (int col = 0; col < board.TotalCols; col++)
{
var figure = board.GetFigureAtPosition(new Position(reversedRow, (char)('a' + col)));
if (figure == null)
{
empySpace++;
}
else
{
if (empySpace != 0)
{
fen.Append(empySpace);
empySpace = 0;
}
if (figure is King)
{
fen.Append('K');
}
else
{
fen.Append('p');
}
}
if (col == (board.TotalCols - 1) && empySpace != 0)
{
fen.Append(empySpace);
}
}
if (row != board.TotalRows)
{
fen.Append('/');
}
reversedRow--;
}
return fen.ToString();
}
示例11: RenderBoard
public void RenderBoard(IBoard board)
{
for (int row = 0; row < board.NumberOfRows; row++)
{
for (int column = 0; column < board.NumberOfColumns; column++)
{
// int cell = board[row, colum];
Position position=new Position(row,column);
var figure = board.GetFigureAtPosition(position);
ConsoleHelpers.PrintFigure(figure,position);
}
Console.WriteLine();
}
}
示例12: RenderBoard
public void RenderBoard(IBoard board)
{
// TODO: Validate Console Dimension
var startRowPrint = (Console.WindowWidth / 2) - ((board.TotalRows / 2) * ConsoleConstants.CharactersPerRowPerBoardSquare);
var startColPrint = (Console.WindowHeight / 2) - ((board.TotalCols / 2) * ConsoleConstants.CharactersPerColPerBoardSquare);
int currentRowPrint = startRowPrint;
int currentColPrint = startColPrint;
this.RenderBoarderForBord(startRowPrint, startColPrint, board.TotalRows, board.TotalCols);
int counter = 1;
for (int top = 0; top < board.TotalCols; top++)
{
for (int left = 0; left < board.TotalRows; left++)
{
currentColPrint = startRowPrint + (left * ConsoleConstants.CharactersPerColPerBoardSquare);
currentRowPrint = startColPrint + (top * ConsoleConstants.CharactersPerRowPerBoardSquare);
ConsoleColor backgroundColor;
if (counter % 2 == 0)
{
backgroundColor = DarskSquareConsoleColor;
Console.BackgroundColor = DarskSquareConsoleColor;
}
else
{
backgroundColor = LightSquareConsoleColor;
Console.BackgroundColor = LightSquareConsoleColor;
}
var position = Position.FromArrayCoordinates(top, left, board.TotalRows);
var figure = board.GetFigureAtPosition(position);
ConsoleHelpers.PrintFigure(figure, backgroundColor, currentRowPrint, currentColPrint);
counter++;
}
counter++;
}
}
示例13: ValidateMove
public override void ValidateMove(IFigure figure, IBoard board, Move move)
{
var from = move.From;
var to = move.To;
if ((from.Row - 1 == to.Row && from.Col + 1 == to.Col) ||
(from.Row - 1 == to.Row && from.Col - 1 == to.Col))
{
var otherFigure = board.GetFigureAtPosition(to);
if (otherFigure != null)
{
throw new InvalidOperationException(InvalidMove);
}
return;
}
throw new InvalidOperationException(InvalidMove);
}
示例14: DownLeftChecker
private void DownLeftChecker(IBoard board, Position from, Position to)
{
var fromRow = from.Row;
var fromCol = from.Col;
var currentRow = fromRow;
var currentCol = fromCol;
while (true)
{
currentRow--;
currentCol--;
if (currentRow == to.Row && currentCol == to.Col)
{
return;
}
Position curentPosition = new Position(currentRow, currentCol);
var figureAtPosition = board.GetFigureAtPosition(curentPosition);
if (figureAtPosition != null)
{
throw new InvalidOperationException("Bishop cannot move this way!");
}
}
}
示例15: RenderBoard
public void RenderBoard(IBoard board)
{
Console.Clear();
var startRowPrint = Console.BufferWidth / 2 - (board.TotalRows / 2) * ConsoleConstants.CharactersPerRowPerBoardSquare;
var startColPrint = Console.BufferHeight / 2 - (board.TotalCols / 2) * ConsoleConstants.CharactersPerColPerBoardSquare;
var currentRowPrint = startRowPrint;
var currentColPrint = startColPrint;
this.PrintBorder(startRowPrint, startColPrint, board.TotalRows, board.TotalCols);
int counter = 1;
for (int top = 0; top < board.TotalRows; top++)
{
for (int left = 0; left < board.TotalCols; left++)
{
currentColPrint = startRowPrint + left * ConsoleConstants.CharactersPerColPerBoardSquare;
currentRowPrint = startColPrint + top * ConsoleConstants.CharactersPerRowPerBoardSquare;
ConsoleColor background;
if (counter % 2 == 0)
{
background = DarkSquareConsoleColor;
Console.BackgroundColor = DarkSquareConsoleColor;
}
else
{
background = LightSquareConsoleColor;
Console.BackgroundColor = LightSquareConsoleColor;
}
var position = new Position(board.TotalRows - top, (char)(left + 'a'));
var figure = board.GetFigureAtPosition(position);
ConsolePrintFigure.Print(figure, background, currentRowPrint, currentColPrint);
counter++;
}
counter++;
}
Console.SetCursorPosition(Console.WindowWidth / 2, 1);
}