Exemple #1
0
 def __init__(self):
     d = "TESTER initially defects to test what the other player will do. "+\
     "If the other player defects ever, TESTER apologizes by cooperating "+\
     "and then mirrors the partner's moves thereafter. If the other "+\
     "player does not retaliate, TESTER cooperates twice but then defects "+\
     "on and off every other turn."
     BotPlayer.__init__(self, "TESTER", description=d)
Exemple #2
0
 def __init__(self, p_sneaky=0.1):
     d = "JOSS defaults to cooperation on the first turn, and "+\
     "thereafter mirrors its partner's previous move, except after its "+\
     "partner cooperates JOSS defects with some probability to see what "+\
     "it can get away with every once in a while."
     BotPlayer.__init__(self, "JOSS_"+str(p_sneaky), description=d)
     self.p_sneaky = p_sneaky
Exemple #3
0
 def __init__(self):
     d = "TESTER initially defects to test what the other player will do. "+\
     "If the other player defects ever, TESTER apologizes by cooperating "+\
     "and then mirrors the partner's moves thereafter. If the other "+\
     "player does not retaliate, TESTER cooperates twice but then defects "+\
     "on and off every other turn."
     BotPlayer.__init__(self, "TESTER", description=d)
Exemple #4
0
 def __init__(self, p_sneaky=0.1):
     d = "JOSS defaults to cooperation on the first turn, and "+\
     "thereafter mirrors its partner's previous move, except after its "+\
     "partner cooperates JOSS defects with some probability to see what "+\
     "it can get away with every once in a while."
     BotPlayer.__init__(self, "JOSS_" + str(p_sneaky), description=d)
     self.p_sneaky = p_sneaky
Exemple #5
0
 def __init__(self):
     d = "PAVLOV defaults to cooperation on the first turn, and "+\
     "thereafter cooperates if and only if both players made the same "+\
     "choice last turn. This is known as 'win-stay, lose-shift', because "+\
     "PAVLOV repeats its own last move after it receives T or R (the good "+\
     "scores) and changes its move after it receives P or S (the bad "+\
     "scores), like a reflex demonstrated in Pavlov's dog experiment."
     BotPlayer.__init__(self, "PAVLOV", d)
Exemple #6
0
 def __init__(self):
     d = "PAVLOV defaults to cooperation on the first turn, and "+\
     "thereafter cooperates if and only if both players made the same "+\
     "choice last turn. This is known as 'win-stay, lose-shift', because "+\
     "PAVLOV repeats its own last move after it receives T or R (the good "+\
     "scores) and changes its move after it receives P or S (the bad "+\
     "scores), like a reflex demonstrated in Pavlov's dog experiment."
     BotPlayer.__init__(self, "PAVLOV", d)
Exemple #7
0
 def __init__(self, p_generous=0.1):
     d = "GENEROUS_TIT_FOR_TAT defaults to cooperation on the first turn, "+\
     "and thereafter mirrors its partner's previous move, except after "+\
     "its partner defects GENEROUS_TIT_FOR_TAT cooperates with some "+\
     "probability to forgive occasional mistakes and avoid unnecessary "+\
     "mutual punishment."
     BotPlayer.__init__(self, "GENEROUS_TIT_FOR_TAT_"+str(p_generous),\
                         description=d)
     self.p_generous = p_generous
Exemple #8
0
 def __init__(self, p_cooperate=0.5):
     d = "CHAMPION cooperates for about 1/20 of the expected length of "+\
     "interaction, mirrors its partner's previous move for about 3/40 of "+\
     "the expected length of interaction, and then cooperates unless all "+\
     "three of the following conditions are true: its partner defected "+\
     "last turn, its partner cooperated less than 60% of the time, and "+\
     "a randomly generated number between 0 and 1 is less than its "+\
     "partner's defection rate."
     BotPlayer.__init__(self, "CHAMPION", description=d)
Exemple #9
0
 def __init__(self, p_generous=0.1):
     d = "GENEROUS_TIT_FOR_TAT defaults to cooperation on the first turn, "+\
     "and thereafter mirrors its partner's previous move, except after "+\
     "its partner defects GENEROUS_TIT_FOR_TAT cooperates with some "+\
     "probability to forgive occasional mistakes and avoid unnecessary "+\
     "mutual punishment."
     BotPlayer.__init__(self, "GENEROUS_TIT_FOR_TAT_"+str(p_generous),\
                         description=d)
     self.p_generous = p_generous
Exemple #10
0
 def __init__(self, p_cooperate=0.5):
     d = "CHAMPION cooperates for about 1/20 of the expected length of "+\
     "interaction, mirrors its partner's previous move for about 3/40 of "+\
     "the expected length of interaction, and then cooperates unless all "+\
     "three of the following conditions are true: its partner defected "+\
     "last turn, its partner cooperated less than 60% of the time, and "+\
     "a randomly generated number between 0 and 1 is less than its "+\
     "partner's defection rate."
     BotPlayer.__init__(self, "CHAMPION", description=d)
Exemple #11
0
 def __init__(self, nice=True):
     d = "STATBOT cooperates, then defects, then after that calculates its average score per move"+\
     " for cooperation and defect and chooses whichever one is higher, in the case of a tie, "+\
     "NICE_STATBOT cooperates and MEAN_STATBOT defects"
     self.nice = nice
     if nice:
         n = 'NICE_STATBOT'
     else:
         n = 'MEAN_STATBOT'
     BotPlayer.__init__(self, n, d)
Exemple #12
0
 def __init__(self, soft=True):
     d = "MAJORITY cooperates as long as its partner has cooperated more "+\
     "than it has defected (if partner has cooperated and defected equal "+\
     "amounts, MAJORITY cooperates if it is soft and defects if it is "+\
     "hard)."
     if soft:
         name = "MAJORITY_SOFT"
     else:
         name = "MAJORITY_HARD"
     BotPlayer.__init__(self, name, description=d)
     self.soft = soft
Exemple #13
0
 def __init__(self, soft=True):
     d = "MAJORITY cooperates as long as its partner has cooperated more "+\
     "than it has defected (if partner has cooperated and defected equal "+\
     "amounts, MAJORITY cooperates if it is soft and defects if it is "+\
     "hard)."
     if soft:
         name = "MAJORITY_SOFT"
     else:
         name = "MAJORITY_HARD"
     BotPlayer.__init__(self, name, description=d)
     self.soft = soft
Exemple #14
0
 def __init__(self, optimistic=True):
     d = "DOWNING tries to maximize expected gains by testing the water "+\
     "with its partner. The idea is that if its partner seems responsive "+\
     "to what DOWNING is doing, DOWNING will cooperate, but if the other "+\
     "player seems unresponsive, DOWNING will try to get away with "+\
     "whatever it can by defecting. DOWNING does this by keeping an "+\
     "estimate of the probability of the other player cooperating given "+\
     "DOWNING's last move. The initial estimates depend on DOWNING's "+\
     "outlook (optimistic or pessimistic)."
     if optimistic:
         name = "OPT_DOWNING"
     elif not optimistic:
         name = "PESS_DOWNING"
     BotPlayer.__init__(self, name, description=d)
     self.optimistic = optimistic
Exemple #15
0
 def __init__(self, optimistic=True):
     d = "DOWNING tries to maximize expected gains by testing the water "+\
     "with its partner. The idea is that if its partner seems responsive "+\
     "to what DOWNING is doing, DOWNING will cooperate, but if the other "+\
     "player seems unresponsive, DOWNING will try to get away with "+\
     "whatever it can by defecting. DOWNING does this by keeping an "+\
     "estimate of the probability of the other player cooperating given "+\
     "DOWNING's last move. The initial estimates depend on DOWNING's "+\
     "outlook (optimistic or pessimistic)."
     if optimistic:
         name = "OPT_DOWNING"
     elif not optimistic:
         name = "PESS_DOWNING"
     BotPlayer.__init__(self, name, description=d)
     self.optimistic = optimistic
Exemple #16
0
 def add_bot(self):
     if not any(
             isinstance(player, BotPlayer)
             for player in self.waiting_players.values()):
         logger.info('adding a bot')
         bot = BotPlayer()
         self.add_player(bot)
Exemple #17
0
def play_game():
    game = GameController()
    tracker = PlayTracker()
    bot = BotPlayer(MODEL_FILE, PLAYS_CATEGORIES_FILE, RESULT_CATEGORIES_FILE)

    while game.is_playing():
        ui.draw_board(game)

        x, y = -1, -1
        if game.current_player_A():
            x, y = ui.read_user_play(game)
        else:
            x, y = bot.play(game)
            ui.print_bot_play(x, y)

        tracker.track(game, x, y)
        game.play(x, y)

    ui.draw_winner(game)
    tracker.store(game, PLAYS_FILE)
    train_model(PLAYS_FILE, MODEL_FILE, PLAYS_CATEGORIES_FILE,
                RESULT_CATEGORIES_FILE)
Exemple #18
0
    def __init__(self, fname, use_bots=False):
        self.waiting_players = {}
        self.db = Database(fname)
        self.rooms = self.db.load_unfinished_rooms()
        self.t = 0
        self.timer = None
        self.use_bots = use_bots

        if use_bots:
            for room in self.rooms:
                for i, nick in enumerate(room.nicks):
                    # XXX recognize bots in a nicer way
                    if nick == 'Bot':
                        bot = BotPlayer()
                        room.add_player(i, bot)
Exemple #19
0
 def __init__(self):
     d = "FRIEDMAN is the permanent retaliator. It cooperates until its "+\
     "partner defects, after which FRIEDMAN defects for the rest of the "+\
     "interaction."
     BotPlayer.__init__(self, "FRIEDMAN", description=d)
Exemple #20
0
 def __init__(self):
     d = "ALL_C cooperates unconditionally."
     BotPlayer.__init__(self, "ALL_C", description=d)
Exemple #21
0
 def __init__(self):
     d = "ALL_C cooperates unconditionally."
     BotPlayer.__init__(self, "ALL_C", description=d)
Exemple #22
0
 def __init__(self):
     d = "FRIEDMAN is the permanent retaliator. It cooperates until its "+\
     "partner defects, after which FRIEDMAN defects for the rest of the "+\
     "interaction."
     BotPlayer.__init__(self, "FRIEDMAN", description=d)
Exemple #23
0
 def __init__(self):
     ## TODO: read pages 45-46 of Axelrod and describe this
     d = None
     BotPlayer.__init__(self, "TRANQUILIZER", d)
Exemple #24
0
 def __init__(self, p_cooperate=0.5):
     d = "RANDOM chooses randomly between cooperation and defection with "+\
     "some specified probability for each, independent of its partner's "+\
     "moves."
     BotPlayer.__init__(self, "RANDOM_"+str(p_cooperate), description=d)
     self.p_cooperate = p_cooperate
Exemple #25
0
 def __init__(self):
     d = "ALL_D defects unconditionally."
     BotPlayer.__init__(self, "ALL_D", description=d)
Exemple #26
0
 def __init__(self):
     d = "TWO_TITS_FOR_TAT cooperates unless its partner defects in which "+\
     "case TWO_TITS_FOR_TAT retaliates with two defections."
     BotPlayer.__init__(self, "TWO_TITS_FOR_TAT", description=d)
Exemple #27
0
 def __init__(self):
     d = "TIT_FOR_TWO_TATS defects if and only if its partner has "+\
     "defected for the past two turns."
     BotPlayer.__init__(self, "TIT_FOR_TWO_TATS", description=d)
Exemple #28
0
                .format(human_player_count))
            continue

        elif human_player_count + ai_player_count == 0:
            print(
                "Do you really want to start a game with 0 players? I don't think so\n"
            )
            continue

        elif human_player_count + ai_player_count == 1:
            print("The game can't start with only one player!\n")
            continue

        for i in range(0, ai_player_count):
            bot_name = "Bot{0}".format(i + 1)
            bot_player = BotPlayer(bot_name)
            bot_player.draw_cards(7, game)
            game.add_player(bot_player)

        for i in range(0, human_player_count):
            human_player = None
            player_name = input(
                "Player {0}'s name? Default is Player{0}: ".format(i + 1))

            if player_name in [player.name for player in game.players]:
                while True:
                    player_name = input(
                        "That name is already being used. Please use a different name: "
                    )
                    if player_name in [player.name for player in game.players]:
                        continue
Exemple #29
0
 def __init__(self):
     d = "ALL_D defects unconditionally."
     BotPlayer.__init__(self, "ALL_D", description=d)
Exemple #30
0
 def __init__(self):
     ## TODO: read pages 45-46 of Axelrod and describe this
     d = None
     BotPlayer.__init__(self, "TRANQUILIZER", d)
Exemple #31
0
 def __init__(self):
     d = "EATHERLY defaults to cooperation, but keeps track of how many "+\
     "times the other player has defected, so after a defection by the "+\
     "other player, EATHERLY can defect with probability equal to the "+\
     "ratio of its partner's defections to the total number of moves so far."
     BotPlayer.__init__(self, "EATHERLY", d)
Exemple #32
0
 def __init__(self):
     d = "SUSPICIOUS_TIT_FOR_TAT defaults to defection on the first turn, "+\
     "and thereafter mirrors its partner's previous move."
     BotPlayer.__init__(self, "SUSPICIOUS_TIT_FOR_TAT", description=d)
Exemple #33
0
 def __init__(self):
     d = "SUSPICIOUS_TIT_FOR_TAT defaults to defection on the first turn, "+\
     "and thereafter mirrors its partner's previous move."
     BotPlayer.__init__(self, "SUSPICIOUS_TIT_FOR_TAT", description=d)
Exemple #34
0
 def __init__(self):
     d = "TWO_TITS_FOR_TAT cooperates unless its partner defects in which "+\
     "case TWO_TITS_FOR_TAT retaliates with two defections."
     BotPlayer.__init__(self, "TWO_TITS_FOR_TAT", description=d)
Exemple #35
0
 def __init__(self, p_cooperate=0.5):
     d = "RANDOM chooses randomly between cooperation and defection with "+\
     "some specified probability for each, independent of its partner's "+\
     "moves."
     BotPlayer.__init__(self, "RANDOM_" + str(p_cooperate), description=d)
     self.p_cooperate = p_cooperate
Exemple #36
0
 def __init__(self):
     d = "EATHERLY defaults to cooperation, but keeps track of how many "+\
     "times the other player has defected, so after a defection by the "+\
     "other player, EATHERLY can defect with probability equal to the "+\
     "ratio of its partner's defections to the total number of moves so far."
     BotPlayer.__init__(self, "EATHERLY", d)
Exemple #37
0
 def __init__(self):
     d = "TIT_FOR_TAT defaults to cooperation on the first turn, and "+\
     "thereafter mirrors its partner's previous move."
     BotPlayer.__init__(self, "TIT_FOR_TAT", description=d)
Exemple #38
0
 def __init__(self):
     d = "TIT_FOR_TAT defaults to cooperation on the first turn, and "+\
     "thereafter mirrors its partner's previous move."
     BotPlayer.__init__(self, "TIT_FOR_TAT", description=d)
Exemple #39
0
 def __init__(self):
     d = "TIT_FOR_TWO_TATS defects if and only if its partner has "+\
     "defected for the past two turns."
     BotPlayer.__init__(self, "TIT_FOR_TWO_TATS", description=d)