Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. This code snipit method calls the copy constructor to undo a move fetching the last stack pus using pop.
  2.  
  3. the problem that Im having is when calling the copy constructor it appears the states (of the enum) stored in the super class of the pawn, rook, bishop, knight, queen, king; namly this super is called ChessPiece, its what I use to store all enums.
  4.  
  5. public void arraySubtract() {
  6. if (this.moveNum > 0) {
  7. this.moveNum--;
  8. setNextPlayer();
  9. IChessPiece[][] iBoard = iBoardStack.pop();
  10. try {
  11. for (int row = 0; row < 8; row++) {
  12. for (int col = 0; col < 8; col++) {
  13. //this.board[row][col] = clonePiece(iBoard[row][col]);
  14. IChessPiece piece = iBoard[row][col];
  15.  
  16. if (piece == null)
  17. this.board[row][col] = iBoard[row][col];
  18. else if (piece.type().equals(Type.Pawn))
  19. this.board[row][col] = new Pawn((Pawn) iBoard[row][col]);
  20. else if (piece.type().equals(Type.Rook))
  21. this.board[row][col] = new Rook((Rook) iBoard[row][col]);
  22. else if (piece.type().equals(Type.Bishop))
  23. this.board[row][col] = new Bishop((Bishop) iBoard[row][col]);
  24. else if (piece.type().equals(Type.Knight))
  25. this.board[row][col] = new Knight((Knight) iBoard[row][col]);
  26. else if (piece.type().equals(Type.Queen))
  27. this.board[row][col] = new Queen((Queen) iBoard[row][col]);
  28. else if (piece.type().equals(Type.King))
  29. this.board[row][col] = new King((King) iBoard[row][col]);
  30. }
  31. }
  32. } catch (IllegalArgumentException arg) {
  33. arg.printStackTrace();
  34. }
  35. System.out.println("Model Move #" + this.moveNum);
  36. }
  37. }
  38.  
  39.  
  40. This is the copy constructor of the pawn class as example of what im currently working on, if i set the enum to enPassant, after a two space move, after undone, apparently opposed to grabbing a stored copy of the enum with a Status.NotMoved, it returns Status.EnPassant?
  41.  
  42.  
  43. public Pawn(ChessPiece piece) {
  44. super(piece);
  45. super.owner = piece.player();
  46. super.status = piece.status();
  47. }
  48.  
  49.  
  50. ChessPiece's copy constructor
  51.  
  52. protected ChessPiece(ChessPiece piece) {
  53. super();
  54. this.owner = piece.player();
  55. this.status = piece.status();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement