![]() |
Strange Problem with List
I am creating a program that is generating a decision tree for a Tic Tac Toe game. I'm using and n-ary tree with nodes. Each node has a parent and a list of children defined as: List<Node> children = new ArrayList<Node>();
I know that there is nothing wrong with my tree, node, and board class. Board is just a class I made up to store the tic tac toe boards, its just a double array or strings. My problem comes in where I am generating the children for a parent. Here is the code I am using: :
public static void buildChildren(Node parent)The problem is in the list that contains all the children. This list is filled with replicas of the last iteration. For example the first child should have X at [0,0], second child X at [0,1] etc. until the last child has X at [2,2]. But instead the list is full of the correct number of children but they are all the last one (X at [2,2]) in this case. Further testing revealed that at each iteration the list of children is filled with copies of the lastest iteration. So that at the end the list is filled with copies of the last iteration. I have tried everything and every sort of testing I can think of and I can't figure this one out. If anyone can PLEASE help it would be greatly appreciated!!! |
Re: Strange Problem with List
I realized now that the issue is a memory problem. Instead of creating the actual Nodes and Boards I'm just creating references to other Nodes and Boards so when those change they all change. Does anyone know a solution for this?
|
| All times are GMT -5. The time now is 4:19 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC