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; }
private List<Move> GetAllAvailableMove(Game game, GameSide gameSide) { var availableMoves = new List<Move>(); foreach (var figure in game.Board.Figures.Where(x => x.Side == gameSide)) { var allMovesForFigure = figure.GetFieldsICanMoveTo(); foreach (var locationToMoveTo in allMovesForFigure) { var move = new Move(figure.Location, locationToMoveTo, gameSide); if (_moveValidator.MoveIsValid(move,game.Board)) availableMoves.Add(move); } } return availableMoves; }
public MoveResult HandleMove(Game game, Move move) { var existingFigure = game.Board.GetFigureOnLocation(move.To); if (existingFigure != null) game.Board.CaptureFigure(existingFigure); var figureToMove = game.Board.GetFigureOnLocation(move.From); if (figureToMove.ShouldConvert(move)) { game.Board.ConvertFigure(figureToMove, move); } else { figureToMove.Move(move); } return GetMoveResult(game.Board, move.Side); }
public int EvaluateMove(Game game, Move move) { throw new System.NotImplementedException(); }
private bool MoveWouldCauseCheckOnSelf(Move move, Board board) { /// TODO return false; }
public bool IsInBoard(Move move) { return IsInBoard(move.From) && IsInBoard(move.To); }
public bool HasFigureForMove(Move move) { var figureOnFrom = GetFigureOnLocation(move.From); return figureOnFrom != null && figureOnFrom.Side == move.Side; }
public void ConvertFigure(Figure figureToMove, Move move) { Figures.Remove(figureToMove); Figures.Add(new Queen(move.Side, move.To.Column, move.To.Row)); }