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