def main(games_in_a_set=1000):
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True, image_exporting=0)
    for n in [6]:
        for thresh in range(1, 250, 25):

            trade_count = []
            winners = [0, 0, 0]

            for i in range(games_in_a_set):
                # Play game.
                player1 = monopoly.Player(
                    1,
                    buying_threshold=thresh,
                    dynamic_ordering=True,
                    n=n,
                )
                player2 = monopoly.Player(
                    2,
                    dynamic_ordering=True,
                    buying_threshold=randint(1, 500),
                    n=randint(1, 18),
                )

                game0.new_players([player1, player2])
                results = game0.play()

                # Store length.
                winners[results['winner']] += 1
                trade_count.append(results['trade count'])

            print(winners, n, thresh, sum(trade_count) / games_in_a_set)
Exemple #2
0
def optimize(games_in_a_set=10000):
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True, image_exporting=0)
    for c in range(-1000, 1, 100):
        trade_count = []
        winners = [0, 0, 0]
        for i in range(games_in_a_set):
            # Play game.
            player1 = monopoly.Player(
                1,
                dynamic_ordering=True,
                # group_ordering=random_ordering(),
                c=c,
                n=6,
            )
            player2 = monopoly.Player(2,
                                      group_ordering=best_ordering(),
                                      step_threshold=True,
                                      buying_threshold=1000)

            game0.new_players([player1, player2])
            results = game0.play()

            # Store length.
            winners[results['winner']] += 1
            trade_count.append(results['trade count'])

        print(winners, c, sum(trade_count) / games_in_a_set)
Exemple #3
0
def main(games_in_a_set=10000):
    game0 = monopoly.Game(
        cutoff=1000,
        trading_enabled=True,
        image_exporting=0,
    )

    trade_count = []
    winners = [0, 0, 0]
    for i in range(games_in_a_set):
        # Play game.
        player1 = monopoly.Player(
            1,
            buying_threshold=500,
            group_ordering=random_ordering(),
            #step_threshold=True,
        )
        player2 = monopoly.Player(2,
                                  dynamic_ordering=True,
                                  n=6,
                                  buying_threshold=500,
                                  jail_time=0)

        game0.new_players([player1, player2])
        results = game0.play()

        # Store length.
        winners[results['winner']] += 1
        trade_count.append(results['trade count'])

    print(winners, sum(trade_count) / games_in_a_set)
Exemple #4
0
def main():
    rule_sets = generate_rules()
    base_games = 100
    desired_radius = 1

    for rule_set in rule_sets:
        game0 = monopoly.Game(
            cutoff=1000,
            trading_enabled=rule_set[5],
            free_parking_pool=rule_set[0],
            double_on_go=rule_set[1],
            no_rent_in_jail=rule_set[2],
            trip_to_start=rule_set[3],
            snake_eyes_bonus=rule_set[4],
        )

        counter = 0
        lengths_sum = 0
        lengths = []
        interval_size = desired_radius + 100
        stalemates = 0

        while (counter < base_games) or interval_size > desired_radius:
            # Play game.
            player1 = monopoly.Player(
                1,
                buying_threshold=1500,
                group_ordering=random_ordering(),
                step_threshold=True,
            )
            player2 = monopoly.Player(2,
                                      buying_threshold=1500,
                                      group_ordering=random_ordering(),
                                      step_threshold=True)

            game0.new_players([player1, player2])
            results = game0.play()

            # Store length.
            length = results['length']

            if length == 1000:
                stalemates += 1
            else:
                counter += 1
                lengths.append(length)
                lengths_sum += length

                interval_size = 1.960 * (numpy.std(lengths) /
                                         math.sqrt(counter))

                # print(counter, lengths_sum / counter, interval_size)

        print(lengths_sum / counter, stalemates / counter, numpy.std(lengths),
              counter, rule_set)
def main(games_in_a_set=100000):
    matrix = numpy.zeros((10, 10))
    game_counter = 0
    game0 = monopoly.Game(cutoff=1000, trading_enabled=False)

    while game_counter < games_in_a_set:
        print(game_counter)
        # Play game.
        player1 = monopoly.Player(1, buying_threshold=500, group_ordering=random_ordering(), step_threshold=True)
        player2 = monopoly.Player(2, buying_threshold=500, group_ordering=random_ordering(), step_threshold=True)

        game0.new_players([player1, player2])
        results = game0.play()

        if results['winner'] != 0:
            game_counter += 1
            winner = game0.active_players[0]
            loser = game0.inactive_players[0]

            winner.add_railroads_and_utilities()
            loser.add_railroads_and_utilities()

            for winning_group in winner.monopolies:
                for losing_group in loser.monopolies:
                    matrix[group_index(winning_group)][group_index(losing_group)] += 1

    matrix = normalize_columns(matrix)

    graph_matrix = []
    group_names = ["Brown", "Light Blue", "Pink", "Orange",
                   "Red", "Yellow", "Green", "Dark Blue",
                   "Utility", "Railroad"]

    graph_matrix.append([""] + group_names)

    for i in range(len(matrix)):
        row = [group_names[i]]
        for j in matrix[i]:
            row.append(float(j))
        graph_matrix.append(row)

    # Save matrix
    with open("PageRankEndGroupsMatrix.csv", 'w', newline='') as csvfile:
        output_file = csv.writer(csvfile, quotechar=',')

        for row in graph_matrix:
            output_file.writerow(row)

    eigenvalues, eigenvectors = numpy.linalg.eig(matrix)
    print(eigenvalues[0])
    for element in normalize_data(eigenvectors[:, 0]):
        print(element)
def main():
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True, image_exporting=0)

    base_games = 1000
    counter = 0
    winners = [0, 0, 0]
    interval_size = 10
    trade_count = []

    while (counter < base_games) or interval_size > 0.01:
        counter += 1
        # Play game.
        player1 = monopoly.Player(
            1,
            buying_threshold=1500,
            group_ordering=[
                'Railroad', 'Dark Blue', 'Utility', 'Green', 'Red', 'Yellow',
                'Orange', 'Light Blue', 'Pink', 'Brown'
            ],
            #('Railroad', 'Utility', 'Dark Blue', 'Green', 'Red', 'Yellow', 'Orange', 'Pink','Light Blue', 'Brown'),
            #group_ordering=random_ordering(),
            step_threshold=True,
        )
        # player1 = monopoly.Player(1,
        #                          buying_threshold=100,
        #                          dynamic_ordering=True,
        #                          n=6,

        #)
        player2 = monopoly.Player(
            2,
            buying_threshold=1500,
            group_ordering=random_ordering(),
            step_threshold=True,
        )

        game0.new_players([player1, player2])
        results = game0.play()

        # Store length.
        winners[results['winner']] += 1

        p = winners[1] / counter
        interval_size = 1.960 * math.sqrt((p * (1 - p)) / counter)

        trade_count.append(results['trade count'])

        # print(counter, p, interval_size)

    print(winners[0] / counter, winners[1] / counter, winners[2] / counter,
          counter)
    print(sum(trade_count) / counter)
Exemple #7
0
def go_record(games_in_a_set=1000):
    game0 = monopoly.Game(cutoff=1000, trading_enabled=False)
    go_record = []

    for i in range(games_in_a_set):
        # Play game.
        player1 = monopoly.Player(1, buying_threshold=100)
        player2 = monopoly.Player(2, buying_threshold=100)
        game0.new_players([player1, player2])
        results = game0.play()

        # Store length.
        go_record.extend(player1.go_record)

    print(sum(go_record) / len(go_record))
def main():
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True, image_exporting=0)

    for n in [6]:  # range(1, 37):
        for threshold in [100]:  # range(100, 1001, 100):
            base_games = 1000
            counter = 0
            winners = [0, 0, 0]
            interval_size = 10
            trade_count = []

            while (counter < base_games) or interval_size > 0.01:
                counter += 1
                # Play game.
                player1 = monopoly.Player(
                    1,
                    buying_threshold=threshold,
                    dynamic_ordering=True,
                    n=n,
                )
                # player2 = monopoly.Player(2, buying_threshold=randint(1, 1000),
                #                          dynamic_ordering=True,
                #                          n=randint(1, 36)
                #)
                player2 = monopoly.Player(2,
                                          buying_threshold=1500,
                                          group_ordering=random_ordering(),
                                          step_threshold=True)

                game0.new_players([player1, player2])
                results = game0.play()

                # Store length.
                winners[results['winner']] += 1

                p = winners[1] / counter
                interval_size = 1.960 * math.sqrt((p * (1 - p)) / counter)
                trade_count.append(results['trade count'])

                # print(counter, p, interval_size)

            print(winners[0] / counter, winners[1] / counter,
                  winners[2] / counter, counter, n, threshold)
            print(sum(trade_count) / counter)
def test(games_in_a_set=1):
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True, image_exporting=0)
    for i in range(games_in_a_set):
        # Play game.
        player1 = monopoly.Player(
            1,
            dynamic_ordering=True,
            n=18,
            c=0,
        )
        player2 = monopoly.Player(
            2,
            dynamic_ordering=True,
            n=6,
            c=0,
        )

        game0.new_players([player1, player2])
        results = game0.play()
Exemple #10
0
def main3(games_in_a_set=1000):
    for m1 in range(1, 21):
        for m2 in range(1, 21):
            game0 = monopoly.Game(cutoff=1000,
                                  trading_enabled=True,
                                  image_exporting=0,
                                  matrix1=m1,
                                  matrix2=m2)
            trade_count = []
            winners = [0, 0, 0]
            for i in range(games_in_a_set):
                # Play game.
                player1 = monopoly.Player(
                    1,
                    buying_threshold=100,
                    # group_ordering=random_ordering(),
                    dynamic_ordering=True,
                    static_threshold=False)
                player2 = monopoly.Player(
                    2,
                    buying_threshold=100,
                    group_ordering=[
                        "Railroad", "Light Blue", "Orange", "Pink", "Red",
                        "Yellow", "Green", "Dark Blue", "Utility", "Brown"
                    ],
                    # group_ordering=random_ordering(),
                    static_threshold=True)

                game0.new_players([player1, player2])
                results = game0.play()

                # Store length.
                winners[results['winner']] += 1
                trade_count.append(results['trade count'])

            print(winners, m1, m2)
        '''print("**")
        print("trades:",results['trade count'])
        for trade_pair in game0.trades:
            print(trade_pair[0].name, "--", trade_pair[1].name)'''
        '''print("avg. trades", sum(trade_count) / games_in_a_set)
def main():
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True, image_exporting=0)

    base_games = 1000
    counter = 0
    winners = [0, 0, 0]
    interval_size = 10
    trade_count = []

    while (counter < base_games) or interval_size > 0.01:
        counter += 1
        # Play game.
        player1 = monopoly.Player(
            1,
            buying_threshold=1500,
            group_ordering=best_ordering(),
            step_threshold=True,
        )
        player2 = monopoly.Player(
            2,
            buying_threshold=1500,
            group_ordering=random_ordering(),
            step_threshold=True,
        )

        game0.new_players([player1, player2])
        results = game0.play()

        # Store length.
        winners[results['winner']] += 1

        p = winners[1] / counter
        interval_size = 1.960 * math.sqrt((p * (1 - p)) / counter)

        trade_count.append(results['trade count'])

        # print(counter, p, interval_size)

    print(winners[0] / counter, winners[1] / counter, winners[2] / counter,
          counter)
    print(sum(trade_count) / counter)
Exemple #12
0
def main(games_in_a_set=5000):
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True)
    for j in range(40):
        thresh = j / 200
        winners = [0, 0, 0]
        for i in range(games_in_a_set):
            # Play game.
            player1 = monopoly.Player(1,
                                      buying_threshold=thresh,
                                      group_ordering=random_ordering())
            player2 = monopoly.Player(2,
                                      buying_threshold=uniform(0, 1),
                                      group_ordering=random_ordering())

            game0.new_players([player1, player2])
            results = game0.play()

            # Store length.
            winners[results['winner']] += 1

        print(winners, thresh)
Exemple #13
0
def main(games_in_a_set=100000):
    for shuffle in [True, False]:
        game0 = monopoly.Game(cutoff=1000, trading_enabled=False, image_exporting=0, shuffle=shuffle, trip_to_start=True)

        trade_count = []
        winners = [0, 0, 0]
        wins1 = []
        wins2 = []
        for i in range(games_in_a_set):
            # Play game.
            player1 = monopoly.Player(1,
                                      buying_threshold=500,
                                      group_ordering=random_ordering(),

            )
            player2 = monopoly.Player(2,
                                      buying_threshold=500,
                                      group_ordering=random_ordering(),
            )

            game0.new_players([player1, player2])
            results = game0.play()

            # Store length.
            winners[results['winner']] += 1
            if results['winner'] == 1:
                wins1.append(1)
                wins2.append(0)
            elif results['winner'] == 2:
                wins1.append(0)
                wins2.append(1)
            else:
                wins1.append(0)
                wins2.append(0)

            trade_count.append(results['trade count'])

        print(mean_confidence_interval(wins1))
        print(mean_confidence_interval(wins2))
        print(winners, shuffle, sum(trade_count) / games_in_a_set)
Exemple #14
0
def main():
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True, image_exporting=0)

    base_games = 1000
    counter = 0
    wins = []

    interval_size = 10

    while (counter < base_games) or interval_size > 0.01:
        counter += 1
        # Play game.
        player1 = monopoly.Player(
            1,
            buying_threshold=1000,
            group_ordering=best_ordering(),
            step_threshold=True,
        )
        player2 = monopoly.Player(
            2,
            buying_threshold=500,
            group_ordering=random_ordering(),
            step_threshold=False,
        )

        game0.new_players([player1, player2])
        results = game0.play()

        # Store length.
        if results['winner'] == 1:
            wins.append(1)
        else:
            wins.append(0)

        p = sum(wins) / counter
        interval_size = 1.960 * math.sqrt((p * (1 - p)) / counter)

        print(counter, p, interval_size)
Exemple #15
0
def main2(games_in_a_set=100):
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True)

    winners = [0, 0, 0]
    for i in range(games_in_a_set):
        # Play game.
        player1 = monopoly.Player(1,
                                  buying_threshold=500,
                                  group_ordering=random_ordering(),
                                  static_threshold=True)
        # player2 = monopoly.Player(2, buying_threshold=randint(1, 500), group_ordering=random_ordering(),static_threshold=True)
        player2 = monopoly.Player(2,
                                  buying_threshold=500,
                                  group_ordering=random_ordering(),
                                  static_threshold=True)

        game0.new_players([player1, player2])
        results = game0.play()

        # Store length.
        winners[results['winner']] += 1

    print(winners)
def main():
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True, image_exporting=0)

    for t in range(20, 40, 1):
        base_games = 1000
        counter = 0
        winners = [0, 0, 0]
        interval_size = 10

        while (counter < base_games) or interval_size > 0.01:
            counter += 1
            # Play game.
            player1 = monopoly.Player(1,
                                      n=6,
                                      buying_threshold=1500,
                                      group_ordering=best_ordering(),
                                      t=t,
                                      hybrid_trading=True,
                                      step_threshold=True)
            player2 = monopoly.Player(2,
                                      buying_threshold=1500,
                                      group_ordering=random_ordering(),
                                      step_threshold=True)

            game0.new_players([player1, player2])
            results = game0.play()

            # Store length.
            winners[results['winner']] += 1

            p = winners[1] / counter
            interval_size = 1.960 * math.sqrt((p * (1 - p)) / counter)

            # print(counter, p, interval_size)

        print(winners[0] / counter, winners[1] / counter, winners[2] / counter,
              counter, t)
def main(desired_radius=0.01):
    matrix = numpy.zeros((40, 40))

    game0 = monopoly.Game(cutoff=1000, trading_enabled=True)

    props = []
    for board_space in game0.board:
        if board_space.is_property:
            props.append(board_space.id)

    main_counter = 0
    for prop1 in props:
        for prop2 in props[props.index(prop1) + 1:]:
            winners = [0, 0, 0]
            base_games = 10
            game_counter = 0
            current_radius = 10

            while (game_counter <
                   base_games) or current_radius > desired_radius:
                # Play game.
                player1 = monopoly.Player(1,
                                          buying_threshold=1500,
                                          step_threshold=True,
                                          group_ordering=random_ordering(),
                                          initial_properties=[prop1])
                player2 = monopoly.Player(2,
                                          buying_threshold=1500,
                                          step_threshold=True,
                                          group_ordering=random_ordering(),
                                          initial_properties=[prop2])

                game0.new_players([player1, player2])
                results = game0.play()
                winners[results['winner']] += 1

                game_counter += 1

                p = winners[1] / game_counter
                current_radius = 1.960 * math.sqrt(
                    (p * (1 - p)) / game_counter)

                #print(game_counter, p, current_radius)

            main_counter += 1
            print(main_counter)

            matrix[prop1][prop2] += winners[1] / game_counter
            matrix[prop2][prop1] += winners[2] / game_counter

    matrix = normalize_columns(matrix)

    # Save matrix
    with open("PageRankStart_Matrix.csv", 'w', newline='') as csvfile:
        output_file = csv.writer(csvfile, quotechar=',')

        for row in matrix:
            output_file.writerow(row)

    eigenvalues, eigenvectors = numpy.linalg.eig(matrix)
    for i in range(len(eigenvalues)):
        print("*************************")
        print(eigenvalues[i])
        normalized_vector = normalize_data(eigenvectors[:, i])
        for element in normalized_vector:
            print(element)
def main(games_in_a_set=10000):
    matrix = numpy.zeros((28, 28))
    game_counter = 0
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True)

    while game_counter < games_in_a_set:
        print(game_counter)
        # Play game.
        player1 = monopoly.Player(
            1,  # dynamic_ordering=True,
            # c=1, n=randint(1, 13))
            buying_threshold=500,
            group_ordering=random_ordering(),
            step_threshold=True)
        player2 = monopoly.Player(
            2,  # dynamic_ordering=True,
            # c=1, n=randint(1, 13))
            buying_threshold=500,
            group_ordering=random_ordering(),
            step_threshold=True)

        game0.new_players([player1, player2])
        results = game0.play()

        if results['winner'] != 0:
            game_counter += 1
            winner = game0.active_players[0]
            loser = game0.inactive_players[0]

            for winning_prop in winner.inventory:
                for losing_prop in loser.inventory:
                    matrix[winning_prop.prop_id][losing_prop.prop_id] += 1

    matrix = normalize_columns(matrix)

    graph_matrix = []
    prop_names = []

    for prop in game0.board:
        if prop.is_property:
            prop_names.append(safe_name(prop.name))

    graph_matrix.append([""] + prop_names)

    for i in range(len(matrix)):
        row = [prop_names[i]]
        for j in matrix[i]:
            row.append(float(j))
        graph_matrix.append(row)

    # Save matrix
    with open("PageRankEndMatrix.csv", 'w', newline='') as csvfile:
        output_file = csv.writer(csvfile, quotechar=',')

        for row in graph_matrix:
            output_file.writerow(row)

    eigenvalues, eigenvectors = numpy.linalg.eig(matrix)
    for i in range(len(eigenvalues)):
        print("*************************")
        print(eigenvalues[i])
        for element in eigenvectors[:, i]:
            if element.real != 0:
                print(element.real)
def main():
    with open('pageRank_DynamicGraph.csv', 'w', newline='') as csvfile:
        output_file = csv.writer(csvfile, quotechar=',')
        game0 = monopoly.Game(cutoff=1000,
                              trading_enabled=True,
                              image_exporting=0)
        groups = [
            "Brown", "Light Blue", "Pink", "Orange", "Red", "Yellow", "Green",
            "Dark Blue", "Utility", "Railroad"
        ]

        counter = 0

        matrix = numpy.zeros((10, 10))

        for i in range(100000):
            counter += 1
            # Play game.
            player1 = monopoly.Player(
                1,
                buying_threshold=100,
                n=6,
                dynamic_ordering=True,
            )

            player2 = monopoly.Player(
                2,
                buying_threshold=1500,
                group_ordering=random_ordering(),
                step_threshold=True,
            )

            game0.new_players([player1, player2])
            results = game0.play()

            for trade in game0.trades:
                # print(trade[1].group, trade[0].group)
                g1to2 = groups.index(trade[0].group)
                g2to1 = groups.index(trade[1].group)
                matrix[g2to1][g1to2] += 1

            if counter % 1000 == 0:
                print(matrix)
                print(counter)
                new_matrix = normalize_columns(copy.deepcopy(matrix))
                eigenvalues, eigenvectors = numpy.linalg.eig(new_matrix)

                big_vector = eigenvectors[:, 0]  # Grab e-vector.
                small_vector = [x for x in big_vector if x != 0]  # Remove 0s

                # Write to file.
                ranking = normalize_data(small_vector)
                for i in range(10):
                    print(ranking[i], groups[i])
                output_file.writerow([counter] + ranking)

    numpy.savetxt("tradeMatrix.csv", matrix, delimiter=",")

    new_matrix = normalize_columns(copy.deepcopy(matrix))
    graph_matrix = []
    group_names = [
        "Brown", "Light Blue", "Pink", "Orange", "Red", "Yellow", "Green",
        "Dark Blue", "Utility", "Railroad"
    ]

    graph_matrix.append([""] + group_names)

    for i in range(len(new_matrix)):
        row = [group_names[i]]
        for j in new_matrix[i]:
            row.append(float(j))
        graph_matrix.append(row)

    # Save matrix
    with open("adjTradeMatrix.csv", 'w', newline='') as csvfile:
        output_file = csv.writer(csvfile, quotechar=',')

        for row in graph_matrix:
            output_file.writerow(row)
Exemple #20
0
def main():
    game0 = monopoly.Game(cutoff=1000,
                          trading_enabled=False,
                          record_predicted_winners=True)

    base_games = 100
    counter = 0
    winners = [0, 0, 0]
    interval_size = 10
    matching_counter = 0
    monopolies_formed_counter = 0
    formation_times = []
    prediction = [0] * 100
    turn_prediction = [0] * 1000
    turn_counter_list = [0] * 1000

    while (counter < base_games) or interval_size > 0.01:
        counter += 1
        # Play game.
        player1 = monopoly.Player(1, buying_threshold=100)
        # group_ordering=random_ordering())
        player2 = monopoly.Player(2, buying_threshold=100)
        # group_ordering=random_ordering())

        game0.new_players([player1, player2])
        results = game0.play()

        winners[results['winner']] += 1
        p = winners[1] / counter
        interval_size = 1.960 * math.sqrt((p * (1 - p)) / counter)

        # It was not a tie.
        if results['winner'] != 0:

            for percent in range(1, 101):
                index = round((percent / 100) * results['length'])
                if game0.predicted_winners[index - 1] == results['winner']:
                    prediction[percent - 1] += 1

            for turn in range(results['length']):
                turn_counter_list[turn] += 1
                if game0.predicted_winners[turn] == results['winner']:
                    turn_prediction[turn] += 1

            # If monopolies formed see if the winner got the first one.
            if game0.first_monopoly:
                monopolies_formed_counter += 1
                if game0.first_monopoly == results['winner']:
                    matching_counter += 1

                    # if results['winning_player'].monopoly_tags:
                    # proportion = results['winning_player'].monopoly_tags[0] / results['length']
                    # formation_times.append(proportion)

    print("*" * 10)

    # finite_games = winners[1] + winners[2]
    # for element in prediction:
    # print(element / finite_games)

    print("*" * 10)

    for i in range(1000):
        if turn_counter_list[i] > 0:
            print(turn_prediction[i] / turn_counter_list[i])
        else:
            print(0)

    print("*" * 10)

    print("games played:", counter)
    print("win %s:", winners[0] / counter, winners[1] / counter,
          winners[2] / counter)
    print("winner had first monopoly:",
          matching_counter / monopolies_formed_counter, "of",
          monopolies_formed_counter, "games")
def main(games_in_a_set=100000):
    with open('pageRank_GroupGraph3.csv', 'w', newline='') as csvfile:
        output_file = csv.writer(csvfile, quotechar=',')
        matrix = numpy.zeros((10, 10))
        game_counter = 0
        game0 = monopoly.Game(cutoff=1000, trading_enabled=True)

        while game_counter < games_in_a_set:
            # Play game.
            player1 = monopoly.Player(1,
                                      buying_threshold=100,
                                      group_ordering=random_ordering())
            player2 = monopoly.Player(2,
                                      buying_threshold=100,
                                      group_ordering=random_ordering())

            game0.new_players([player1, player2])
            results = game0.play()

            if results['winner'] != 0:
                game_counter += 1
                winner = game0.active_players[0]
                loser = game0.inactive_players[0]

                winner.add_railroads_and_utilities()
                loser.add_railroads_and_utilities()

                #print(winner.monopolies, loser.monopolies)
                for winning_group in winner.monopolies:
                    for losing_group in loser.monopolies:
                        matrix[group_index(winning_group)][group_index(
                            losing_group)] += 1

            if game_counter % 100 == 0:
                print(game_counter)
                new_matrix = normalize_columns(copy.deepcopy(matrix))
                eigenvalues, eigenvectors = numpy.linalg.eig(new_matrix)

                big_vector = eigenvectors[:, 0]  # Grab e-vector.
                small_vector = [x for x in big_vector if x != 0]  # Remove 0s

                # Write to file.
                output_file.writerow([game_counter] +
                                     normalize_data(small_vector))

        new_matrix = normalize_columns(copy.deepcopy(matrix))
        graph_matrix = []
        group_names = [
            "Brown", "Light Blue", "Pink", "Orange", "Red", "Yellow", "Green",
            "Dark Blue", "Utility", "Railroad"
        ]

        graph_matrix.append([""] + group_names)

        for i in range(len(new_matrix)):
            row = [group_names[i]]
            for j in new_matrix[i]:
                row.append(float(j))
            graph_matrix.append(row)

        # Save matrix
        with open("PageRankEndGroupsMatrix.csv", 'w', newline='') as csvfile:
            output_file = csv.writer(csvfile, quotechar=',')

            for row in graph_matrix:
                output_file.writerow(row)
def main():
    game0 = monopoly.Game(cutoff=1000, trading_enabled=True, image_exporting=0)

    for thresh in [1]:  # range(150,1501,150):
        base_games = 1000
        counter = 0
        winners = [0, 0, 0]
        interval_size = 10

        while (counter < base_games) or interval_size > 0.01:
            counter += 1
            # Play game.
            player1 = monopoly.Player(
                1,  # Newbie
                buying_threshold=1500,
                group_ordering=[
                    "Dark Blue", "Green", "Yellow", "Red", "Orange",
                    "Railroad", "Utility", "Pink", "Light Blue", "Brown"
                ],
                step_threshold=True,
            )
            '''player1 = monopoly.Player(1,
                                      buying_threshold=thresh,
                                      group_ordering=random_ordering(),
                                      step_threshold=False,

            )'''
            '''player2 = monopoly.Player(2,
                                      buying_threshold=1500,
                                      group_ordering=random_ordering(),
                                      step_threshold=True,
            )'''

            player2 = monopoly.Player(
                2,
                buying_threshold=1500,
                group_ordering=best_ordering(),
                step_threshold=True,
            )
            '''player2 = monopoly.Player(2,
                                      buying_threshold=100,
                                      n=6,
                                      dynamic_ordering=True,
            )'''
            '''player2 = monopoly.Player(2,
                                      buying_threshold=1500,
                                      n=6,
                                      t=10,
                                      hybrid_trading=True,
                                      group_ordering=best_ordering(),
                                      step_threshold=True
            )'''

            game0.new_players([player1, player2])
            results = game0.play()

            # Store length.
            winners[results['winner']] += 1

            p = winners[1] / counter
            interval_size = 1.960 * math.sqrt((p * (1 - p)) / counter)

            # print(counter, p, interval_size)

        print(winners[0] / counter, winners[1] / counter, winners[2] / counter,
              counter, thresh)
Exemple #23
0
def main(games_in_a_set=100000):
    with open('pageRankEnd_Graph.csv', 'w', newline='') as csvfile:
        output_file = csv.writer(csvfile, quotechar=',')

        matrix = numpy.zeros((28, 28))
        game_counter = 0
        game0 = monopoly.Game(cutoff=1000, trading_enabled=True)

        keep_going = True
        while keep_going:
            # Play game.
            player1 = monopoly.Player(1,
                                      buying_threshold=1500,
                                      group_ordering=random_ordering(),
                                      step_threshold=True)
            player2 = monopoly.Player(2,
                                      buying_threshold=1500,
                                      group_ordering=random_ordering(),
                                      step_threshold=True)

            game0.new_players([player1, player2])
            results = game0.play()

            if results['winner'] != 0:
                game_counter += 1
                winner = game0.active_players[0]
                loser = game0.inactive_players[0]

                for winning_prop in winner.inventory:
                    for losing_prop in loser.inventory:
                        matrix[winning_prop.prop_id][losing_prop.prop_id] += 1

            if game_counter % 100 == 0:
                print(game_counter)
                new_matrix = normalize_columns(copy.deepcopy(matrix))
                eigenvalues, eigenvectors = numpy.linalg.eig(new_matrix)

                e_vector = eigenvectors[:, 0]  # Grab e-vector.

                # Write to file.
                output_file.writerow([game_counter] + normalize_data(e_vector))
                if game_counter == games_in_a_set:
                    for element in normalize_data(e_vector):
                        print(element)

                keep_going = False
                for i in range(28):
                    for j in range(28):
                        p = matrix[i][j] / game_counter
                        radius = 1.960 * math.sqrt(
                            (p * (1 - p)) / game_counter)
                        if radius > 0.01:
                            keep_going = True

        graph_matrix = []
        prop_names = []

        for prop in game0.board:
            if prop.is_property:
                prop_names.append(safe_name(prop.name))

        graph_matrix.append([""] + prop_names)

        for i in range(len(matrix)):
            row = [prop_names[i]]
            for j in matrix[i]:
                row.append(float(j))
            graph_matrix.append(row)

        # Save matrix
        with open("PageRankEnd_Matrix.csv", 'w', newline='') as csvfile:
            output_file = csv.writer(csvfile, quotechar=',')

            for row in graph_matrix:
                output_file.writerow(row)