Exemple #1
0
        /// <summary>
        /// generates the regular cardinal movements
        /// </summary>
        private static IEnumerable <Move> AddBasicMoves(Cell cell, MoveDefinition moveDef)
        {
            var  moves      = new List <Move>();
            bool isTopColor = cell.piece.color == GameBoard.Instance.Layout.topColor;

            foreach (MoveDirection dir in Enum.GetValues(typeof(MoveDirection)))
            {
                if (dir == MoveDirection.None || !moveDef.direction.HasFlag(dir))
                {
                    continue;
                }

                foreach (Point p in GetDirectionOffset(dir))
                {
                    var offset = isTopColor ? new Point(p.X, -p.Y) : p;

                    moves.AddRange(
                        FilterMoves(moveDef,
                                    GetCellsInDirection(cell, moveDef.distance, offset).ToList(), cell)
                        );
                }
            }

            return(moves);
        }
Exemple #2
0
        private static List <Move> AddLeaperMoves(MoveDefinition moveDef, Cell start, Point leapOffset, List <Move> moves)
        {
            var points = new List <Point>();

            for (int i = -1; i <= 1; i += 2)
            {
                for (int j = -1; j <= 1; j += 2)
                {
                    points.Add(start.position + new Point(leapOffset.X * i, leapOffset.Y * j));
                    points.Add(start.position + new Point(leapOffset.Y * i, leapOffset.X * j));
                }
            }

            points.RemoveAll(p => !GameBoard.InBounds(p));
            points.RemoveAll(p => GameBoard.Instance.TryGetPiece(p, out var piece) && piece.color == start.piece.color);

            return(FilterMoves(moveDef, points.Select(p => new Move(p)).ToList(), start));
        }
Exemple #3
0
        private static List <Move> FilterMoves(MoveDefinition moveDef, List <Move> moves, Cell cell)
        {
            if (moveDef.condition.HasFlag(MoveCondition.Initial) && cell.piece.HasMoved)
            {
                return(new List <Move>());
            }

            if (moveDef.condition.HasFlag(MoveCondition.CaptureOnly))
            {
                moves.RemoveAll(move => !GameBoard.Instance.CellOccupied(move.targetPosition));
            }

            if (moveDef.condition.HasFlag(MoveCondition.NotCaptureOnly))
            {
                moves.RemoveAll(move => GameBoard.Instance.CellOccupied(move.targetPosition));
            }

            moves.RemoveAll(m => !GameBoard.InBounds(m.targetPosition));

            return(moves);
        }