jackcs
New Member
never mind
Posts: 12
|
Post by jackcs on Jul 12, 2014 17:57:11 GMT -8
Can someone please have mercy on me and explain how the List of moves "moves" is also having it's elements removed when a different list of moves "orderedMoves" has its elements removed as below? (e.g. when orderedMoves is empty. so is moves ??) List<Move> orderedMoves = getStateMachine().getLegalMoves(aState, getRole()); List<Move> moves = getStateMachine().getLegalMoves(aState, getRole()); while(!orderedMoves.isEmpty()) { Move aMove = orderedMoves.get(0); orderedMoves.remove(aMove); } advTHANKSance
|
|
|
Post by Steve Draper on Jul 12, 2014 18:16:29 GMT -8
Depending on the state machine (and in particular if your using the caching state machine that the default players use) getlegalMoves() returns a REFERENCE to an existing (SINGLE) list of moves for that state. If you want to modify it you should create your own copy of the list using something like:
List<Move> modifiableList = new ArrayList<Move>(getStateMachine().getLegalMoves(aState, getRole()));
|
|
jackcs
New Member
never mind
Posts: 12
|
Post by jackcs on Jul 12, 2014 18:45:05 GMT -8
I guess I would have to say I have a very poor understanding of both Java and GGP. Thank you sir, you are a gentleman and a scholar.
|
|
|
Post by Steve Draper on Jul 13, 2014 5:34:34 GMT -8
I guess I would have to say I have a very poor understanding of both Java and GGP. Thank you sir, you are a gentleman and a scholar. To be honest, on could make an argument that this is bad API design in the StateMachine class, and that perhaps having it return Enumerable<Move> rather than List<Move> might be better, as it would prevent that sort of mistake
|
|