/// <summary> /// Checks the movement rule of queens to see if a grid can be moved to or not. /// </summary> /// <returns><c>true</c>movement to the destination grid is possible<c>false</c> otherwise.</returns> /// <param name="grid">The destination grid</param> /// <param name="cb">the Chessboard currently used</param> public override bool CheckMovementRule(Grid grid, ChessBoard cb) { if (!CheckDestinationPieceColour (grid)) return false; if (IsDestinationSameGrid (grid)) return false; //Checks the case of the destination grid. //The destination has to be either directly horizontal, vertical, or diagonal to the queen piece, else returns false if (grid.Y == this.Grid.Y) { return CheckVertical (grid, cb); } else if (grid.X == this.Grid.X) { return CheckHorizontal (grid, cb); } else if (Math.Abs (grid.X - this.Grid.X) == Math.Abs (grid.Y - this.Grid.Y)) { return CheckDiagonal (grid, cb); } else { return false; } }
public void TestCapturePossibility() { ChessBoard cb = new ChessBoard (); Bishop bsh = new Bishop (cb [4, 4], "B"); cb [4, 4].PlacePiece (bsh); //Check attempt to capture same color piece cb [1, 1].PlacePiece (new Bishop(cb[1, 1], "B")); cb [6, 6].PlacePiece (new Bishop(cb[6, 6], "B")); cb [2, 6].PlacePiece (new Bishop(cb[2, 6], "B")); cb [6, 2].PlacePiece (new Bishop(cb[6, 2], "B")); Assert.IsFalse (bsh.CheckMovementRule (cb [1, 1], cb)); Assert.IsFalse(bsh.CheckMovementRule (cb [6, 6], cb)); Assert.IsFalse (bsh.CheckMovementRule (cb [2, 6], cb)); Assert.IsFalse (bsh.CheckMovementRule (cb [6, 2], cb)); //Check attempt to capture different color piece cb [1, 1].PlacePiece (new Bishop(cb[1, 1], "W")); cb [6, 6].PlacePiece (new Bishop(cb[6, 6], "W")); cb [2, 6].PlacePiece (new Bishop(cb[2, 6], "W")); cb [6, 2].PlacePiece (new Bishop(cb[6, 2], "W")); Assert.IsTrue (bsh.CheckMovementRule (cb [1, 1], cb)); Assert.IsTrue(bsh.CheckMovementRule (cb [6, 6], cb)); Assert.IsTrue (bsh.CheckMovementRule (cb [2, 6], cb)); Assert.IsTrue (bsh.CheckMovementRule (cb [6, 2], cb)); }
public void TestCapture() { ChessBoard cb = new ChessBoard (); Rook rk = new Rook (cb [3, 3], "B"); cb [3, 3].PlacePiece (rk); //Test capture failure - piece of the same color cb [2, 3].PlacePiece (new Rook (cb [2, 3], "B")); Assert.IsFalse (rk.CheckMovementRule (cb[2, 3], cb)); cb [4, 3].PlacePiece (new Rook (cb [4, 3], "B")); Assert.IsFalse (rk.CheckMovementRule (cb [4, 3], cb)); cb [3, 2].PlacePiece (new Rook (cb [3, 2], "B")); Assert.IsFalse (rk.CheckMovementRule (cb [3, 2], cb)); cb [3, 4].PlacePiece (new Rook (cb [3, 4], "B")); Assert.IsFalse (rk.CheckMovementRule (cb[3, 4], cb)); //Test capture failure - piece of different color cb [2, 3].PlacePiece (new Rook (cb [2, 3], "W")); Assert.IsTrue (rk.CheckMovementRule (cb[2, 3], cb)); cb [4, 3].PlacePiece (new Rook (cb [4, 3], "W")); Assert.IsTrue (rk.CheckMovementRule (cb [4, 3], cb)); cb [3, 2].PlacePiece (new Rook (cb [3, 2], "W")); Assert.IsTrue (rk.CheckMovementRule (cb [3, 2], cb)); cb [3, 4].PlacePiece (new Rook (cb [3, 4], "W")); Assert.IsTrue (rk.CheckMovementRule (cb[3, 4], cb)); }
public void TestIfDestinationIsSameGrid() { ChessBoard cb = new ChessBoard (); Bishop cpb = new Bishop (cb [4, 4], "B"); Assert.IsTrue (cpb.IsDestinationSameGrid(cb[4, 4])); Assert.IsFalse (cpb.IsDestinationSameGrid(cb[4, 5])); }
public void TestIfPieceisMoved() { ChessBoard cb = new ChessBoard (); Bishop cpb = new Bishop (cb [4, 4], "B"); cpb.MovePiece (cb [5, 5], cb); Assert.AreEqual (cb [5, 5], cpb.Grid); }
public void TestMovementRule() { ChessBoard cb = new ChessBoard (); Pawn testPiece = new Pawn (cb [3, 2], "B"); cb [3, 2].PlacePiece(testPiece); Assert.IsFalse (testPiece.CheckMovementRule (cb [3, 2], cb)); }
public void RookMovementTests() { ChessBoard cb = new ChessBoard (); Rook rk = new Rook (cb [1, 3], "B"); cb [1, 3].PlacePiece (rk); Assert.IsTrue(rk.CheckMovementRule (cb [1, 4], cb)); Assert.IsFalse (rk.CheckMovementRule (cb [1, 0], cb)); }
public void TestPiecePlayer() { ChessBoard cb = new ChessBoard (); Bishop cpb = new Bishop (cb [4, 4], "B"); King cpk = new King (cb [3, 3], "W"); Assert.AreEqual ("B", cpb.Player); Assert.AreEqual ("W", cpk.Player); }
public void TestPieceVerticalPath() { ChessBoard cb = new ChessBoard (); Bishop cpb = new Bishop (cb [4, 4], "B"); King cpk = new King (cb [3, 3], "W"); Assert.IsTrue (cpb.CheckHorizontal(cb[3, 2], cb)); Assert.IsTrue (cpk.CheckVertical(cb[0, 0], cb)); }
public void TestPieceName() { ChessBoard cb = new ChessBoard (); Bishop cpb = new Bishop (cb [4, 4], "B"); King cpk = new King (cb [3, 3], "W"); Assert.AreEqual ("BB", cpb.Name); Assert.AreEqual ("WKG", cpk.Name); }
/// <summary> /// Checks the movement rule of kings to see if a grid can be moved to or not. /// </summary> /// <returns><c>true</c>movement to the destination grid is possible<c>false</c> otherwise.</returns> /// <param name="grid">The destination grid</param> /// <param name="cb">the Chessboard currently used</param> public override bool CheckMovementRule(Grid grid, ChessBoard cb) { if (!CheckDestinationPieceColour (grid)) return false; if (IsDestinationSameGrid (grid)) return false; //Checks if both of the X and Y coordinates of the destination is only less thab 1 unit different from the current grid if (Math.Abs (grid.X - this.Grid.X) <= 1 && Math.Abs (grid.Y - this.Grid.Y) <= 1) return true; return false; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.IsMouseVisible = true; base.Initialize(); Global.Init(); this.board = new ChessBoard(); }
public void TestPathCheck() { ChessBoard cb = new ChessBoard (); Bishop bsh = new Bishop (cb [4, 4], "B"); cb [4, 4].PlacePiece (bsh); Assert.IsTrue (bsh.CheckDiagonal (cb [1, 1], cb)); Assert.IsTrue (bsh.CheckDiagonal (cb [6, 6], cb)); Assert.IsTrue (bsh.CheckDiagonal (cb [2, 6], cb)); Assert.IsTrue (bsh.CheckDiagonal (cb [6, 2], cb)); }
public void TestPieceGrid() { ChessBoard cb = new ChessBoard (); Bishop cpb = new Bishop (cb [4, 4], "B"); King cpk = new King (cb [3, 3], "W"); cpk.MovePiece(cb[3, 4], cb); cpk.MovePiece(cb[6, 6], cb); Assert.AreEqual (cb[4, 4], cpb.Grid); Assert.AreEqual (cb[3, 4], cpk.Grid); }
public void TestRookMovement() { ChessBoard cb = new ChessBoard (); Rook rk = new Rook (cb [3, 1], "B"); cb [3, 1].PlacePiece (rk); Assert.IsTrue(rk.CheckMovementRule (cb [4, 1], cb)); Assert.IsFalse (rk.CheckMovementRule (cb [0, 3], cb)); Assert.AreEqual (rk.MovePiece (cb [0, 3], cb), "Invalid move"); Assert.AreNotSame (rk.Grid, cb [0, 3]); Assert.IsNull(rk.MovePiece (cb [4, 1], cb)); Assert.AreSame (rk.Grid, cb [4, 1]); }
public void TestKnightInvalidMovement() { ChessBoard cb = new ChessBoard (); Knight kn = new Knight (cb [4, 4], "B"); cb [4, 4].PlacePiece (kn); Assert.IsFalse(kn.CheckMovementRule(cb[3,3], cb)); Assert.IsFalse(kn.CheckMovementRule(cb[7,7], cb)); Assert.IsFalse(kn.CheckMovementRule(cb[4, 3], cb)); Assert.AreEqual (kn.MovePiece (cb [4, 3], cb), "Invalid move"); Assert.AreNotSame (kn.Grid, cb [4, 3]); Assert.AreSame (kn.Grid, cb [4, 4]); }
public void TestKingCaptureRule() { ChessBoard cb = new ChessBoard (); King kg = new King (cb [4, 4], "B"); cb [4, 4].PlacePiece (kg); //Create piece cases within range cb[5, 4].PlacePiece(new King(cb[5, 4], "B")); cb [5, 5].PlacePiece (new King (cb [5, 5], "W")); //Check whether the pieces can be captured or not. Assert.IsFalse(kg.CheckMovementRule(cb[5,4], cb)); Assert.IsTrue (kg.CheckMovementRule (cb [5, 5], cb)); }
/// <summary> /// Checks the movement rules of bishops to see if a grid can be moved to or not. /// </summary> /// <returns><c>true</c>movement to the destination grid is possible<c>false</c> otherwise.</returns> /// <param name="grid">The destination grid</param> /// <param name="cb">the Chessboard currently used</param> public override bool CheckMovementRule(Grid grid, ChessBoard cb) { if (!CheckDestinationPieceColour (grid)) return false; if (IsDestinationSameGrid (grid)) return false; //Checks if the path is diagonal or not. Immediately returns false if invalid if (Math.Abs (grid.X - this.Grid.X) == Math.Abs (grid.Y - this.Grid.Y)) { return CheckDiagonal (grid, cb); } else return false; }
public void TestMovement() { ChessBoard cb = new ChessBoard (); Pawn testPiece = new Pawn (cb [3, 1], "B"); cb [3, 1].PlacePiece(testPiece); Assert.AreEqual (testPiece.MovePiece (cb [4, 2], cb), "Invalid move"); Assert.IsNull (testPiece.MovePiece (cb [3, 2],cb)); Assert.AreSame (testPiece.Grid, cb [3, 2]); Assert.IsNull (testPiece.MovePiece (cb [3, 3], cb)); Pawn testPiece2 = new Pawn (cb [4, 4], "W"); cb [4, 4].PlacePiece(testPiece2); Assert.IsNull (testPiece.MovePiece (cb [4, 4], cb)); }
public void TestMovement() { ChessBoard cb = new ChessBoard (); Bishop bsh = new Bishop (cb [4, 4], "B"); cb [4, 4].PlacePiece (bsh); //Test correct movement Assert.IsTrue(bsh.CheckMovementRule (cb [6, 6], cb)); Assert.IsNull (bsh.MovePiece (cb [6, 6], cb)); Assert.AreSame (bsh.Grid, cb [6, 6]); //Test invalid movement Assert.IsFalse (bsh.CheckMovementRule (cb[4, 3], cb)); Assert.AreEqual (bsh.MovePiece (cb [4, 3], cb), "Invalid move"); Assert.AreSame (bsh.Grid, cb [6, 6]); }
public void TestKingMovement() { ChessBoard cb = new ChessBoard (); King kg = new King (cb [4, 4], "B"); cb [4, 4].PlacePiece (kg); //Test invalid movement Assert.IsFalse(kg.CheckMovementRule(cb[6,7], cb)); Assert.AreEqual(kg.MovePiece(cb[6, 7], cb), "Invalid move"); Assert.AreSame (kg.Grid, cb [4, 4]); //Test valid movement Assert.IsTrue (kg.CheckMovementRule (cb [3, 5], cb)); Assert.IsNull (kg.MovePiece (cb [3, 5], cb)); Assert.AreSame (kg.Grid, cb [3, 5]); }
public void TestPathBlock() { ChessBoard cb = new ChessBoard (); Bishop bsh = new Bishop (cb [4, 4], "B"); cb [4, 4].PlacePiece (bsh); //Create obstructions cb [3, 3].PlacePiece (new Bishop(cb[3, 3], "B")); cb [5, 5].PlacePiece (new Bishop(cb[5, 5], "B")); cb [3, 5].PlacePiece (new Bishop(cb[3, 5], "W")); cb [5, 3].PlacePiece (new Bishop(cb[5, 3], "W")); Assert.IsFalse (bsh.CheckDiagonal (cb [1, 1], cb)); Assert.IsFalse(bsh.CheckDiagonal (cb [6, 6], cb)); Assert.IsFalse (bsh.CheckDiagonal (cb [2, 6], cb)); Assert.IsFalse (bsh.CheckDiagonal (cb [6, 2], cb)); }
public void TestKnightMovementOnEmpty() { ChessBoard cb = new ChessBoard (); Knight kn = new Knight (cb [4, 4], "B"); cb [4, 4].PlacePiece (kn); Assert.IsTrue(kn.CheckMovementRule(cb[6, 5], cb)); Assert.IsTrue(kn.CheckMovementRule(cb[5, 6], cb)); Assert.IsTrue(kn.CheckMovementRule(cb[3, 2], cb)); Assert.IsTrue(kn.CheckMovementRule(cb[2, 3], cb)); Assert.IsTrue(kn.CheckMovementRule(cb[3, 6], cb)); Assert.IsTrue(kn.CheckMovementRule(cb[6, 3], cb)); Assert.IsTrue(kn.CheckMovementRule(cb[2, 5], cb)); Assert.IsTrue(kn.CheckMovementRule(cb[5, 2], cb)); Assert.IsNull (kn.MovePiece (cb [5, 2], cb)); Assert.AreEqual (kn.Grid, cb [5, 2]); }
public void TestHorizontalPathChecking() { ChessBoard cb = new ChessBoard (); Rook rk = new Rook (cb [3, 3], "B"); cb [3, 3].PlacePiece (rk); //Test valid path Assert.IsTrue (rk.CheckHorizontal (cb[3, 6], cb)); Assert.IsTrue (rk.CheckHorizontal (cb[3, 1], cb)); //Test White piece path block cb [3, 2].PlacePiece (new Rook (cb [3, 2], "W")); Assert.IsFalse (rk.CheckHorizontal (cb[3, 1], cb)); cb [3, 4].PlacePiece (new Rook (cb [3, 4], "W")); Assert.IsFalse (rk.CheckHorizontal (cb [3, 6], cb)); //Test Black piece path block cb [3, 4].PlacePiece (new Rook (cb [3, 4], "B")); Assert.IsFalse (rk.CheckHorizontal (cb [3, 6], cb)); cb [3, 2].PlacePiece (new Rook (cb [3, 2], "B")); Assert.IsFalse (rk.CheckHorizontal (cb[3, 1], cb)); }
public void TestKingMovementRuleOnEmptyGrids() { ChessBoard cb = new ChessBoard (); King kg = new King (cb [4, 4], "B"); cb [4, 4].PlacePiece (kg); //Check all possible movements Assert.IsTrue (kg.CheckMovementRule (cb [5, 4], cb)); Assert.IsTrue (kg.CheckMovementRule (cb [5, 5], cb)); Assert.IsTrue (kg.CheckMovementRule (cb [5, 3], cb)); Assert.IsTrue (kg.CheckMovementRule (cb [4, 3], cb)); Assert.IsTrue (kg.CheckMovementRule (cb [4, 5], cb)); Assert.IsTrue (kg.CheckMovementRule (cb [3, 3], cb)); Assert.IsTrue (kg.CheckMovementRule (cb [3, 4], cb)); Assert.IsTrue (kg.CheckMovementRule (cb [3, 5], cb)); //Check some invalid movements Assert.IsFalse (kg.CheckMovementRule (cb [6, 6], cb)); Assert.IsFalse (kg.CheckMovementRule (cb [4, 6], cb)); Assert.IsFalse (kg.CheckMovementRule (cb [6, 4], cb)); }
public void TestVerticalPathChecking() { ChessBoard cb = new ChessBoard (); Rook rk = new Rook (cb [3, 3], "B"); cb [3, 3].PlacePiece (rk); //Test Valid path Assert.IsTrue (rk.CheckVertical (cb[6, 3], cb)); Assert.IsTrue (rk.CheckVertical(cb[1, 3], cb)); //Test White piece path block cb [2, 3].PlacePiece (new Rook (cb [2, 3], "W")); Assert.IsFalse (rk.CheckVertical (cb[1, 3], cb)); cb [4, 3].PlacePiece (new Rook (cb [4, 3], "W")); Assert.IsFalse (rk.CheckVertical (cb [6, 3], cb)); //Test Black piece path block cb [4, 3].PlacePiece (new Rook (cb [4, 3], "B")); Assert.IsFalse (rk.CheckVertical (cb [6, 3], cb)); cb [2, 3].PlacePiece (new Rook (cb [2, 3], "B")); Assert.IsFalse (rk.CheckVertical (cb[1, 3], cb)); }
public void TestKnightMovementOnGridWithEnemyPiece() { ChessBoard cb = new ChessBoard (); Knight kn = new Knight (cb [4, 4], "B"); cb [4, 4].PlacePiece (kn); cb [6, 5].PlacePiece (new Knight (cb [6, 5], "W")); Assert.IsTrue(kn.CheckMovementRule(cb[6, 5], cb)); cb [5, 6].PlacePiece (new Knight (cb [5, 6], "W")); Assert.IsTrue(kn.CheckMovementRule(cb[5, 6], cb)); cb [3, 2].PlacePiece (new Knight (cb [3, 2], "W")); Assert.IsTrue(kn.CheckMovementRule(cb[3, 2], cb)); cb [2, 3].PlacePiece (new Knight (cb [2, 3], "W")); Assert.IsTrue(kn.CheckMovementRule(cb[2, 3], cb)); cb [3, 6].PlacePiece (new Knight (cb [3, 6], "W")); Assert.IsTrue(kn.CheckMovementRule(cb[3, 6], cb)); cb [6, 3].PlacePiece (new Knight (cb [6, 3], "W")); Assert.IsTrue(kn.CheckMovementRule(cb[6, 3], cb)); cb [2, 5].PlacePiece (new Knight (cb [2, 5], "W")); Assert.IsTrue(kn.CheckMovementRule(cb[2, 5], cb)); cb [5, 2].PlacePiece (new Knight (cb [5, 2], "W")); Assert.IsTrue(kn.CheckMovementRule(cb[5, 2], cb)); }
/// <summary> /// Checks the movement rule of rooks to see if a grid can be moved to or not. /// </summary> /// <returns><c>true</c>movement to the destination grid is possible<c>false</c> otherwise.</returns> /// <param name="grid">The destination grid</param> /// <param name="cb">the Chessboard currently used</param> public override bool CheckMovementRule(Grid grid, ChessBoard cb) { if (!CheckDestinationPieceColour (grid)) return false; if (IsDestinationSameGrid (grid)) return false; //The path is vertical if (grid.Y == this.Grid.Y) { return CheckVertical (grid, cb); } //The path is horizontal else if (grid.X == this.Grid.X) { return CheckHorizontal (grid, cb); } //The path is invalid else { return false; } }
/// <summary> /// Checks the movement rules of knights to see if a grid can be moved to or not. /// </summary> ///<returns><c>true</c>movement to the destination grid is possible<c>false</c> otherwise.</returns> /// <param name="grid">The destination grid</param> /// <param name="cb">the Chessboard currently used</param> public override bool CheckMovementRule(Grid grid, ChessBoard cb) { if (!CheckDestinationPieceColour (grid)) return false; if (IsDestinationSameGrid (grid)) return false; if (Math.Abs (grid.X - this.Grid.X) == 1) { if (Math.Abs (grid.Y - this.Grid.Y) == 2) return true; return false; } else if (Math.Abs (grid.Y - this.Grid.Y) == 1) { if (Math.Abs (grid.X - this.Grid.X) == 2) return true; return false; } else { return false; } }
public Tower(ChessBoard chessBoard, Color color) : base(chessBoard, color) { }
private void LoadBoard() { PictureBox[,] pictureBoxes = new PictureBox[8, 8]; pictureBoxes[0, 0] = pictureBox1; pictureBoxes[0, 1] = pictureBox2; pictureBoxes[0, 2] = pictureBox3; pictureBoxes[0, 3] = pictureBox4; pictureBoxes[0, 4] = pictureBox5; pictureBoxes[0, 5] = pictureBox6; pictureBoxes[0, 6] = pictureBox7; pictureBoxes[0, 7] = pictureBox8; pictureBoxes[1, 0] = pictureBox9; pictureBoxes[1, 1] = pictureBox10; pictureBoxes[1, 2] = pictureBox11; pictureBoxes[1, 3] = pictureBox12; pictureBoxes[1, 4] = pictureBox13; pictureBoxes[1, 5] = pictureBox14; pictureBoxes[1, 6] = pictureBox15; pictureBoxes[1, 7] = pictureBox16; pictureBoxes[2, 0] = pictureBox17; pictureBoxes[2, 1] = pictureBox18; pictureBoxes[2, 2] = pictureBox19; pictureBoxes[2, 3] = pictureBox20; pictureBoxes[2, 4] = pictureBox21; pictureBoxes[2, 5] = pictureBox22; pictureBoxes[2, 6] = pictureBox23; pictureBoxes[2, 7] = pictureBox24; pictureBoxes[3, 0] = pictureBox25; pictureBoxes[3, 1] = pictureBox26; pictureBoxes[3, 2] = pictureBox27; pictureBoxes[3, 3] = pictureBox28; pictureBoxes[3, 4] = pictureBox29; pictureBoxes[3, 5] = pictureBox30; pictureBoxes[3, 6] = pictureBox31; pictureBoxes[3, 7] = pictureBox32; pictureBoxes[4, 0] = pictureBox33; pictureBoxes[4, 1] = pictureBox34; pictureBoxes[4, 2] = pictureBox35; pictureBoxes[4, 3] = pictureBox36; pictureBoxes[4, 4] = pictureBox37; pictureBoxes[4, 5] = pictureBox38; pictureBoxes[4, 6] = pictureBox39; pictureBoxes[4, 7] = pictureBox40; pictureBoxes[5, 0] = pictureBox41; pictureBoxes[5, 1] = pictureBox42; pictureBoxes[5, 2] = pictureBox43; pictureBoxes[5, 3] = pictureBox44; pictureBoxes[5, 4] = pictureBox45; pictureBoxes[5, 5] = pictureBox46; pictureBoxes[5, 6] = pictureBox47; pictureBoxes[5, 7] = pictureBox48; pictureBoxes[6, 0] = pictureBox49; pictureBoxes[6, 1] = pictureBox50; pictureBoxes[6, 2] = pictureBox51; pictureBoxes[6, 3] = pictureBox52; pictureBoxes[6, 4] = pictureBox53; pictureBoxes[6, 5] = pictureBox54; pictureBoxes[6, 6] = pictureBox55; pictureBoxes[6, 7] = pictureBox56; pictureBoxes[7, 0] = pictureBox57; pictureBoxes[7, 1] = pictureBox58; pictureBoxes[7, 2] = pictureBox59; pictureBoxes[7, 3] = pictureBox60; pictureBoxes[7, 4] = pictureBox61; pictureBoxes[7, 5] = pictureBox62; pictureBoxes[7, 6] = pictureBox63; pictureBoxes[7, 7] = pictureBox64; b = new ChessBoard(pictureBoxes); }
public override ChessSquare[] GetSquares() { ChessBoard b = ChessBoard.GetBoard(); return(null); }
public Horse(ChessBoard chessBoard, Color color) : base(chessBoard, color) { }
public TestChessPiece() { ChessBoard cb = new ChessBoard (); //ChessPiece cp = new ChessPiece (cb [4, 4], "B", "B) }
public Pawn(ChessBoard chessBoard, Color color) : base(chessBoard, color) { }