コード例 #1
0
        public bool IsValid(PawnAdapter selectedPawn, List <PawnAdapter> bluePawns, List <PawnAdapter> redPawns)
        {
            List <PawnAdapter> oponentPlayer = selectedPawn.Player() == PlayerEnum.Red ? bluePawns : redPawns;
            List <Point>       positions     = new List <Point>();
            int nextPosition = selectedPawn.Player() == PlayerEnum.Red ? RuleConfig.moveBackTwoRows : RuleConfig.moveTwoRows;

            positions.Add(new Point(selectedPawn.Column() + RuleConfig.moveTwoColumns, selectedPawn.Row() + nextPosition));
            positions.Add(new Point(selectedPawn.Column() - RuleConfig.moveTwoColumns, selectedPawn.Row() + nextPosition));

            if (selectedPawn.Type() == PawnTypeEnum.Jumper)
            {
                positions.Add(new Point(selectedPawn.Column() + RuleConfig.moveTwoColumns, selectedPawn.Row() - nextPosition));
                positions.Add(new Point(selectedPawn.Column() - RuleConfig.moveTwoColumns, selectedPawn.Row() - nextPosition));
            }
            foreach (Point position in positions)
            {
                if (IsInField(position) && !ShouldOccupy(position, redPawns, bluePawns))
                {
                    Point middlePoint = new Point(AverageCalculator.CalculateAverage(position.X, selectedPawn.Column()), AverageCalculator.CalculateAverage(position.Y, selectedPawn.Row()));
                    if (Occupy(middlePoint, oponentPlayer))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #2
0
        public int CalculateMovedRows(PawnAdapter origin, PawnAdapter destination)
        {
            int movedRows = origin.Row() - destination.Row();

            movedRows = origin.Player() == PlayerEnum.Red ? movedRows : (movedRows * -1);

            return(origin.Type() == PawnTypeEnum.Jumper ? Math.Abs(movedRows) : movedRows);
        }
コード例 #3
0
        public bool IsValid(PawnAdapter origin, PawnAdapter destination)
        {
            int movedRows = MoveCalculator.CalculateMovedRows(origin, destination);

            movedRows = origin.Type() == PawnTypeEnum.Jumper ? Math.Abs(movedRows) : movedRows;
            int movedColumns = MoveCalculator.CalculateMovedColumns(origin, destination);

            return(movedRows == RuleConfig.moveOneRow && Math.Abs(movedColumns) == RuleConfig.moveOneColumn);
        }