Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 public int EvaluateMove(Game game, Move move)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 6
0
 private bool MoveWouldCauseCheckOnSelf(Move move, Board board)
 {
     /// TODO
     return false;
 }
Exemplo n.º 7
0
 public bool IsInBoard(Move move)
 {
     return IsInBoard(move.From) && IsInBoard(move.To);
 }
Exemplo n.º 8
0
 public bool HasFigureForMove(Move move)
 {
     var figureOnFrom = GetFigureOnLocation(move.From);
     return figureOnFrom != null && figureOnFrom.Side == move.Side;
 }
Exemplo n.º 9
0
 public void ConvertFigure(Figure figureToMove, Move move)
 {
     Figures.Remove(figureToMove);
     Figures.Add(new Queen(move.Side, move.To.Column, move.To.Row));
 }