public bool MoveIsValid(Move move, Board board) { if (move == null) { Console.WriteLine("parse failed"); return false; } if (!board.IsInBoard(move)) { Console.WriteLine("move not on board"); return false; } if (!board.HasFigureForMove(move)) { Console.WriteLine("no figure to move"); return false; } if (!MoveIsAllowed(move, board)) { Console.WriteLine("invalid move"); return false; } return true; }
private bool MoveIsAllowed(Move move, Board board) { var figure = board.GetFigureOnLocation(move.From); if (!figure.CanMoveToLocation(move.To)) return false; var figureOnLocation = board.GetFigureOnLocation(move.To); if (figureOnLocation != null && figureOnLocation.Side == move.Side) return false; if (MoveWouldCauseCheckOnSelf(move, board)) return false; return true; }
public void Draw(Board board) { Console.Clear(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(); Console.WriteLine(" a b c d e f g h"); Console.WriteLine(); for (var row = 8; row >= 1; row--) { //var line = ""; for (var att = 0; att <= 1; att++) { Console.ForegroundColor = ConsoleColor.DarkYellow; if (att == 0) Console.Write(" "); else Console.Write(row + " "); for (var col = 1; col <= 8; col++) { var figure = board.GetFigureOnLocation(new FieldLocation(row, col)); if (figure == null) Console.Write(" "); else { Console.ForegroundColor = figure.Side == GameSide.White ? ConsoleColor.White : ConsoleColor.DarkRed; Console.Write(figure.GetString()); Console.Write(figure.GetString()); } Console.Write(" "); } Console.WriteLine(""); } Console.WriteLine(); } Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(); Console.WriteLine(" a b c d e f g h"); }
public Board CreateNewBoard() { var board = new Board(); board.Figures = new List<Figure>(); for (var row = 1; row <= 8; row++) { for (var col = 1; col <= 8; col++) { var figureToGive = GetFigureToGive(row, col); if (figureToGive != null) { figureToGive.Board = board; board.Figures.Add(figureToGive); } } } return board; }
public bool IsMate(Board board, GameSide side) { // check if opponent can make any move after which his king won't be attacked return false; }
public bool IsCheck(Board board, GameSide side) { // check if any of figures is attacking opponents king return false; }
private bool MoveWouldCauseCheckOnSelf(Move move, Board board) { /// TODO return false; }
private MoveResult GetMoveResult(Board board, GameSide side) { if (_boardHandler.IsCheck(board, side)) { if (_boardHandler.IsMate(board, side)) { return MoveResult.Mate; } return MoveResult.Check; } return MoveResult.NormalMove; }