示例#1
0
        private static IEnumerable <FigureMoving> AllKnightMoves(FigureMoving fm)
        {
            fm.GetCellsAndFigures("Nc4a5");//Влево-Вверх
            yield return(fm);

            fm.GetCellsAndFigures("Nc4a3");//Влево-Вниз
            yield return(fm);

            fm.GetCellsAndFigures("Nc4b6");//Вверх-Влево
            yield return(fm);

            fm.GetCellsAndFigures("Nc4d6");//Вверх-Вправо
            yield return(fm);

            fm.GetCellsAndFigures("Nc4e5");//Вправо-Вверх
            yield return(fm);

            fm.GetCellsAndFigures("Nc4e3");//Вправо-Вниз
            yield return(fm);

            fm.GetCellsAndFigures("Nc4b2");//Вниз-Влево
            yield return(fm);

            fm.GetCellsAndFigures("Nc4d2");//Вниз-Вправо
            yield return(fm);
        }
示例#2
0
        public void CanMoveKingBeatFriendlyFigureTest()//Атака дружественных фигур
        {
            Board Board = new Board("rnbqkbnr/pppppppp/PPPPPPPP/PPPPKPPP/PPPPPPPP/PPPPPPPP/PPPPPPPP/RNBQPBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            Fm.GetCellsAndFigures("Ke5e6");
            Assert.IsFalse(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("Ke5f6");
            Assert.IsFalse(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("Ke5f5");
            Assert.IsFalse(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("Ke5f4");
            Assert.IsFalse(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("Ke5e4");
            Assert.IsFalse(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("Ke5d4");
            Assert.IsFalse(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("Ke5d5");
            Assert.IsFalse(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("Ke5d6");
            Assert.IsFalse(Moves.CanMove(Fm));
        }
示例#3
0
        private static IEnumerable <FigureMoving> AllKingMoves(FigureMoving fm)
        {
            fm.GetCellsAndFigures("Ke5e6");
            yield return(fm);

            fm.GetCellsAndFigures("Ke5f6");
            yield return(fm);

            fm.GetCellsAndFigures("Ke5f5");
            yield return(fm);

            fm.GetCellsAndFigures("Ke5f4");
            yield return(fm);

            fm.GetCellsAndFigures("Ke5e4");
            yield return(fm);

            fm.GetCellsAndFigures("Ke5d4");
            yield return(fm);

            fm.GetCellsAndFigures("Ke5d5");
            yield return(fm);

            fm.GetCellsAndFigures("Ke5d6");
            yield return(fm);
        }
示例#4
0
        public void GetCellAndFigureWrongYAndXTest()//Отсутствие координаты X и Y на поле
        {
            Board Board = new Board(Fen);

            FigureMoving Fm = new FigureMoving(Board);

            Assert.ThrowsException <ArgumentException>(() => Fm.GetCellsAndFigures("nb9a9"));
        }
示例#5
0
        public void MoveFigureMovingIsNullTest()
        {
            Board Board = new Board(Fen);

            FigureMoving Fm = null;

            Assert.ThrowsException <NullReferenceException>(() => Board.Move(Fm));
        }
示例#6
0
        public bool CanMove(FigureMoving figureMoving)
        {
            this.Fm = figureMoving;

            return(CanMoveFrom() &&
                   CanMoveTo() &&
                   CanFigureMove());
        }
示例#7
0
        public void GetCellAndFigureNoFigureAndNegativeCoordinateYTest()//Отсутствие фигуры и отрицательная координата, но зато 5 символов
        {
            Board Board = new Board(Fen);

            FigureMoving Fm = new FigureMoving(Board);

            Assert.ThrowsException <ArgumentException>(() => Fm.GetCellsAndFigures("b1a-2"));
        }
示例#8
0
        public void GetCellAndFigureSymbolsMoreThan5Test()//Параметр имеет больше 5 символов
        {
            Board Board = new Board(Fen);

            FigureMoving Fm = new FigureMoving(Board);

            Assert.ThrowsException <ArgumentException>(() => Fm.GetCellsAndFigures("nb-1a2"));
        }
示例#9
0
        public void GetCellAndFigureWrongFigureTest()//Неправильная фигура на начальной клетке
        {
            Board Board = new Board(Fen);

            FigureMoving Fm = new FigureMoving(Board);

            Assert.ThrowsException <ArgumentException>(() => Fm.GetCellsAndFigures("ra1a2"));
        }
示例#10
0
        public void GetCellAndFigureNoFigureTest()//Отсутствие фигуры в параметре, параметр меньше 5 символов
        {
            Board Board = new Board(Fen);

            FigureMoving Fm = new FigureMoving(Board);

            Assert.ThrowsException <ArgumentException>(() => Fm.GetCellsAndFigures("a1a2"));
        }
示例#11
0
文件: Moves.cs 项目: ValikSk8er/chess
 public bool CanMove(FigureMoving fm)
 {
     this.fm = fm;
     return
         (CanMoveFrom() &&
          CanMoveTo() &&
          CanFigureMove());
 }
示例#12
0
        public Board Move(FigureMoving fm)
        {
            Board next = new Board(fen);

            next.SetFigureAt(fm.from, Figure.none);
            next.SetFigureAt(fm.to, fm.figure);
            next.moveColor = moveColor.FlipColor();
            return(next);
        }
示例#13
0
        public void CanMoveLikeRookBeatFriendlyFigureTest()//Попытка ферзя атаковать дружеские фигуры, выполняя ход как ладья
        {
            Board Board = new Board(Fen);
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            Fm.GetCellsAndFigures("Qd1d2");
            Assert.IsFalse(Moves.CanMove(Fm));
        }
示例#14
0
        public void CanMoveWrongMoveTest() //Невозможное перемещение пешки
        {
            Board Board = new Board(Fen);
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            Fm.GetCellsAndFigures("Pa2a5");
            Assert.IsFalse(Moves.CanMove(Fm));
        }
示例#15
0
        public void CanMoveRookBeatFriendlyFigureTest()//Попытка ладьи атаковать дружеские фигуры
        {
            Board Board = new Board(Fen);
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            Fm.GetCellsAndFigures("Ra1a2");
            Assert.IsFalse(Moves.CanMove(Fm));
        }
示例#16
0
        public void MoveNegativeFigureMovingTest()
        {
            Board Board = new Board(Fen);

            Cell FromCell = new Cell(-1, -1);
            Cell ToCell   = new Cell(-1, -2);

            FigureMoving Fm = new FigureMoving(FromCell, ToCell);

            Assert.AreEqual(Board.Fen, Board.Move(Fm).Fen);//Поле никак не изменилось, хода не был сделан
        }
示例#17
0
        public void CanMoveKnightBeatFigureTest()//Атака конем вражеских фигур
        {
            Board Board = new Board("rnbqkbnr/pppppppp/pppppppp/pppppppp/ppNppppp/pppppppp/pppppppp/RNBQKBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            foreach (var fm in AllKnightMoves(Fm))
            {
                Assert.IsTrue(Moves.CanMove(fm));
            }
        }
示例#18
0
        public void CanMoveBishopMoveTest()//Перемещение слона
        {
            Board Board = new Board("rnbqkbnr/......../......../......../...B..../......../......../RNBQKBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            foreach (var fm in AllBishopMoves(Fm))
            {
                Assert.IsTrue(Moves.CanMove(fm));
            }
        }
示例#19
0
        public void CanMoveBishopJumpOverFigureTest()//Попытка слона перепрыгнуть через фигуры
        {
            Board Board = new Board("rnbqkbnr/......../......../..p.p.../...B..../..P.P.../......../RNBQKBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            foreach (var fm in AllBishopMoves(Fm))
            {
                Assert.IsFalse(Moves.CanMove(fm));
            }
        }
示例#20
0
        public void CanMoveLikeBishopMoveTest()//Перемещение ферзя, выполняя ход как слон
        {
            Board Board = new Board("rnbqkbnr/......../......../......../...Q..../......../......../RNBQKBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            foreach (var fm in AllBishopMovesForQueen(Fm))
            {
                Assert.IsTrue(Moves.CanMove(fm));
            }
        }
示例#21
0
        public void CanMoveLikeBishopJumpOverFigureTest()//Попытка ферзя перепрыгнуть через фигуры, выполняя ход как слон
        {
            Board Board = new Board("rnbqkbnr/......../......../..p.p.../...Q..../..P.P.../......../RNBQKBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            foreach (var fm in AllBishopMovesForQueen(Fm))
            {
                Assert.IsFalse(Moves.CanMove(fm));
            }
        }
示例#22
0
        public void CanMoveKingWrongMoveTest() //Возможные перемещения короля
        {
            Board Board = new Board("rnbqkbnr/pppppppp/......../....K.../......../......../PPPPPPPP/RNBQPBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            foreach (var fm in AllKingMoves(Fm))
            {
                Assert.IsTrue(Moves.CanMove(fm));
            }
        }
示例#23
0
        public void CanMoveKnightBeatTeamFigureTest()//Попытка коня атаковать дружеские фигуры
        {
            Board Board = new Board("rnbqkbnr/pppppppp/PPPPPPPP/PPPPPPPP/PPNPPPPP/PPPPPPPP/PPPPPPPP/RNBQKBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            foreach (var fm in AllKnightMoves(Fm))
            {
                Assert.IsFalse(Moves.CanMove(fm));
            }
        }
示例#24
0
        public void CanMoveKnightMoveTest() //Перемещение коня
        {
            Board Board = new Board("rnbqkbnr/......../......../......../..N...../......../......../RNBQKBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            foreach (var fm in AllKnightMoves(Fm))
            {
                Assert.IsTrue(Moves.CanMove(fm));
            }
        }
示例#25
0
        public void CanMoveKingBeatFigureTest()//Атака фигуры
        {
            Board Board = new Board("rnbqkbnr/pppppppp/pppppppp/ppppKppp/pppppppp/pppppppp/PPPPPPPP/RNBQPBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            foreach (var fm in AllKingMoves(Fm))
            {
                Assert.IsTrue(Moves.CanMove(fm));
            }
        }
示例#26
0
        public void CanMoveLikeRookRightMoveTest()//Перемещение ферзя, выполняя ход как ладья
        {
            Board Board = new Board("rnbqkbnr/pppppppp/......../......../......../Q......./.PPPPPPP/RNB.KBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            Fm.GetCellsAndFigures("Qa3a4");//По вертикали
            Assert.IsTrue(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("Qa3b3");//По горизонтали
            Assert.IsTrue(Moves.CanMove(Fm));
        }
示例#27
0
        public void CanMoveLikeRookBeatFigureTest()//Атака вражеских фигур ферзем, выполняя ход как ладья
        {
            Board Board = new Board("rnbqkbnr/pppppppp/......../......../......../Q....p../.PPPPPPP/RNB.KBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            Fm.GetCellsAndFigures("Qa3a7");//По вертикали
            Assert.IsTrue(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("Qa3f3");//По горизонтали
            Assert.IsTrue(Moves.CanMove(Fm));
        }
示例#28
0
        public void CanMoveBeatFigureTest()//Атака фигуры
        {
            Board Board = new Board("rnbqkbnr/pppppppp/......../p.p...../.P....../......../PPPPPPPP/RNBQKBNR");
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            Fm.GetCellsAndFigures("Pb4a5");//Налево
            Assert.IsTrue(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("Pb4c5");//Направо
            Assert.IsTrue(Moves.CanMove(Fm));
        }
示例#29
0
        public void CanMoveRightMoveBlackOneStepTest()//Правильное перещение черных
        {
            Board Board = new Board(Fen);
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            Fm.GetCellsAndFigures("pa7a6");//На 1 ход вперед
            Assert.IsTrue(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("pa7a5");//На 2 хода вперед
            Assert.IsTrue(Moves.CanMove(Fm));
        }
示例#30
0
        public void CanMoveRightMoveWhiteOneStepTest()//Правильное перемещение белых
        {
            Board Board = new Board(Fen);
            Moves Moves = new Moves(Board);

            FigureMoving Fm = new FigureMoving(Board);

            Fm.GetCellsAndFigures("Pa2a3");//На 1 ход вперед
            Assert.IsTrue(Moves.CanMove(Fm));

            Fm.GetCellsAndFigures("Pa2a4");//На 2 хода вперед
            Assert.IsTrue(Moves.CanMove(Fm));
        }