I'm using pickle as well for saving and load, although I actually convert my data objects(map, item lists, monster lists, other things) into a few big Dict objects and then Pickle-save them. Its not quite as easy, but I was paranoid about save-games breaking between code edits at the time, so I wanted to explicitly state what gets saved/loaded.
---Brainstorming---
I was sick for most of last week so I haven't gotten a lot of work done on my game(Also been playing too much Civ 5 and Dishonored

). Now I'm going to do some brainstorming.
I was working on the AI code for a monster to go to the barracks to sleep, and then go back to his post when he wakes up. As I was writing it I realized that I'm going to need a more robust system to help the AI get pathfinding info when a monster wants to go somewhere. Right now I need to do this:
1) Find all the barracks rooms from list of rooms.
2) Does each barracks have a bed in it?
3) Can I path to the beds?
4) Choose the barracks/bed with the shortest path.
5) Done.
My digging monsters do much the same thing.
1) Find a list of walls marked dig AND have an open space next to them.
2) Sort by shortest distance.
3) Keep checking them for a valid path until we find one.
4) Done
And my monsters that are checking to attack someone:
1) Check list of monsters for ones that are in eyesight of this one and are an enemy.
2) Sort by closest
3) Pathfind to that location.
I can see myself spending a significant amount of time when writing AI just doing this "Find blah if blah exists and pathfind to it". How to avoid? MOAR INFRASTRUCTURE!
I have a bad habit of writing far too much infrastructure and not enough actual game, but whatever.

My plan is to create a PathFinder class to ease the load on the AI sections. It needs to make it relatively easy for the AI to get a pathfinding target.
#Pseudo code structure
class PathFinder:
def get_path(monster, target): #finds a path to a particular object.
#Target can be a [x,y] coordinate, a monster, a construction(bed), a zone(room) or an item.
#code...
return path
def find_path(monster, type, target, zone=nil): #finds a path to a generic object. Like "barracks" or "goblin".
#type must be one of "zone", "construction", "monster", "item"
#target is the more specific type, such as "bed", "goblin", "weapon"
#zone is optional. It restricts to a particular room type, such as "barracks", "guard post".
#code...
return path
def get_dig_path(monster): #specialized code for digging, because its a bit more complicated.
#code...
return path
I think this is a fairly general and sensible way of doing things, and will let me write more complicated AI code a bit faster. Also if I have to optimize later, I only will need to optimize this new PathFinder class, instead of every AI routine I write.
