def __init__(self, abr): super(CoastProvince, self).__init__(abr) self.land_location = Location((0, 0)) self.land_adjacent = list() self.water_location = Location((0, 0)) self.water_adjacent = list() if (self.is_power()): self.produce = [UnitType.ARMY, UnitType.FLEET]
class TwoCoastProvince(ProvinceBase): """Used for a coastal province with two coasts. Includes land AND north AND south adjacencies, and locations for each""" land_adjacent: List['Province'] land_location: Location north_adjacent: List['Province'] north_location: Location south_adjacent: List['Province'] south_location: Location def __init__(self, abr): super(TwoCoastProvince, self).__init__(abr) self.land_location = Location((0, 0)) self.land_adjacent = list() self.north_location = Location((0, 0)) self.north_adjacent = list() self.south_location = Location((0, 0)) self.south_adjacent = list() if (self.is_power()): self.produce = [UnitType.ARMY, UnitType.FLEET] def set_data(self, data, P): super(TwoCoastProvince, self).set_data(data) self.land_location = Location(data['land_location']) for abr in data['land_adjacent']: self.land_adjacent.append(P[abr]) self.north_location = Location(data['north_location']) for abr in data['north_adjacent']: self.north_adjacent.append(P[abr]) self.south_location = Location(data['south_location']) for abr in data['south_adjacent']: self.south_adjacent.append(P[abr]) return def is_adjacent(self, prov: ProvinceBase, unit: 'Unit'): if unit.typ == UnitType.ARMY: if prov in self.land_adjacent: return True if unit.typ == UnitType.FLEET: if prov in self.north_adjacent or prov in self.south_adjacent: return True return False def serialize(self): out_dict = dict() out_dict['name'] = self.name out_dict['form'] = self.form() out_dict['land_location'] = self.land_location.print() out_dict['land_adjacent'] = self.adj_serialize(self.land_adjacent) out_dict['north_location'] = self.north_location.print() out_dict['north_adjacent'] = self.adj_serialize(self.north_adjacent) out_dict['south_location'] = self.south_location.print() out_dict['south_adjacent'] = self.adj_serialize(self.south_adjacent) return out_dict def form(self): return "TWO_COAST"
def set_data(self, data, P): super(CoastProvince, self).set_data(data) self.land_location = Location(data['land_location']) for abr in data['land_adjacent']: self.land_adjacent.append(P[abr]) self.water_location = Location(data['water_location']) for abr in data['water_adjacent']: self.water_adjacent.append(P[abr]) return
class CoastProvince(ProvinceBase): """Used for a costal province with only one coast. Includes land AND water adjacencies, and land and water locations""" land_adjacent: List['Province'] land_location: Location water_adjacent: List['Province'] water_location: Location def __init__(self, abr): super(CoastProvince, self).__init__(abr) self.land_location = Location((0, 0)) self.land_adjacent = list() self.water_location = Location((0, 0)) self.water_adjacent = list() if (self.is_power()): self.produce = [UnitType.ARMY, UnitType.FLEET] def set_data(self, data, P): super(CoastProvince, self).set_data(data) self.land_location = Location(data['land_location']) for abr in data['land_adjacent']: self.land_adjacent.append(P[abr]) self.water_location = Location(data['water_location']) for abr in data['water_adjacent']: self.water_adjacent.append(P[abr]) return def is_adjacent(self, prov: ProvinceBase, unit: 'Unit'): if unit.typ == UnitType.ARMY: if prov in self.land_adjacent: return True if unit.typ == UnitType.FLEET: if prov in self.water_adjacent: return True return False def serialize(self): out_dict = dict() out_dict['name'] = self.name out_dict['form'] = self.form() out_dict['land_location'] = self.land_location.print() out_dict['land_adjacent'] = self.adj_serialize(self.land_adjacent) out_dict['water_location'] = self.water_location.print() out_dict['water_adjacent'] = self.adj_serialize(self.water_adjacent) return out_dict def form(self): return "COAST"
def location(self): if self.typ == UnitType.ARMY: if isinstance(self.province, LandProvince) or isinstance(self.province, CoastProvince): return self.province.land_location elif self.typ == UnitType.FLEET: if isinstance(self.province, WaterProvince) or isinstance(self.province, CoastProvince): return self.province.water_location elif isinstance(self.province, TwoCoastProvince): if self.coast == Coast.NORTH: return self.province.north_location elif self.coast == Coast.SOUTH: return self.province.south_location return Location(0,0)
def set_data(self, data, P): super(TwoCoastProvince, self).set_data(data) self.land_location = Location(data['land_location']) for abr in data['land_adjacent']: self.land_adjacent.append(P[abr]) self.north_location = Location(data['north_location']) for abr in data['north_adjacent']: self.north_adjacent.append(P[abr]) self.south_location = Location(data['south_location']) for abr in data['south_adjacent']: self.south_adjacent.append(P[abr]) return
class WaterProvince(ProvinceBase): """Class used for a province that is water. Includes water adjacencies and positions where fleets appear.""" water_adjacent: List['Province'] water_location: Location def __init__(self, abr): super(WaterProvince, self).__init__(abr) self.water_location = Location((0, 0)) self.water_adjacent = list() if (self.is_power()): self.produce = [UnitType.FLEET] def set_data(self, data, P): super(WaterProvince, self).set_data(data) self.water_location = Location(data['water_location']) for abr in data['water_adjacent']: self.water_adjacent.append(P[abr]) return def is_adjacent(self, prov: ProvinceBase, unit: 'Unit'): if unit.typ == UnitType.ARMY: return False elif unit.typ == UnitType.FLEET: if prov in self.water_adjacent: return True return False def serialize(self): out_dict = dict() out_dict['name'] = self.name out_dict['form'] = self.form() out_dict['water_location'] = self.water_location.print() out_dict['water_adjacent'] = self.adj_serialize(self.water_adjacent) return out_dict def form(self): return 'WATER'
class LandProvince(ProvinceBase): """Class used for a province that is land locked. Includes land adjacencies and position where armies appear.""" land_adjacent: List['Province'] land_location: Location def __init__(self, abr): super(LandProvince, self).__init__(abr) self.land_location = Location((0, 0)) self.land_adjacent = list() if (self.is_power()): self.produce = [UnitType.ARMY] def set_data(self, data, P): super(LandProvince, self).set_data(data) self.land_location = Location(data['land_location']) for abr in data['land_adjacent']: self.land_adjacent.append(P[abr]) return def is_adjacent(self, prov: ProvinceBase, unit: 'Unit'): if unit.typ == UnitType.ARMY: if prov in self.land_adjacent: return True elif unit.typ == UnitType.FLEET: return False return False def serialize(self): out_dict = dict() out_dict['name'] = self.name out_dict['form'] = self.form() out_dict['land_location'] = self.land_location.print() out_dict['land_adjacent'] = self.adj_serialize(self.land_adjacent) return out_dict def form(self): return 'LAND'
def __init__(self, abr): super(LandProvince, self).__init__(abr) self.land_location = Location((0, 0)) self.land_adjacent = list() if (self.is_power()): self.produce = [UnitType.ARMY]