그래서 Othello 게임을위한 Monte Carlo 검색 트리를 구현하려고합니다. 나는 하나의 합법적 인 이동에서 'y'에서 'x'로 이동할 수있는 경우 'x'가 'y'의 하위 노드 인 루트 노드와 자식 노드가 있습니다.새로운 개체를 만들기 때문에 C++에서 메모리가 부족합니다.
각 노드마다 각 보드의 값과 같은 보드 정보를 모두 담는 '보드'객체를 저장합니다. 내가 가지고있는 첫 번째 문제는 자식 노드의 보드 객체를 변경하면 부모 노드의 값도 변경된다는 것입니다. 모든 하위 노드에 대해 '새'보드 객체를 만들어이 문제를 해결했지만, 메모리가 부족한 시점까지 시뮬레이션을 몇 천 번 실행했을 때 과도한 메모리가 사용되었습니다.
부모의 보드 정보를 변경하지 않고 자식 노드에서 보드 정보를 변경하는 방법이 있거나 각 노드에 보드 정보를 저장하는 더 좋은 방법이있는 경우 방황합니다. 모든 노드에 대해 새 Board 객체를 만듭니다.
아래에서 의견을 명확히 할 필요가있는 경우, 읽어 주셔서 감사합니다.
편집 :
for (int x = 0; x < numberOfChildren; x += 1) {
// Resets *currentBoard to the same state as the node being expanded
Board *currentBoard = nodeToExpand->getCurrentBoard();
// Retrives the board value information
int** temporaryBoardValues = currentBoard->getBoardValues();
// Makes a new board object with the previous parameters
Board *temporaryBoard = new Board(blockSize, boardSize, offset);
// Sets the new board values to the same as the old ones
temporaryBoard->setBoardValues(temporaryBoardValues);
// Creates a clone of that board state
// Board *temporaryBoard = cloneBoard(*currentBoard);
// Creates a node with the cloned board state, setting the parent to be the node being expanded.
// Assigns it one of the available moves
// Produces the array of child nodes
myChildren[x] = new Node(nodeToExpand, temporaryBoard, availableMoves[x], currentPlayer);
//delete temporaryBoard;
}
작은 코드. 그것은 내가 모든 메모리를 다 사용하는 새로운 Board 객체를 만드는 부분입니다.
작은 코드 샘플을 게시 할 수 있습니까? –
일종의 실행 취소 작업을 위해이 정보를 저장하고 있습니까? – NathanOliver
'n'의 깊이로 분기 트리를 검색하려면 : 현재 최상의 이동 및 'n'노드 만 메모리 (1)에 유지하면됩니다.전체 트리는 현재의 검색/평가를 1 브랜치에서 깊이'n '까지만 유지할 필요가 없습니다. 스택에서 쉽게 유지할 수 있습니다. 힙에 많은 보드를 보유하고 있다면 아마도 잘못했을 것입니다. (알파 베타 알고리즘 참조). –