public void ResetBoard() { //Resets all tiles to null Array.Clear(BoardGrid, 0, BoardGrid.Length); //intialize the pieces InitializePawns(); InitializeRooks(); InitializeKnights(); InitializeBishops(); InitializeQueens(); InitializeKings(); //initialize remaining tiles as empty var currentPos = new Vector2d(); for (var r = 0; r < MaxRows; r++) { for (var c = 0; c < MaxColumns; c++) { currentPos.X = c; currentPos.Y = r; if (BoardGrid[r, c] == null) { BoardGrid[r, c] = new EmptyPiece(currentPos, "-", false); } } } }
private void MovePiece(int from_x, int from_y, int to_x, int to_y) { Piece from_piece = board[from_x, from_y]; Piece to_piece = board[to_x, to_y]; if (board.IsInsideBounds(to_x, to_y) && !to_piece.IsBlocking()) { board[to_x, to_y] = from_piece; from_piece.UpdatePosition(to_x, to_y); board[from_x, from_y] = new EmptyPiece(from_y, from_x); } else { if (OnMoveBlocked != null) { OnMoveBlocked(from_piece, to_piece, from_x, from_y, to_x, to_y); } } }
void Initialize() { for(int x = 0; x < CUBE_SIZE; x++) { for(int y = 0; y < CUBE_SIZE; y++) { for(int z = 0; z < CUBE_SIZE; z++) { bool isXEdge = x == 0 || x == CUBE_SIZE - 1; bool isYEdge = y == 0 || y == CUBE_SIZE - 1; bool isZEdge = z == 0 || z == CUBE_SIZE - 1; int edgeSum = CountTrue(isXEdge, isYEdge, isZEdge); switch (edgeSum) { case 0: m_cube[x,y,z] = new EmptyPiece(x + CUBE_OFFSET, y + CUBE_OFFSET, z + CUBE_OFFSET); break; case 1: m_cube[x,y,z] = new CenterPiece(x + CUBE_OFFSET, y + CUBE_OFFSET, z + CUBE_OFFSET); break; case 2: m_cube[x,y,z] = new EdgePiece(x + CUBE_OFFSET, y + CUBE_OFFSET, z + CUBE_OFFSET); break; case 3: m_cube[x,y,z] = new CornerPiece(x + CUBE_OFFSET, y + CUBE_OFFSET, z + CUBE_OFFSET); break; } } } } }
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; } }