Exemplo n.º 1
0
        private void AddTakeMoves(FindTakeMovesParameter takeMoveInfo, List<string> moves, Cell cell, string path)
        {
            var takeMoves = GetSingleTakeMoves(takeMoveInfo, cell);
            if (takeMoves.Count == 0 && !string.IsNullOrEmpty(path))
            {
                moves.Add(path);
                return;
            }

            if (string.IsNullOrEmpty(path)) path = cell.ToString();

            foreach (var takeMove in takeMoves)
            {
                takeMoveInfo.AddAlreadyTaken(takeMove.SquareTaken);

                var newPieceType = (cell.Type == PieceType.Simple &&
                                    IsTurnToKingHorizontal(_position.CurrentColor, takeMove.SquareToMove.Y)
                    ? PieceType.King
                    : cell.Type);
                var newPiece = new Piece(newPieceType, cell.Color);
                var newCell = new Cell(takeMove.SquareToMove, newPiece);

                AddTakeMoves(takeMoveInfo, moves, newCell, path + "-" + takeMove.SquareToMove);
                takeMoveInfo.RemoveLastAlreadyTaken();
            }
        }
Exemplo n.º 2
0
        private List<TakeMove> GetSingleTakeMoves(FindTakeMovesParameter takeMoveInfo, Cell cell)
        {
            var result = new List<TakeMove>();
            foreach (var direction in _directions.AllDirections())
            {
                result.AddRange(AddTakeMoves(takeMoveInfo, cell, direction));
            }

            return result;
        }
Exemplo n.º 3
0
        private IEnumerable<TakeMove> AddTakeMoves(FindTakeMovesParameter takeMoveInfo, Cell cell, IDirection direction)
        {
            int distance = cell.Type == PieceType.King ? 0 : 2;
            var squares = _boardGeometry.GetCellsByDirection(cell, direction, distance);
            bool isTaken = false;

            var result = new List<TakeMove>();

            ISquare cellTaken = null;
            foreach (var square in squares)
            {
                if (isTaken)
                {
                    if (!_position.SquareIsEmpty(square) && !square.IsEqualTo(takeMoveInfo.StartCell)) break;
                    result.Add(new TakeMove {SquareTaken = cellTaken, SquareToMove = square});
                }
                else
                {
                    if (_position.SquareIsColor(square, takeMoveInfo.StartCell.Color.GetOppositeColor()))
                    {
                        if (takeMoveInfo.IsAlreadyTaken(square)) break;
                        isTaken = true;
                        cellTaken = square;
                    }
                }
            }
            return result;
        }