public override bool Execute(IChessPiece[][] board, Vector2 newLocation, Vector2 curLocation) { if (!IsOnBoard(board, newLocation)) { return(false); } if (IsTeamMateInPosition(board, newLocation, board[(int)curLocation.X][(int)curLocation.Y].Color)) { return(false); } int x = (int)curLocation.X; int y = (int)curLocation.Y; int[] xNews = { x - 1, x, x + 1, x + 1, x + 1, x, x - 1, x - 1 }; int[] yNews = { y - 1, y - 1, y - 1, y, y + 1, y + 1, y + 1, y }; for (int i = 0; i < xNews.Length; i++) { if ((int)newLocation.X == xNews[i] && (int)newLocation.Y == yNews[i]) { board[(int)newLocation.X][(int)newLocation.Y] = board[x][y]; board[x][y] = new BlankPiece(); return(true); } } return(false); }
public void InitializeBoard(IChessPiece[][] board) { board[0][0] = new RookPieceBlack(); board[1][0] = new KnightPieceBlack(); board[2][0] = new BishopPieceBlack(); board[3][0] = new QueenPieceBlack(); board[4][0] = new KingPieceBlack(); board[5][0] = new BishopPieceBlack(); board[6][0] = new KnightPieceBlack(); board[7][0] = new RookPieceBlack(); board[0][7] = new RookPieceWhite(); board[1][7] = new KnightPieceWhite(); board[2][7] = new BishopPieceWhite(); board[3][7] = new QueenPieceWhite(); board[4][7] = new KingPieceWhite(); board[5][7] = new BishopPieceWhite(); board[6][7] = new KnightPieceWhite(); board[7][7] = new RookPieceWhite(); for (int i = 0; i < 8; i++) { board[i][1] = new PawnPieceBlack(); board[i][6] = new PawnPieceWhite(); board[i][2] = new BlankPiece(); board[i][3] = new BlankPiece(); board[i][4] = new BlankPiece(); board[i][5] = new BlankPiece(); } }
private bool CheckInPositionDiagonalAlt(IChessPiece[][] board, Vector2 newLocation, Vector2 curLocation) { if (Math.Abs(newLocation.X - curLocation.X) != Math.Abs(newLocation.Y - curLocation.Y)) { return(false); } int x = (int)curLocation.X; int y = (int)curLocation.Y; int xMoveInt = 0; int yMoveInt = 0; if (newLocation.X > curLocation.X && newLocation.Y > curLocation.Y) { xMoveInt = 1; yMoveInt = 1; } else if (newLocation.X > curLocation.X && newLocation.Y < curLocation.Y) { xMoveInt = 1; yMoveInt = -1; } else if (newLocation.X < curLocation.X && newLocation.Y > curLocation.Y) { xMoveInt = -1; yMoveInt = 1; } else if (newLocation.X < curLocation.X && newLocation.Y < curLocation.Y) { xMoveInt = -1; yMoveInt = -1; } int xNew = x + xMoveInt; int yNew = y + yMoveInt; while (IsOnBoard(board, new Vector2(xNew, yNew)) && board[xNew][yNew].Color == ChessPieceType.Color.Blank && !(newLocation.X == xNew && newLocation.Y == yNew)) { xNew += xMoveInt; yNew += yMoveInt; } if (newLocation.X == xNew && newLocation.Y == yNew) { board[(int)newLocation.X][(int)newLocation.Y] = board[x][y]; board[x][y] = new BlankPiece(); return(true); } return(false); }
public override bool Execute(IChessPiece[][] board, Vector2 newLocation, Vector2 curLocation) { if (!IsOnBoard(board, newLocation)) { return(false); } if (IsTeamMateInPosition(board, newLocation, board[(int)curLocation.X][(int)curLocation.Y].Color)) { return(false); } if (board[(int)curLocation.X][(int)curLocation.Y].Color == ChessPieceType.Color.Black && newLocation.Y < curLocation.Y) { return(false); } if (board[(int)curLocation.X][(int)curLocation.Y].Color == ChessPieceType.Color.White && newLocation.Y > curLocation.Y) { return(false); } int x = (int)curLocation.X; int y = (int)curLocation.Y; int[] xNewsD = { x - 1, x + 1, x - 1, x + 1 }; int[] yNewsD = { y + 1, y + 1, y - 1, y - 1 }; int[] xNewsS = { x, x }; int[] yNewsS = { y - 1, y + 1 }; int[] xNewsF = { x, x }; int[] yNewsF = { y - 2, y + 2 }; for (int i = 0; i < xNewsD.Length; i++) { if ((int)newLocation.X == xNewsD[i] && (int)newLocation.Y == yNewsD[i]) { if (IsEnemyInPosition(board, newLocation, board[(int)curLocation.X][(int)curLocation.Y].Color)) { ChangeMoveStatus(board, curLocation); board[(int)newLocation.X][(int)newLocation.Y] = board[x][y]; board[x][y] = new BlankPiece(); return(true); } } } for (int i = 0; i < xNewsS.Length; i++) { if ((int)newLocation.X == xNewsS[i] && (int)newLocation.Y == yNewsS[i]) { if (!IsEnemyInPosition(board, newLocation, board[(int)curLocation.X][(int)curLocation.Y].Color)) { ChangeMoveStatus(board, curLocation); board[(int)newLocation.X][(int)newLocation.Y] = board[x][y]; board[x][y] = new BlankPiece(); return(true); } } } for (int i = 0; i < xNewsF.Length; i++) { if ((int)newLocation.X == xNewsF[i] && (int)newLocation.Y == yNewsF[i]) { if (!IsEnemyInPosition(board, newLocation, board[(int)curLocation.X][(int)curLocation.Y].Color) && board[(int)curLocation.X][(int)curLocation.Y].FirstMove) { ChangeMoveStatus(board, curLocation); board[(int)newLocation.X][(int)newLocation.Y] = board[x][y]; board[x][y] = new BlankPiece(); return(true); } } } return(false); }