示例#1
0
文件: Rules.cs 项目: urise/Checkers
 private void AddMoves(List<string> moves, Cell cell)
 {
     if (cell.Type == PieceType.King)
         AddKingMoves(moves, cell);
     else
         AddSimpleMoves(moves, cell);
 }
示例#2
0
文件: Rules.cs 项目: urise/Checkers
        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();
            }
        }
示例#3
0
文件: Rules.cs 项目: urise/Checkers
 private void AddSimpleMoves(List<string> moves, Cell cell)
 {
     foreach (var square in GetPossibleSimpleMoves(cell))
     {
         if (_position.SquareIsEmpty(square))
             moves.Add(cell + "-" + square);
     }
 }
示例#4
0
文件: Rules.cs 项目: urise/Checkers
 private void AddKingMoves(List<string> moves, Cell cell)
 {
     foreach (var direction in _directions.AllDirections())
     {
         var squares = _boardGeometry.GetCellsByDirection(cell, direction, 0);
         foreach (var square in squares)
         {
             if (!_position.SquareIsEmpty(square)) break;
             moves.Add(cell + "-" + square);
         }
     }
 }
示例#5
0
 private void SetCell(string cellStr)
 {
     if (cellStr.Length != 3) throw new Exception("Wrong format: " + cellStr);
     var cell = new Cell(cellStr);
     _cells.Add(cell);
 }
示例#6
0
文件: Rules.cs 项目: urise/Checkers
 private void AddTakeMoves(List<string> moves, Cell cell)
 {
     AddTakeMoves(new FindTakeMovesParameter(cell), moves, cell, string.Empty);
 }
示例#7
0
文件: Rules.cs 项目: urise/Checkers
        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;
        }
示例#8
0
文件: Rules.cs 项目: urise/Checkers
 private IEnumerable<ISquare> GetPossibleSimpleMoves(Cell cell)
 {
     return _boardGeometry.GetCellsByDirections(cell, _directions.SimpleMoveDirections(cell.Color), 1);
 }
示例#9
0
文件: Rules.cs 项目: urise/Checkers
        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;
        }
示例#10
0
 public FindTakeMovesParameter(Cell startCell)
 {
     StartCell = startCell;
 }