public void BlackBishopTest() { //a - arange var board = new Board(); var bishop = new FigureBishop(Side.BLACK); var knight = new FigureKnight(Side.WHITE); var rook = new FigureRook(Side.WHITE); var queen = new FigureQueen(Side.WHITE); var pawn = new FigurePawn(Side.WHITE); board["e5"] = bishop; board["c3"] = knight; board["c7"] = rook; board["g3"] = pawn; board["g7"] = queen; //a - act var map = new AttackMap(new List<Move>(), board); //a - assert var validCells = new List<string> { "f6","g7", "d4","c3", "d6","c7", "f4","g3" }; for (var j = 1; j <= Board.BoardSize; j++) { for (var i = 'a'; i <= 'h'; i++) { var cell = i.ToString(CultureInfo.InvariantCulture) + j; if (validCells.Contains(cell)) { Assert.IsTrue(map[cell].Contains(bishop)); } else { Assert.IsFalse(map[cell].Contains(bishop)); } } } }
public void SimpleKnightTest() { //a - arange var board = new Board(); var knight = new FigureKnight(Side.WHITE); board["e4"] = knight; //a - act var map = new AttackMap(new List<Move>(), board); //a - assert Assert.IsTrue(map["f6"].Contains(knight)); Assert.IsTrue(map["g5"].Contains(knight)); Assert.IsTrue(map["g3"].Contains(knight)); Assert.IsTrue(map["f2"].Contains(knight)); Assert.IsTrue(map["d2"].Contains(knight)); Assert.IsTrue(map["c3"].Contains(knight)); Assert.IsTrue(map["c5"].Contains(knight)); Assert.IsTrue(map["d6"].Contains(knight)); }
public void LongCastlingBlackTest4() { //a - arange var board = new Board(); var king = new FigureKing(Side.BLACK); var rook = new FigureRook(Side.BLACK); var knight = new FigureKnight(Side.WHITE); board["e8"] = king; board["a8"] = rook; board["d6"] = knight; //a - act var moves = new List<Move>{ new Move { From = "c8", To = "d6" }}; var map = new AttackMap(moves, board); //a - assert Assert.IsFalse(map["c8"].Contains(king)); }
public void IsMateWhiteTest() { //a - arange var board = new Board(); board["a1"] = new FigureKing(Side.WHITE); board["a2"] = new FigurePawn(Side.WHITE); board["b1"] = new FigureRook(Side.WHITE); board["b2"] = new FigureBishop(Side.WHITE); board["c2"] = new FigureKnight(Side.BLACK); //a - act var map = new AttackMap(new List<Move>(), board); //a - assert Assert.IsTrue(map.IsMateWhite); }
public void BlackRookVsBlackTest() { //a - arange var board = new Board(); var rook = new FigureRook(Side.BLACK); var knight = new FigureKnight(Side.BLACK); var queen = new FigureQueen(Side.BLACK); var bishop = new FigureBishop(Side.BLACK); var rook2 = new FigureRook(Side.BLACK); board["e4"] = rook; board["e2"] = rook2; board["e6"] = knight; board["f4"] = queen; board["b4"] = bishop; //a - act var map = new AttackMap(new List<Move>(), board); //a - assert for (var j = 1; j <= Board.BoardSize; j++) { if (j != 4 && j < 6 && j > 2) Assert.IsTrue(map["e" + j].Contains(rook)); if (j >= 6 && j < 2) Assert.IsTrue(!map["e" + j].Contains(rook)); } for (var i = 'a'; i <= 'h'; i++) { if (i != 'e' && i < 'f' && i > 'b') Assert.IsTrue(map[i.ToString(CultureInfo.InvariantCulture) + 4].Contains(rook)); } }
public void BlackRookTest() { //a - arange var board = new Board(); var rook = new FigureRook(Side.BLACK); var knight = new FigureKnight(Side.WHITE); var bishop = new FigureBishop(Side.WHITE); var pawn = new FigurePawn(Side.WHITE); var queen = new FigureQueen(Side.WHITE); board["e4"] = rook; board["e3"] = knight; board["e5"] = bishop; board["d4"] = pawn; board["f4"] = queen; //a - act var map = new AttackMap(new List<Move>(), board); for (var i = 'a'; i <= 'h'; i++) { for (var j = 1; j <= Board.BoardSize; j++) { if (j == 4) { if (i == 'f' || i == 'd') Assert.IsTrue(map[i.ToString(CultureInfo.InvariantCulture) + j].Contains(rook)); if (i == 'e') Assert.IsTrue(!map[i.ToString(CultureInfo.InvariantCulture) + j].Contains(rook)); } else if (j == 3 || j == 5) { if (i == 'e') Assert.IsTrue(map[i.ToString(CultureInfo.InvariantCulture) + j].Contains(rook)); } else Assert.IsTrue(!map[i.ToString(CultureInfo.InvariantCulture) + j].Contains(rook)); } } }
public void BlackQueenVsWhiteTest() { //a - arange var board = new Board(); var knight = new FigureKnight(Side.WHITE); var rook = new FigureRook(Side.WHITE); var queen2 = new FigureQueen(Side.WHITE); var pawn = new FigurePawn(Side.WHITE); var queen = new FigureQueen(Side.BLACK); board["d1"] = rook; board["d8"] = rook; board["h4"] = knight; board["a4"] = queen2; //Диагональ board["d4"] = queen; board["a1"] = knight; board["a7"] = rook; board["g1"] = pawn; board["h8"] = queen2; //a - act var map = new AttackMap(new List<Move>(), board); //a - assert var validCells = new List<string> { "e3","f2", "g1","c5", "b6","a7", "c3","b2", "a1","e5", "f6","g7", "h8", "d3","d2","d1", "d5","d6","d7","d8", "e4","f4","g4","h4", "c4","b4","a4" }; for (var j = 1; j <= Board.BoardSize; j++) { for (var i = 'a'; i <= 'h'; i++) { var cell = i.ToString(CultureInfo.InvariantCulture) + j; if (validCells.Contains(cell)) { Assert.IsTrue(map[cell].Contains(queen)); } else { Assert.IsFalse(map[cell].Contains(queen)); } } } }
public void WhiteKnightTest() { //a - arange var board = new Board(); var knight = new FigureKnight(Side.WHITE); var rook = new FigureRook(Side.BLACK); var bishop = new FigureBishop(Side.BLACK); var queen = new FigureQueen(Side.BLACK); var queen1 = new FigureQueen(Side.WHITE); var bishop1 = new FigureBishop(Side.BLACK); board["e4"] = knight; board["f6"] = queen1; board["g5"] = bishop1; board["g3"] = bishop; board["f3"] = rook; board["d2"] = queen; //a - act var map = new AttackMap(new List<Move>(), board); //a - assert Assert.IsTrue(!map["f6"].Contains(knight)); Assert.IsTrue(map["g5"].Contains(knight)); Assert.IsTrue(map["g3"].Contains(knight)); Assert.IsTrue(map["f2"].Contains(knight)); Assert.IsTrue(map["d2"].Contains(knight)); Assert.IsTrue(map["c3"].Contains(knight)); Assert.IsTrue(map["c5"].Contains(knight)); Assert.IsTrue(map["d6"].Contains(knight)); Assert.IsTrue(!map["h6"].Contains(knight)); }
public void InitialPosition() { Cells[0, 0] = new FigureRook(Side.WHITE); Cells[1, 0] = new FigureKnight(Side.WHITE); Cells[2, 0] = new FigureBishop(Side.WHITE); Cells[3, 0] = new FigureQueen(Side.WHITE); Cells[4, 0] = new FigureKing(Side.WHITE); Cells[5, 0] = new FigureBishop(Side.WHITE); Cells[6, 0] = new FigureKnight(Side.WHITE); Cells[7, 0] = new FigureRook(Side.WHITE); for (int i = 0; i < BoardSize; i++) { Cells[i, 1] = new FigurePawn(Side.WHITE); } //FillEmptyCells(0, BoardSize, 2, BoardSize - 2); for (int i = 0; i < BoardSize; i++) { Cells[i, 6] = new FigurePawn(Side.BLACK); } Cells[0, 7] = new FigureRook(Side.BLACK); Cells[1, 7] = new FigureKnight(Side.BLACK); Cells[2, 7] = new FigureBishop(Side.BLACK); Cells[3, 7] = new FigureQueen(Side.BLACK); Cells[4, 7] = new FigureKing(Side.BLACK); Cells[5, 7] = new FigureBishop(Side.BLACK); Cells[6, 7] = new FigureKnight(Side.BLACK); Cells[7, 7] = new FigureRook(Side.BLACK); }