Ezraay / kaggle

FIT 3163 Connect X competition on Kaggle
0 stars 0 forks source link

Copy board functionality #31

Closed Ezraay closed 1 year ago

Ezraay commented 1 year ago

There needs to be ability to copy a board object into a new instance. It should be a smart copy that contains the same history, board state etc. This is required so that agents don't accidentally mess with the actual board state when performing searches incorrectly.

# Example
board = Board()
board.create((7, 6))
board2 = board.copy()
Q-g2 commented 1 year ago

Does this copy() function okay ? def copy(self): """Create a deep copy of the current board.""" new_board = Board() new_board.heights = self.heights.copy() new_board.board = [row.copy() for row in self.board] new_board.size = self.size new_board.history = self.history.copy() return new_board

Ezraay commented 1 year ago

@Q-g2 code encounters an error image you should make the function a part of the board object, see my initial code snippet for expected usage. Error is you can't access private members of a class outside code in the class declaration. image