private static IReadOnlyCollection<BitArray> InitializeRays() { var rays = new List<BitArray>(Chessboard.NumLocations); var bishop = new Bishop(ChessColour.Black); var rook = new Rook(ChessColour.Black); for (int i = 0; i < Chessboard.NumLocations; i++) { rays.Add(bishop.GetRay(i).Or(rook.GetRay(i))); } return rays; }
public Board(LaunchState launchState = LaunchState.Empty) { gameSpace = new Piece[8, 8]; switch (launchState) { case LaunchState.Empty: for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { gameSpace[x, y] = new EmptyPiece(x, y); } } break; case LaunchState.NoPawns: for (int y = 0; y < 8; y++) { if (y == 7) { for (int x = 0; x < 8; x++) { if (x == 0 | x == 7) { gameSpace[x, y] = new Rook("White", x, y); } else if (x == 1 | x == 6) { gameSpace[x, y] = new Knight("White", x, y); } else if (x == 2 | x == 5) { gameSpace[x, y] = new Bishop("White", x, y); } else if (x == 3) { gameSpace[x, y] = new Queen("White", x, y); } else if (x == 4) { gameSpace[x, y] = new King("White", x, y); } } } else if (y == 0) { for (int x = 0; x < 8; x++) { if (x == 0 | x == 7) { gameSpace[x, y] = new Rook("Black", x, y); } else if (x == 1 | x == 6) { gameSpace[x, y] = new Knight("Black", x, y); } else if (x == 2 | x == 5) { gameSpace[x, y] = new Bishop("Black", x, y); } else if (x == 3) { gameSpace[x, y] = new Queen("Black", x, y); } else if (x == 4) { gameSpace[x, y] = new King("Black", x, y); } } } else { for (int x = 0; x < 8; x++) { gameSpace[x, y] = new EmptyPiece(x, y); } } } break; case LaunchState.FullStart: for (int y = 0; y < 8; y++) { if (y == 7) { for (int x = 0; x < 8; x++) { if (x == 0 | x == 7) { gameSpace[x, y] = new Rook("White", x, y); } else if (x == 1 | x == 6) { gameSpace[x, y] = new Knight("White", x, y); } else if (x == 2 | x == 5) { gameSpace[x, y] = new Bishop("White", x, y); } else if (x == 3) { gameSpace[x, y] = new Queen("White", x, y); } else if (x == 4) { gameSpace[x, y] = new King("White", x, y); } } } else if (y == 6) { for (int x = 0; x < 8; x++) { gameSpace[x, y] = new Pawn("White", x, y); } } else if (y == 1) { for (int x = 0; x < 8; x++) { gameSpace[x, y] = new Pawn("Black", x, y); } } else if (y == 0) { for (int x = 0; x < 8; x++) { if (x == 0 | x == 7) { gameSpace[x, y] = new Rook("Black", x, y); } else if (x == 1 | x == 6) { gameSpace[x, y] = new Knight("Black", x, y); } else if (x == 2 | x == 5) { gameSpace[x, y] = new Bishop("Black", x, y); } else if (x == 3) { gameSpace[x, y] = new Queen("Black", x, y); } else if (x == 4) { gameSpace[x, y] = new King("Black", x, y); } } } else { for (int x = 0; x < 8; x++) { gameSpace[x, y] = new EmptyPiece(x, y); } } } break; default: break; } }
private void InitializePieces() { board = new Piece[8, 8]; whites = new MarkableButtonPanel(); blacks = new MarkableButtonPanel(); int pieceSize = Constants.PIESESIZE; int markSize = Constants.MARKED_PIESESIZE; for (int i = 0; i < 8; i++) { Piece temp = new Pawn(new Sprite2D(ContentService.Instance.Textures["WhitePawn"], new Rectangle(0, 0, pieceSize, pieceSize)), 6, i, ChessColor.White, this); temp.Center(grid[6, i].Bounds); board[6, i] = temp; } Piece x = new Rook(new Sprite2D(ContentService.Instance.Textures["WhiteRook"], new Rectangle(0, 0, pieceSize, pieceSize)), 7, 0, ChessColor.White, this); x.Center(grid[7, 0].Bounds); board[7, 0] = x; x = new Rook(new Sprite2D(ContentService.Instance.Textures["WhiteRook"], new Rectangle(0, 0, pieceSize, pieceSize)), 7, 7, ChessColor.White, this); x.Center(grid[7, 7].Bounds); board[7, 7] = x; x = new Knight(new Sprite2D(ContentService.Instance.Textures["WhiteKnight"], new Rectangle(0, 0, pieceSize, pieceSize)), 7, 1, ChessColor.White, this); x.Center(grid[7, 1].Bounds); board[7, 1] = x; x = new Knight(new Sprite2D(ContentService.Instance.Textures["WhiteKnight"], new Rectangle(0, 0, pieceSize, pieceSize)), 7, 6, ChessColor.White, this); x.Center(grid[7, 6].Bounds); board[7, 6] = x; x = new Bishop(new Sprite2D(ContentService.Instance.Textures["WhiteBishop"], new Rectangle(0, 0, pieceSize, pieceSize)), 7, 2, ChessColor.White, this); x.Center(grid[7, 2].Bounds); board[7, 2] = x; x = new Bishop(new Sprite2D(ContentService.Instance.Textures["WhiteBishop"], new Rectangle(0, 0, pieceSize, pieceSize)), 7, 5, ChessColor.White, this); x.Center(grid[7, 5].Bounds); board[7, 5] = x; x = new Queen(new Sprite2D(ContentService.Instance.Textures["WhiteQueen"], new Rectangle(0, 0, pieceSize, pieceSize)), 7, 3, ChessColor.White, this); x.Center(grid[7, 3].Bounds); board[7, 3] = x; x = new King(new Sprite2D(ContentService.Instance.Textures["WhiteKing"], new Rectangle(0, 0, pieceSize, pieceSize)), 7, 4, ChessColor.White, this); x.Center(grid[7, 4].Bounds); board[7, 4] = x; for (int i = 0; i < 8; i++) { Piece temp = new Pawn(new Sprite2D(ContentService.Instance.Textures["BlackPawn"], new Rectangle(0, 0, pieceSize, pieceSize)), 1, i, ChessColor.Black, this); temp.Center(grid[1, i].Bounds); board[1, i] = temp; } x = new Rook(new Sprite2D(ContentService.Instance.Textures["BlackRook"], new Rectangle(0, 0, pieceSize, pieceSize)), 0, 0, ChessColor.Black, this); x.Center(grid[0, 0].Bounds); board[0, 0] = x; x = new Rook(new Sprite2D(ContentService.Instance.Textures["BlackRook"], new Rectangle(0, 0, pieceSize, pieceSize)), 0, 7, ChessColor.Black, this); x.Center(grid[0, 7].Bounds); board[0, 7] = x; x = new Knight(new Sprite2D(ContentService.Instance.Textures["BlackKnight"], new Rectangle(0, 0, pieceSize, pieceSize)), 0, 1, ChessColor.Black, this); x.Center(grid[0, 1].Bounds); board[0, 1] = x; x = new Knight(new Sprite2D(ContentService.Instance.Textures["BlackKnight"], new Rectangle(0, 0, pieceSize, pieceSize)), 0, 6, ChessColor.Black, this); x.Center(grid[0, 6].Bounds); board[0, 6] = x; x = new Bishop(new Sprite2D(ContentService.Instance.Textures["BlackBishop"], new Rectangle(0, 0, pieceSize, pieceSize)), 0, 2, ChessColor.Black, this); x.Center(grid[0, 2].Bounds); board[0, 2] = x; x = new Bishop(new Sprite2D(ContentService.Instance.Textures["BlackBishop"], new Rectangle(0, 0, pieceSize, pieceSize)), 0, 5, ChessColor.Black, this); x.Center(grid[0, 5].Bounds); board[0, 5] = x; x = new Queen(new Sprite2D(ContentService.Instance.Textures["BlackQueen"], new Rectangle(0, 0, pieceSize, pieceSize)), 0, 3, ChessColor.Black, this); x.Center(grid[0, 3].Bounds); board[0, 3] = x; x = new King(new Sprite2D(ContentService.Instance.Textures["BlackKing"], new Rectangle(0, 0, pieceSize, pieceSize)), 0, 4, ChessColor.Black, this); x.Center(grid[0, 4].Bounds); board[0, 4] = x; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (board[i, j] == null) { continue; } board[i, j].MarkAnimation = new ButtonAnimation(null, new Rectangle(board[i, j].Bounds.Location, new Point(markSize, markSize)), null, true); board[i, j].UnMarkAnimation = new ButtonAnimation(null, new Rectangle(board[i, j].Bounds.Location, new Point(pieceSize, pieceSize)), null, true); if (board[i, j].ChessColor == ChessColor.Black) { blacks.Add(board[i, j]); } else { whites.Add(board[i, j]); } } } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (board[i, j] != null) { board[i, j].CalculateLegalMoves(); } } } }