Ejemplo n.º 1
0
def main():
    import config_helpers
    config_helpers.initialize_game_environment(sys.argv[1])
    from main import Main
    from development_tools.frame_visualizer import FrameVisualizer

    file = open(sys.argv[2], mode='rb')
    test_game_controller = pickle.load(file)
    file.close()
    FrameVisualizer(test_game_controller).mainloop()
Ejemplo n.º 2
0
def main():
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument(
        '-c', '--bot-commands-file', required=True,
        help='file where each line represents command to launch bot'
    )

    arg_parser.add_argument(
        '-d', '--directory', required=True,
        help='directory with game'
    )

    arg_parser.add_argument(
        '-v', '--visualize', action='store_true',
        help='visualize game after run'
    )

    arg_parser.add_argument(
        '-s', '--save-to',
        help='save game log to specified file'
    )

    arg_parser.add_argument(
        '-f', '--from-file',
        help='visualize game log from specified file'
    )

    arg_parser.add_argument(
        '-r', '--only-run', action='store_true',
        help='don\'t visualize and save logs, only run game'
    )

    args = arg_parser.parse_args()

    config_helpers.initialize_game_environment(args.directory)

    if args.from_file:
        game_controller = load_game_controller(args.from_file)
        visualize(game_controller)
    else:
        new_game(args)
Ejemplo n.º 3
0
    arg_parser.add_argument(
        'game_path',
        help='Directory containing game'
    )
    arg_parser.add_argument(
        '-tid', '--tournament-id', type=int,
        help='''
Tournament id which is used for saving logs,
if you don't set tournament id it will be least non-used one'''
    )
    args = arg_parser.parse_args()
    '''
    If tournament id isn't setted it will be least non-used one
    '''

    config_helpers.initialize_game_environment(args.game_path)
import config

from tournament_stages.tournament import Tournament
from utils import print_tournament_system_results
import bot


class Main:
    def __init__(self, game_path, tournament_id):
        self._game_path = game_path
        self._players_list = None
        self._tournament_id = tournament_id
        self.tournament = None

    def _load_players(self):
Ejemplo n.º 4
0
from config_helpers import initialize_game_environment, players_parse
from visualizer import VideoVisualizer
import sys
from time import clock
import os

if len(sys.argv) < 5:
    print('Usage: create_video.py <path to game env> <folder with game logs> '
          '<filemask of logs> <resw_name> [-f <framerate>] [--silent]')
    exit()

if __name__ == '__main__':
    game_path, log_path, log_mask, res_name = sys.argv[1:5]
    framerate = 24 if '-f' not in sys.argv\
                  else int(sys.argv[sys.argv.index('-f') + 1])
    silent = '--silent' in sys.argv
    initialize_game_environment(game_path)
    import config
    from tournament_systems.tournament_system_factory import create
    beg = clock()
    ts = create()(players_parse(os.path.join(game_path,
                                             config.players_config)))
    visualizer = VideoVisualizer(framerate, config.Painter, log_mask,
                                 log_path, silent, ts.draw_table\
                                 if hasattr(ts, 'draw_table') else None)
    visualizer.compile(res_name)
    if not silent:
        print('Compiled in', clock() - beg, 'sec.')
GAME_PATH = 'games/nim'
BOTS = ['python3 games/nim/bots/random_bot.py',
        'python3 games/nim/bots/wrong_bot.py']

import config_helpers
config_helpers.initialize_game_environment(GAME_PATH)
import config

import unittest
import random
from tournament_stages.game_signature import GameSignature
from player import Player
from game_simulator import GameSimulator


class GameModulesIntegrationTests(unittest.TestCase):
    def setUp(self):
        signature = GameSignature()
        players = [Player(command_line) for command_line in BOTS]
        generator = config.Generator()
        start_states = list(generator.generate_start_positions(signature,
                                                               players))
        start_state = random.choice(start_states)
        self._simulator = GameSimulator(players, start_state, signature)

    def test_that_game_is_finished(self):
        controller = self._simulator.play()
        self.assertTrue(controller.is_finished)

    def test_that_scores_exists_for_each_player(self):
        controller = self._simulator.play()
Ejemplo n.º 6
0
 def test_initialize_game_environment(self):
     config_helpers.initialize_game_environment('.')
     import config_testing
     self.assertEqual(config_testing.some_value, 0)