There is room for improvement in the Board class, since it was originally developed with the mantra of "get it working". Some ideas/weaknesses:
[x] pegs_left method: currently iterates through every hole in the board. It shouldn't have to do this. All operations related to the board should be contained within methods of the Board class, so we should be able to maintain an attribute for the number of pegs left on the board. We would decrement it with each move. First, need to move the make_jump method from the Game class into the Board class. Also, make sure that the save_state method in Game accurately saves this new attribute.
[x] locate_peg method: could I use a dictionary to map each peg letter to its current location? Should be able to, yes. The only changes are to 2 pegs on each move (jumper and jumpee), and when the first peg is removed to start the game.
[x] remove method: would be more efficient if we have a dictionary mapping pegs to locations (O(1))
[x] get_moves method: currently iterates through each spot in the board looking for holes. Could we store as an attribute a list of all locations with holes? May not be any better...how would we remove a hole from the list? Maybe using a set...that would provide O(1) add and remove...OK, that actually works.
There is room for improvement in the Board class, since it was originally developed with the mantra of "get it working". Some ideas/weaknesses:
pegs_left
method: currently iterates through every hole in the board. It shouldn't have to do this. All operations related to the board should be contained within methods of the Board class, so we should be able to maintain an attribute for the number of pegs left on the board. We would decrement it with each move. First, need to move themake_jump
method from the Game class into the Board class. Also, make sure that thesave_state
method in Game accurately saves this new attribute.locate_peg
method: could I use a dictionary to map each peg letter to its current location? Should be able to, yes. The only changes are to 2 pegs on each move (jumper and jumpee), and when the first peg is removed to start the game.remove
method: would be more efficient if we have a dictionary mapping pegs to locations (O(1))get_moves
method: currently iterates through each spot in the board looking for holes. Could we store as an attribute a list of all locations with holes? May not be any better...how would we remove a hole from the list? Maybe using a set...that would provide O(1) add and remove...OK, that actually works.