def loadFromDict(fields): countries = [createCountry(countryInfo) for countryInfo in fields["countries"]] territories = [createTerritory(tInfo, countries) for tInfo in fields["territories"]] for info in fields["territories"]: territory = Util.getByName(territories, info["name"]) territory.connections = [Util.getByName(territories, neighbour) for neighbour in info["connections"]] unitInfo = {unitType: UnitInfo(unitType, unitInfo) for unitType, unitInfo in fields["unitCatalogue"].items()} units = [] for unitDef in fields["units"]: newUnit = Unit.createUnitFromDict(unitDef, unitInfo, countries, territories) units.append(newUnit) boughtUnits = [] for unitDef in fields["buyList"]: newUnit = Unit.createBoughtUnitFromDict(unitDef, territories) boughtUnits.append(newUnit) board = Board(unitInfo, territories, units, countries, fields["currentPhase"], boughtUnits) for conflictInfo in fields["pastConflicts"]: conflict = Conflict.fromDict(conflictInfo, board) board.resolvedConflicts.append(conflict) board.currentCountry = Util.getByName(countries, fields["currentCountry"]) return board
def createUnits(unitInfoCollection): # Small issue - will create new instance of units that already exist return [Unit.createUnitFromDict(unitInfo, board.unitInfoDict, board.countries, board.territories) for unitInfo in unitInfoCollection]