public void TestValidPawnMovesDiagonal_l_1() { Game.Board b = new Game.Board("RNBKQBNR\nPPPPPPPP\n.p......\np.......\n........\n.....P..\n.ppppppp\nrnbkqbnr"); //b.BoardString = b.Initialize8x8Board(); b.BoardStringToPieces(); // TODO: actually test the method - this is just cruft trying to set up for the real test while switching notations Game.Piece p = Game.GetPieceOnSquare(b, '1', '7'); Game.Piece p2 = Game.GetPieceOnSquare(b, "a7"); // same piece different method Assert.IsTrue(p == null); Assert.IsTrue(p2 == null); }
public void Test_GetAlgebraicPiecesOnSquare_InitialBoard() { Game.Board b = new Game.Board("RNBKQBNR\nPPPPPPPP\n........\n........\n........\n........\npppppppp\nrnbkqbnr"); Assert.IsTrue(b.Pieces != null); Assert.IsTrue(b.Pieces.Count == 32); Game.Piece p = Game.GetPieceOnSquare(b, "a1"); Assert.IsFalse(p == null); Assert.IsTrue(p.AlgebraicCoordinate == "a1"); Assert.IsTrue(p.type == "R"); // This is a little counter-intuitive Assert.IsTrue(p.color == "w"); }
public void TestValidPawnMovesForward_blocking() { // condition where there is a piece blocking Game.Board b = new Game.Board("RNBKQBNR\nPPPPPPPP\n........\np.......\n........\n........\n.ppppppp\nrnbkqbnr"); Assert.IsTrue(b.Pieces.Count == 32); // initial board returns a valid set of two moves -> this one should only return one Game.Piece p = Game.GetPieceOnSquare(b, '1', '2'); Assert.IsTrue(p != null); List <Point> pts = Game.ValidMoves(b, p); Assert.IsTrue(pts.Count == 1); //b.BoardStringToPieces(); }
public void GeneratePawnsOnABoard() { Game.Board b = new Game.Board(); b.Pieces = new List <Game.Piece>(); // generate eight white pawns for (int i = 0; i < 8; i++) { Game.Piece p = new Game.Piece(); p.color = "w"; p.x = (i + 1).ToString()[0]; // note this won't work for bigger boards p.y = '2'; p.moved = false; b.Pieces.Add(p); } Assert.IsTrue(b.Pieces.Count == 8); }
public void TestValidPawnMovesForward_init() { Game.Board b = new Game.Board(); b.BoardString = b.Initialize8x8Board(); b.BoardStringToPieces(); // initial board returns a valid set of two moves Game.Piece p = Game.GetPieceOnSquare(b, '1', '2'); Assert.IsTrue(p != null); List <Point> pts2 = Game.ValidMoves(b, p); Assert.IsTrue(pts2.Count > 0); Assert.IsTrue(pts2.Count == 2); Assert.IsTrue(pts2[0].X == 1); // first move coordinates Assert.IsTrue(pts2[0].Y == 3); Assert.IsTrue(pts2[1].X == 1); // second move coordinates Assert.IsTrue(pts2[1].Y == 4); }
public void GeneratePawns() { List <Game.Piece> pieces = new List <Game.Piece>(); // generate eight white pawns for (int i = 0; i < 8; i++) { Game.Piece p = new Game.Piece(); p.color = "w"; p.x = (i + 1).ToString()[0]; // note this won't work for bigger boards p.y = '2'; p.moved = false; pieces.Add(p); } Assert.IsTrue(pieces.Count == 8); Assert.IsTrue(pieces[0].color == "w"); Assert.IsTrue(pieces[0].x == '1'); Assert.IsTrue(pieces[0].y == '2'); Assert.IsTrue(pieces[0].moved == false); }
public void Test_GetPiecesOnSquare_InitialBoard() { Game.Board b = new Game.Board(); b.BoardString = b.Initialize8x8Board(); b.BoardStringToPieces(); Assert.IsTrue(b.Pieces != null); Assert.IsTrue(b.Pieces.Count == 32); // iterate over the board // first row string FirstRow = "RNBKQBNR"; for (int i = 1; i < 8; i++) { Game.Piece p = Game.GetPieceOnSquare(b, i.ToString()[0], '1'); Assert.IsTrue(p != null); Assert.IsTrue(p.color == "w"); Assert.IsTrue(p.type == FirstRow[i - 1].ToString()); } // second row // (all pawns) for (int i = 1; i < 8; i++) { Game.Piece p = Game.GetPieceOnSquare(b, i.ToString()[0], '2'); Assert.IsTrue(p != null); Assert.IsTrue(p.color == "w"); Assert.IsTrue(p.type == 'P'.ToString()); } // third - sixth rows have no pieces on start for (int j = 3; j < 7; j++) { for (int i = 1; i < 8; i++) { Game.Piece p = Game.GetPieceOnSquare(b, i.ToString()[0], j.ToString()[0]); Assert.IsTrue(p == null); } } // seventh row for (int i = 1; i < 8; i++) { Game.Piece p = Game.GetPieceOnSquare(b, i.ToString()[0], '7'); Assert.IsTrue(p != null); Assert.IsTrue(p.color == "b"); Assert.IsTrue(p.type == 'p'.ToString()); } // eighth row string EighthRow = "rnbkqbnr"; for (int i = 1; i < 8; i++) { Game.Piece p = Game.GetPieceOnSquare(b, i.ToString()[0], '8'); Assert.IsTrue(p != null); Assert.IsTrue(p.color == "b"); Assert.IsTrue(p.type == EighthRow[i - 1].ToString()); } }