0
votes

I have a State class that I want to be my nodes in the graph and I have a Move class that I want to be the edges between states. My State class just holds some data and I can get to other states by applying a Moveto it which is simply a class with some information on how to get to that next state.

For example from state1, state1.applyMove(move1), takes me to state2

I'm not sure what type of graph this would be (undirected, directed?) and what information I would have to add to my current classes to implement a graph structure.

1
It sounds like your State class needs two fields: State left; State right; that indicate the result of moving left and right. Without more information it's hard to say. - Paul Boddington
@PaulBoddington I added a bit more information on what I currently have - Brejuro
How many different Move objects are there? 4? (e.g. up, down, left, right). - Paul Boddington
@PaulBoddington Move has a String direction (up, down, left, right) and a int piece which is just some information on how to get to the next state. - Brejuro

1 Answers

0
votes

You ask two questions:

I'm not sure what type of graph this would be (undirected, directed?) ...

As described, I would say that this is a directed graph, because your edges represent "moves". But if your moves can be applied in both directions (such that state.applyMove(move1).applyMove(move1) == state), then you could also consider it an undirected graph.

... and what information I would have to add to my current classes to implement a graph structure?

"Graph structure" is not really well-defined and the answer to this question really depends on what you consider to be a graph structure. Very liberally taken, every object model is a graph structure, where the objects are nodes and the references edges. In your case, you even have classes which represent edges (the moves) so I would certainly consider your situation a "graph structure". You don't have to add anything.