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); }
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)); }
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); }
public void GetCellAndFigureWrongYAndXTest()//Отсутствие координаты X и Y на поле { Board Board = new Board(Fen); FigureMoving Fm = new FigureMoving(Board); Assert.ThrowsException <ArgumentException>(() => Fm.GetCellsAndFigures("nb9a9")); }
public void MoveFigureMovingIsNullTest() { Board Board = new Board(Fen); FigureMoving Fm = null; Assert.ThrowsException <NullReferenceException>(() => Board.Move(Fm)); }
public bool CanMove(FigureMoving figureMoving) { this.Fm = figureMoving; return(CanMoveFrom() && CanMoveTo() && CanFigureMove()); }
public void GetCellAndFigureNoFigureAndNegativeCoordinateYTest()//Отсутствие фигуры и отрицательная координата, но зато 5 символов { Board Board = new Board(Fen); FigureMoving Fm = new FigureMoving(Board); Assert.ThrowsException <ArgumentException>(() => Fm.GetCellsAndFigures("b1a-2")); }
public void GetCellAndFigureSymbolsMoreThan5Test()//Параметр имеет больше 5 символов { Board Board = new Board(Fen); FigureMoving Fm = new FigureMoving(Board); Assert.ThrowsException <ArgumentException>(() => Fm.GetCellsAndFigures("nb-1a2")); }
public void GetCellAndFigureWrongFigureTest()//Неправильная фигура на начальной клетке { Board Board = new Board(Fen); FigureMoving Fm = new FigureMoving(Board); Assert.ThrowsException <ArgumentException>(() => Fm.GetCellsAndFigures("ra1a2")); }
public void GetCellAndFigureNoFigureTest()//Отсутствие фигуры в параметре, параметр меньше 5 символов { Board Board = new Board(Fen); FigureMoving Fm = new FigureMoving(Board); Assert.ThrowsException <ArgumentException>(() => Fm.GetCellsAndFigures("a1a2")); }
public bool CanMove(FigureMoving fm) { this.fm = fm; return (CanMoveFrom() && CanMoveTo() && CanFigureMove()); }
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); }
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)); }
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)); }
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)); }
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);//Поле никак не изменилось, хода не был сделан }
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)); } }
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)); } }
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)); } }
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)); } }
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)); } }
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)); } }
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)); } }
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)); } }
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)); } }
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)); }
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)); }
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)); }
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)); }
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)); }