Пример #1
0
    def __init__(self):
        self.nb_maison_dispo = 32
        self.nb_hotel_dispo = 12

        self.dice = Dice()

        # instanciation des cartes
        self.carte_chance = Carte_chance()
        self.carte_communaute = Carte_communaute()

        # self.proprietes = proprietes_data

        # instanciation des cases propriété
        self.proprietes = []
        for i in proprietes_data:
            self.proprietes.append(Propriete(i))
        # for p in self.proprietes: p.fiche()

        # instanciation des cases gare
        self.gares = []
        for i in gares_data:
            self.gares.append(Gare(i))
        # for g in self.gares: g.fiche()

        # instanciation des cases compagnie
        self.compagnies = []
        for i in compagnies_data:
            self.compagnies.append(Compagnie(i))
        # for c in self.compagnies: c.fiche()

        # instanciation de la prison
        self.prison = Prison()

        # tableau des joueurs
        self.joueurs = []
Пример #2
0
    def __init__(self, dimension, num_citizens, num_cops, max_iterations):
        """
        Inicjacja przestrzeni panstwa wraz z rzadem, losowymi
        Citizenami i Copami

        """
        self.government = Government(.82)
        self.prison = Prison(self)
        # self.statistics_office = StatisticsOffice()
        # lista pol zajetych
        # tuple : referencja do obiektu
        # inicjalizacja pustej przestrzeni
        self.occupied_fields = dict()
        for x in range(dimension):
            for y in range(dimension):
                self.occupied_fields[(x,y)] = None
        # dimension * dimension to ilosc pol
        self.dimension = dimension

        # ilosc agentow typu citizen
        self.num_citizens = num_citizens
        # ilosc obywateli typu Cop
        self.num_cops = num_cops
        # ilosc iteracji symulacji
        self.max_iterations = max_iterations
      
        
        # zmienne do wizualizacji symulacji
        self.plot_data = np.zeros((self.dimension,self.dimension))


        self.id_generator =  self.create_id_generaor(start_id = 1)

        self.agent_types = {"None": 0 ,
                    "ActiveCitizen" : 1, 
                    "PassiveCitizen" : 2,
                    "Cop" : 3,
                    "Prisoner" : 4
                    }

        # kolekcjonowanie danych symulacji
        self._column_names = [
                             "number_of_agents", 
                             "number_of_arrests", # tylko dla copa uzupelniane
                             "total_grievance",
                             "total_preceived_hardship",
                             "total_risk_aversion"                       
                             ]
        self.statistics = {
                            self.agent_types["None"] : pd.DataFrame(columns = self._column_names), # czysto techniczne - w razie czego
                            self.agent_types["ActiveCitizen"] : pd.DataFrame(columns = self._column_names),
                            self.agent_types["PassiveCitizen"] : pd.DataFrame(columns = self._column_names),
                            self.agent_types["Cop"] : pd.DataFrame(columns = self._column_names),
                            self.agent_types["Prisoner"] : pd.DataFrame(columns = self._column_names)
                           }
Пример #3
0
class Country():
    """
    Panstwo, przestrzen w ktorej zyja agenci. 
    Wladze w panstwie sprawoje rzad.
    """
    def __init__(self, dimension, num_citizens, num_cops, max_iterations):
        """
        Inicjacja przestrzeni panstwa wraz z rzadem, losowymi
        Citizenami i Copami

        """
        self.government = Government(.82)
        self.prison = Prison(self)
        # self.statistics_office = StatisticsOffice()
        # lista pol zajetych
        # tuple : referencja do obiektu
        # inicjalizacja pustej przestrzeni
        self.occupied_fields = dict()
        for x in range(dimension):
            for y in range(dimension):
                self.occupied_fields[(x,y)] = None
        # dimension * dimension to ilosc pol
        self.dimension = dimension

        # ilosc agentow typu citizen
        self.num_citizens = num_citizens
        # ilosc obywateli typu Cop
        self.num_cops = num_cops
        # ilosc iteracji symulacji
        self.max_iterations = max_iterations
      
        
        # zmienne do wizualizacji symulacji
        self.plot_data = np.zeros((self.dimension,self.dimension))


        self.id_generator =  self.create_id_generaor(start_id = 1)

        self.agent_types = {"None": 0 ,
                    "ActiveCitizen" : 1, 
                    "PassiveCitizen" : 2,
                    "Cop" : 3,
                    "Prisoner" : 4
                    }

        # kolekcjonowanie danych symulacji
        self._column_names = [
                             "number_of_agents", 
                             "number_of_arrests", # tylko dla copa uzupelniane
                             "total_grievance",
                             "total_preceived_hardship",
                             "total_risk_aversion"                       
                             ]
        self.statistics = {
                            self.agent_types["None"] : pd.DataFrame(columns = self._column_names), # czysto techniczne - w razie czego
                            self.agent_types["ActiveCitizen"] : pd.DataFrame(columns = self._column_names),
                            self.agent_types["PassiveCitizen"] : pd.DataFrame(columns = self._column_names),
                            self.agent_types["Cop"] : pd.DataFrame(columns = self._column_names),
                            self.agent_types["Prisoner"] : pd.DataFrame(columns = self._column_names)
                           }

        
 

    def get_free_location(self, search_for_nones = False):
        """Zwraca wolna lokalizacje."""
        if search_for_nones :
            free_fields = [field for field in self.occupied_fields 
                            if self.occupied_fields[field] == None]
        else:
            free_fields = [field for field in self.occupied_fields 
                            if self.occupied_fields[field].my_type == 0]
            
        assert(len(free_fields) > 0)
        return random.choice(free_fields)

    def update_plot_data(self):
        # agent w tej iteracji to tuple
        # dodajemy
        for x in range(self.dimension):
            for y in range(self.dimension):
                    self.plot_data[(x,y)] = self.occupied_fields[(x,y)].my_type

    def create_id_generaor(self, start_id = 1):
        i = start_id
        while True:
            yield i
            i += 1

    def plot(self):
        """Metoda odpowiedzialna za wizualizacje modelu."""    
        self.update_plot_data()
        self.gp.plot()
    
    def initialize_simulation(self, visualize):
        """ Metoda odpowiedzialna za inicjalizacje srodowiska symulacji """
        for i in range(self.num_citizens):
            Citizen(self, next(self.id_generator))
        for i in range(self.num_cops):
            Cop(self, next(self.id_generator))

        # reszte pol wypelnic agentami typu none
        for location in self.occupied_fields: 
            if self.occupied_fields[location] == None:
                Agent(self, -1 , location)
        if visualize:
            self.update_plot_data()
            self.gp = GridPlot(self.plot_data,["white","red", "green", "black"])
            
    def export_statistics(self, path, agents_to_export = list()):
        """
            Eksportowanie statystyk agentow do pliku csv zadanego w zmiennej path
            mozemy przekazac liste nazw agentow , ktorych statystyki chcemy
            defaultowo bierzemy wszystko
        """

        if len(agents_to_export) <= 0: 
            agents_to_export = list((self.agent_types.keys()))
            agents_to_export.remove('None')
        # sprawdzenie czy lista agentow jest niepusta i czy podani agenci istnieja
        assert(set(agents_to_export).issubset(set(self.agent_types.keys())))
        export_cols = ["agent_type"] + self._column_names
        df_to_export = pd.DataFrame(columns = export_cols)
        # do kazdego dataframe ze statystykami dopisuje kolumne wypelniona rodzajem agenta
        # wszystkie dataframy skladam w jeden i potem eksportuje
        for agent_type in agents_to_export:
            temp_df = self.statistics[self.agent_types[agent_type]]
            temp_df["agent_type"] = [agent_type for i in range(len(temp_df))]
            df_to_export = pd.concat([df_to_export, temp_df])
        
        df_to_export.to_csv(path, columns = export_cols)
                                        
    def run(self, record_data = False, visualize = False):
        """
        Metoda odpowiedzialna za przeprowadzenie symulacji 
        """
        self.initialize_simulation(visualize)

        for i in range(self.max_iterations):

            # dodanie nowego wiersza z danymi z zerami
            if record_data:
                for key, dataframe in self.statistics.items():
                    dataframe.loc[len(dataframe)] = (
                        [0 for stat in range(len(self._column_names))])

            # obsluzenie wiezienia
            freed_prisoners = self.prison.get_leaving_prisoners(record_data)
            # umieszczenie wolnych citizenow na dostepnych polach
            for prisoner in freed_prisoners:
                prisoner.location = self.get_free_location()
                self.occupied_fields[prisoner.location] = prisoner
                           
            for agent in self.occupied_fields:
                if self.occupied_fields[agent].my_type != 0:
                    ag = self.occupied_fields[agent]
                    ag.update_agent(record_data)
                          
            if visualize:
                self.plot()

            print(i)
Пример #4
0
def createInmates():
    inmates = []
    inmates.append(
        Inmate("Augustus", "Hill", 1234, Prison.getNewPrisonerID(), "killer",
               10))
    inmates.append(
        Inmate("Tobias", "Beecher", 1234, Prison.getNewPrisonerID(), "killer",
               5))
    inmates.append(
        Inmate("Vernon", "Schillinger", 1234, Prison.getNewPrisonerID(),
               "killer", 11))
    inmates.append(
        Inmate("Ryan", "O'Reily", 1234, Prison.getNewPrisonerID(), "killer",
               100))
    inmates.append(
        Inmate("Bob", "Rebadow", 1234, Prison.getNewPrisonerID(), "killer",
               45))
    inmates.append(
        Inmate("Kareem", "Said", 1234, Prison.getNewPrisonerID(), "killer",
               24))
    inmates.append(
        Inmate("Miguel", "Alvarez", 1234, Prison.getNewPrisonerID(), "killer",
               14))
    inmates.append(
        Inmate("Cyril", "O'Reily", 1234, Prison.getNewPrisonerID(), "killer",
               22))
    inmates.append(
        Inmate("Simon", "Adebisi", 1234, Prison.getNewPrisonerID(), "killer",
               67))
    inmates.append(
        Inmate("Kenny", "Wangler", 1234, Prison.getNewPrisonerID(), "killer",
               17))
    inmates.append(
        Inmate("Shirley", "Bellinger", 1234, Prison.getNewPrisonerID(),
               "killer", 75))
    inmates.append(
        Inmate("Omar", "White", 1234, Prison.getNewPrisonerID(), "killer", 44))
    inmates.append(
        Inmate("Chris", "Keller", 1234, Prison.getNewPrisonerID(), "killer",
               42))
    inmates.append(
        Inmate("Scott", "Ross ", 1234, Prison.getNewPrisonerID(), "killer",
               65))
    inmates.append(
        Inmate("Augustus", "Hill", 1234, Prison.getNewPrisonerID(), "killer",
               10))
    inmates.append(
        Inmate("Tobias", "Beecher", 1234, Prison.getNewPrisonerID(), "killer",
               5))
    inmates.append(
        Inmate("Vernon", "Schillinger", 1234, Prison.getNewPrisonerID(),
               "killer", 11))
    inmates.append(
        Inmate("Ryan", "O'Reily", 1234, Prison.getNewPrisonerID(), "killer",
               100))
    inmates.append(
        Inmate("Bob", "Rebadow", 1234, Prison.getNewPrisonerID(), "killer",
               45))
    inmates.append(
        Inmate("Kareem", "Said", 1234, Prison.getNewPrisonerID(), "killer",
               24))
    inmates.append(
        Inmate("Miguel", "Alvarez", 1234, Prison.getNewPrisonerID(), "killer",
               14))
    inmates.append(
        Inmate("Cyril", "O'Reily", 1234, Prison.getNewPrisonerID(), "killer",
               22))
    inmates.append(
        Inmate("Simon", "Adebisi", 1234, Prison.getNewPrisonerID(), "killer",
               67))
    inmates.append(
        Inmate("Kenny", "Wangler", 1234, Prison.getNewPrisonerID(), "killer",
               17))
    inmates.append(
        Inmate("Shirley", "Bellinger", 1234, Prison.getNewPrisonerID(),
               "killer", 75))
    inmates.append(
        Inmate("Omar", "White", 1234, Prison.getNewPrisonerID(), "killer", 44))
    inmates.append(
        Inmate("Chris", "Keller", 1234, Prison.getNewPrisonerID(), "killer",
               42))
    inmates.append(
        Inmate("Scott", "Ross ", 1234, Prison.getNewPrisonerID(), "killer",
               65))
    return inmates
Пример #5
0
class Game_board:

    # constructeur
    def __init__(self):
        self.nb_maison_dispo = 32
        self.nb_hotel_dispo = 12

        self.dice = Dice()

        # instanciation des cartes
        self.carte_chance = Carte_chance()
        self.carte_communaute = Carte_communaute()

        # self.proprietes = proprietes_data

        # instanciation des cases propriété
        self.proprietes = []
        for i in proprietes_data:
            self.proprietes.append(Propriete(i))
        # for p in self.proprietes: p.fiche()

        # instanciation des cases gare
        self.gares = []
        for i in gares_data:
            self.gares.append(Gare(i))
        # for g in self.gares: g.fiche()

        # instanciation des cases compagnie
        self.compagnies = []
        for i in compagnies_data:
            self.compagnies.append(Compagnie(i))
        # for c in self.compagnies: c.fiche()

        # instanciation de la prison
        self.prison = Prison()

        # tableau des joueurs
        self.joueurs = []

    def init_game(self):
        print("************************************\n" +
              "* BIENVENUE A LA TABLE DE MONOPOLY *\n" +
              "************************************\n")

        j = Joueur()
        self.joueurs.append(j)
        j = Joueur()
        self.joueurs.append(j)
        print("Il y a", len(self.joueurs), "joueurs à la table\n")
        while len(self.joueurs) < 5 and input(
                "Souhaitez-vous ajouter un nouveau joueur (max = 5) (o/N) ? "
        ).lower() == "o":
            j = Joueur()
            self.joueurs.append(j)
            print("Il y a", len(self.joueurs), "joueurs à la table\n")
        print("\nDébut de la partie\n")
        # for j in self.joueurs: j.fiche()

    def play(self):
        for j in self.joueurs:
            j.fiche()
            if j.position == 40:  #joueur en prison
                self.prison.libere(j, self.carte_chance, self.carte_communaute)
                if j.position != 40:
                    self.case_arrivee(j)  # le joueur a été libéré
            else:  # si joueur n'est pas en prison
                j.go(self.dice.lancer(j))
                self.case_arrivee(j)
                while j.nb_double > 0:  # tant le joueur a fait un double, il rejoue
                    print(j.nom, "rejoue")
                    j.go(self.dice.lancer(j))
                    self.case_arrivee(j)

    # analyse de la case d'arrivée
    def case_arrivee(self, j):  # joueur j
        if j.position == 0:  # case départ = 0
            j.cash += 200
            print("Vous avez reçu 200 € !")

        elif j.position in [7, 22, 36]:
            self.carte_chance.tirer_carte(
                j
            )  # carte chance voir si supprimer proprietes en mettant import dans chance
            if j.replay:
                j.replay = False
                self.case_arrivee(j)  # en cas de carte de déplacement

        elif j.position in [2, 17, 33]:
            self.carte_communaute.tirer_carte(
                j, self.joueurs)  # carte caisse de communauté
            if j.replay:
                j.replay = False
                self.case_arrivee(j)  # en cas de carte de déplacement
            if j.retire_chance:
                j.retire_chance = False
                self.carte_chance.tirer_carte(
                    j)  # si ne paye pas l'amende et préfere tirer chance

        elif j.position in proprietes_data:  # terrain
            p = Propriete(j.position)
            p.fiche()
            p.visite(j, self.joueurs)

        elif j.position in compagnies_data:  # électricité/eau
            c = Compagnie(j.position)
            c.fiche()
            c.visite(j, self.joueurs)

        elif j.position in gares_data:  # gare
            g = Gare(j.position)
            g.fiche()
            g.visite(j, self.joueurs)

        elif j.position in [0, 10,
                            20]:  # case départ, simple visite, parc gratuit
            if j.position == 0: print("Case départ")
            elif j.position == 10: print("Simple visite")
            elif j.position == 20: print("Parc gratuit")

        elif j.position == 30:  # allez en prison
            print("Allez directement en prison")
            j.position = 40
            j.nb_double = 0  # cas du joueur qui arrive ici par un double => ne rejoue pas

        elif j.position == 4:  # impôts
            print("Taxe sur le revenu: 200 €")
            j.payer(200)

        elif j.position == 38:  # taxe luxe
            print("Taxe de luxe: 100 €")
            j.payer(100)

        else:  # pour debug
            print("Erreur de case")
            exit()

#############################################################################
###########################  FONCTIONS POUR DEBUG ###########################
#############################################################################

    def list_all(self):
        print("****************\nListing complet")
        for i in range(1, 40):
            print("\ncase:", i)
            if i in self.proprietes:
                p = Propriete(i)
                p.fiche()
            elif i in self.compagnies:
                c = Compagnie(i)
                c.fiche()
            elif i in self.gares:
                g = Gare(i)
                g.fiche()

    def list_proprietes(self):
        print("****************\nListing propriétés")
        for i in range(1, 40):
            if i in self.proprietes:
                print("\ncase:", i)
                p = Propriete(i)
                p.fiche()

    def list_gares(self):
        print("****************\nListing gares")
        for i in range(1, 40):
            if i in self.gares:
                print("\ncase:", i)
                g = Gare(i)
                g.fiche()

    def list_compagnies(self):
        print("****************\nListing compagnies")
        for i in range(1, 40):
            if i in self.compagnies:
                print("\ncase:", i)
                c = Compagnie(i)
                c.fiche()

    # listing des cartes chance
    def list_chance(self):
        print("****************\nListing cartes chance")
        # for i in range(len(self.carte_chance.jeu_carte)): print(self.carte_chance.jeu_carte.pop(len(self.carte_chance.jeu_carte)-1)[0])
        for c in self.carte_chance.jeu_carte:
            print(self.carte_chance.jeu_carte[c])

    # listing des cartes caisse de communauté
    def list_communaute(self):
        print("****************\nListing cartes caisse de communauté")
        # for i in range(len(self.carte_communaute.jeu_carte)): print(self.carte_communaute.jeu_carte.pop(len(self.carte_communaute.jeu_carte)-1)[0])
        for c in self.carte_communaute.jeu_carte:
            print(self.carte_communaute.jeu_carte[c])
Пример #6
0
from prison import Prison
from user_interface import UI

prison = Prison()
UI = UI()
UI.print_menu()

# TO-DO NEXT
"""
Implement actual game (days actually running)
    -Somehow add people to the room they should be in at that hour
        -Remove them at end of hour
    -Implement gossip system
    -Gaining and spending
    -Update morale / skill
    -Attempt escapes
        -Send to solitary for some amount of days?
    -Check win condition

"""
Пример #7
0
#imports
from inmate import Inmate
from warden import Warden
from prison import Prison
from prisonBlock import PrisonBlock

from setupHelper import createInmates

#create chief warden
w = Warden("Leo", "Glynn", 6546876, 100)

#create prison
oz = Prison("Oz", w)

#create wardens
ward01 = Warden("Tim", "McManus", 323243, 20)
ward02 = Warden("Sean", "Murphy", 456788, 40)

#create prison blocks
pbA = PrisonBlock("Emerald City", 3, ward01)
pbB = PrisonBlock("Block B", 5, ward02)

#add blocks to prison
oz.addBlock(pbA)
oz.addBlock(pbB)

print("\n")

#print block strings
print(oz.getBlocksString())