Beispiel #1
0
# then displays their scores.
#
# For running this script, you need to put the 'game.py'
# as well as your 'player.py' to the python path, e.g.
# to the the working directory.
import stahnuto
import player
import randomplayer
from game import Game

# define the payoff matrix; see game.py for detailed explanation of this matrix
payoff_matrix = [[(4, 4), (1, 6)], [(6, 1), (2, 2)]]

# define the number of iterations
number_of_iterations = 110

# create the players
playerA = player.MyPlayer(payoff_matrix, number_of_iterations)
playerB = randomplayer.MyPlayer(payoff_matrix, number_of_iterations)

# create the game instance
my_game = Game(playerA, playerB, payoff_matrix, number_of_iterations)
# run game
my_game.run()

# get scores
scores = my_game.get_players_payoffs()

# display scores
print('playerA got:', scores[0], '\nplayerB got:', scores[1])
Beispiel #2
0
# lets them play for some number of iterations and
# then displays their scores.
#
# For running this script, you need to put the 'game.py'
# as well as your 'player.py' to the python path, e.g.
# to the the working directory.

import player
from game import Game

# define the payoff matrix; see game.py for detailed explanation of this matrix
payoff_matrix = [[(4, 4), (1, 6)], [(6, 1), (2, 2)]]

# define the number of iterations
number_of_iterations = 20

# create the players
playerA = player.MyPlayer(payoff_matrix)
playerB = player.MyPlayer(payoff_matrix)

# create the game instance
my_game = Game(playerA, playerB, payoff_matrix, number_of_iterations)
# run game
my_game.run()

# get scores
scores = my_game.get_players_payoffs()

# display scores
print('playerA got:', scores[0], '\nplayerB got:', scores[1])
        else:
            print('Draw')
        print('\n-----------------------------\n\n')


if __name__ == "__main__":
    (choices, args) = getopt.getopt(sys.argv[1:], "")
    p0_color = 0
    p1_color = 1

    if len(args) == 0:
        print(
            'No arguments given.\nRunning game with my player against a random player.'
        )
        p0 = random_player.MyPlayer(p0_color, p1_color)
        p1 = player.MyPlayer(p1_color, p0_color)
        game = HeadlessReversiCreator(p0, p0_color, p1, p1_color, 8)
        game.play_game()

    elif len(args) == 1:
        print(
            'One player given in argument.\nRunning game with given player against the random player.'
        )
        p0 = random_player.MyPlayer(p0_color, p1_color)
        try:
            player_module = __import__(args[0])
            p1 = player_module.MyPlayer(p1_color, p0_color)

            game = HeadlessReversiCreator(p0, p0_color, p1, p1_color, 8)
            game.play_game()
Beispiel #4
0
            print('Draw')
        print('\n-----------------------------\n\n')


if __name__ == "__main__":
    (choices, args) = getopt.getopt(sys.argv[1:], "")
    p1_color = 0
    p2_color = 1

    if len(args) == 0:
        print('No arguments given.\nRunning game with two random players.')
        # TODO Change players
        #p1 = greedy.MyPlayer(p1_color, p2_color)
        #p1 = random_player.MyPlayer(p1_color, p2_color)
        p1 = dummier.MyPlayer(p1_color, p2_color)
        p2 = player.MyPlayer(p2_color, p1_color)
        game = HeadlessReversiCreator(p1, p1_color, p2, p2_color, 8)
        game.play_game()

    elif len(args) == 1:
        print('One player given in argument.\nRunning game with given player aginst the random player.')
        p1 = random_player.MyPlayer(p1_color, p2_color)
        try:
            player_module = __import__(args[0])
            p2 = player_module.MyPlayer(p2_color, p1_color)

            game = HeadlessReversiCreator(p1, p1_color, p2, p2_color, 8)
            game.play_game()

        except ImportError:
            print('Error: Cannot import given player: %s.' % (args[0]))
Beispiel #5
0
def play(payoff_matrix):
    p1 = prisoner1.MyPlayer(payoff_matrix, number_of_iterations)
    p2 = prisoner2.MyPlayer(payoff_matrix, number_of_iterations)
    p3 = prisoner3.MyPlayer(payoff_matrix, number_of_iterations)
    p4 = prisoner4.MyPlayer(payoff_matrix, number_of_iterations)
    p5 = prisoner5.MyPlayer(payoff_matrix, number_of_iterations)
    p6 = prisoner6.MyPlayer(payoff_matrix, number_of_iterations)
    p7 = prisoner7.MyPlayer(payoff_matrix, number_of_iterations)
    p8 = prisoner8.MyPlayer(payoff_matrix, number_of_iterations)
    p9 = prisoner9.MyPlayer(payoff_matrix, number_of_iterations)
    p10 = prisoner10.MyPlayer(payoff_matrix, number_of_iterations)
    p11 = prisoner11.MyPlayer(payoff_matrix, number_of_iterations)
    p12 = prisoner12.MyPlayer(payoff_matrix, number_of_iterations)
    p13 = prisoner13.MyPlayer(payoff_matrix, number_of_iterations)
    p14 = prisoner14.MyPlayer(payoff_matrix, number_of_iterations)
    p15 = prisoner15.MyPlayer(payoff_matrix, number_of_iterations)
    p16 = prisoner16.MyPlayer(payoff_matrix, number_of_iterations)
    p17 = prisoner17.MyPlayer(payoff_matrix, number_of_iterations)
    p0 = prisoner0.MyPlayer(payoff_matrix, number_of_iterations)
    pl = player.MyPlayer(payoff_matrix, number_of_iterations)

    list_of_players = [
        pl, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15,
        p16, p17
    ]

    for i in range(50):
        list_of_players.append(
            prisoner1.MyPlayer(payoff_matrix, number_of_iterations))

    for i in range(102):
        list_of_players.append(
            prisoner3.MyPlayer(payoff_matrix, number_of_iterations))

    for i in range(30):
        list_of_players.append(
            prisoner12.MyPlayer(payoff_matrix, number_of_iterations))

    results = [0 for x in list_of_players]

    for x in list_of_players:
        indexX = list_of_players.index(x)

        for y in list_of_players:
            indexY = list_of_players.index(y)

            x.__init__(payoff_matrix, number_of_iterations)
            y.__init__(payoff_matrix, number_of_iterations)

            game = Game(x, y, payoff_matrix, number_of_iterations)
            game.run()

            result_A, result_B = game.get_players_payoffs()
            results[indexX] += result_A
            results[indexY] += result_B

    ret = 1
    for i in range(18):
        if results[i] > results[0]:
            ret += 1

    #print(results)
    print(results.index(max(results)) + 1)
    return ret