Beispiel #1
0
def run(sample_number, resolution):
    global engine, screen
    print("hi")
    screen = pygame.display.set_mode(resolution if resolution else (600, 600))
    engine = Engine(screen)
    globals()[f"sample_{sample_number}"]()
    engine.start()
Beispiel #2
0
    def __init__(self, datafile, db, log):
        with open(datafile, 'rb') as src:
            self.data = Data(src)

        self.engine = Engine(self.data, log=log)
        self.db = db
        self.log = log
    def test_should_set_home_when_engine_init(self):
        home_position = (1, 1)
        self.cleaner.position = MagicMock(return_value=home_position)
        environment = Mock()

        Engine(
            self.cleaner, environment, self.touch_sensor, self.photo_sensor, self.infrared_sensor,
        )

        environment.set_home.assert_called_once_with(home_position)
Beispiel #4
0
 def __init__(self,max_moves,ai_config,opponent_config,param_ranges,n_iter,n_games,init_params,n_batches = 1):
     self.ai_config = ai_config
     self.opponent_config = opponent_config
     self.param_ranges = param_ranges
     self.n_iter = n_iter
     self.n_games = n_games
     self.max_moves = max_moves
     self.engine = Engine(self.max_moves,self.ai_config, self.opponent_config)
     self.params = init_params
     self.n_batches = n_batches
     self.score_history = []
     self.the_good_ones = []
Beispiel #5
0
def lint_and_run_game(pylint_args, fullscreen, resolution):
    """Run pylint, get the output, parse it, initialize the game and run it."""
    animal_groups = create_animals(parse(lint(pylint_args)))
    flags = pygame.FULLSCREEN if fullscreen else 0
    if not resolution and not fullscreen:
        resolution = (600, 600)
    screen = pygame.display.set_mode((0, 0) if fullscreen else resolution,
                                     flags)
    organize_groups(screen, animal_groups)
    engine = Engine(screen)
    for animal_group in animal_groups:
        engine.add_animals(*animal_group)
    engine.start()
    def setUp(self):
        self.cleaner = Mock()
        self.cleaner.position = MagicMock(return_value=(1, 1))

        self.environment = Mock()

        self.touch_sensor = Mock()
        self.photo_sensor = Mock()
        self.infrared_sensor = Mock()

        self.engine = Engine(
            self.cleaner, self.environment, self.touch_sensor, self.photo_sensor, self.infrared_sensor,
        )
Beispiel #7
0
def main(datafile):
    ''' Text Adventure CLI

        DATAFILE - Path to ScottFree data file
    '''
    data = Data(datafile)
    state = StateFromGameData(data)
    engine = Engine(data)

    state = engine.start_game(state)
    click.echo(state.last_message)

    repl = REPL(engine, state)
    repl.cmdloop()
Beispiel #8
0
def test_game():
    animal1 = Animal(shape="Y", max_health=2, size=40)
    animal2 = Animal(shape="X", max_health=2, size=40)

    animal1.also_likes_to_eat(animal2)
    animal2.also_likes_to_eat(animal1)

    screen = pygame.display.set_mode((600, 600))

    animal1.put_relative(30, 30, screen)
    animal2.put_relative(60, 60, screen)

    engine = Engine(screen)
    engine.add_animals(animal1, animal2)
    engine.start()
    def __init__(self, start=None, n_games=10, start_temp=1024, factor=2):
        self.start = start
        if start == None:
            self.start = get_random_start()

        self.delta = 0.00001
        self.n_games = n_games
        #make both of them random, but the simpel start state
        self.player_config = {
            Settings.AI.value: True,  #should this be Ai or person
            Settings.START_TYPE.value:
            StartType.SIMPLE.value,  #what kind of start state
            Settings.START_PARAMS.value: [],  #any parameters for the stater
            Settings.SEARCH_TYPE.value:
            SearchType.RANDOM.value,  #what kind of search is happening
            Settings.SEARCH_PARAMS.value: [],  #any parameters for the search
            Settings.AI_TYPE.value: AIType.NONE.value,  # what is the AI
            Settings.AI_PARAMS.value: []  #any params for the ai
        }
        self.opponent_config = {
            Settings.AI.value: True,  #should this be Ai or person
            Settings.START_TYPE.value:
            StartType.CHAMPION.value,  #what kind of start state
            Settings.START_PARAMS.value: [],  #any parameters for the stater
            Settings.SEARCH_TYPE.value:
            SearchType.RANDOM.value,  #what kind of search is happening
            Settings.SEARCH_PARAMS.value: [],  #any parameters for the search
            Settings.AI_TYPE.value: AIType.NONE.value,  # what is the AI
            Settings.AI_PARAMS.value: []  #any params for the ai
        }

        self.engine = Engine(1000)
        self.best, stats = self.simulated_annealing(start_temp, factor)
        print(self.best)
        f = open("train/simulated_annealing_results.txt", "a")
        t = open("train/simulated_annealing_factors.txt", "a")
        s = open("train/simuated_annealing_start_state.txt", "a")
        g = open("train/simulated_annealing_stats.txt", "a")
        f.write("{}\n".format(self.best))
        t.write("{}\n".format([start_temp, factor]))
        s.write("{}\n".format(self.start))
        g.write("{}\n".format(stats))
        g.close()
        s.close()
        t.close()
        f.close()
Beispiel #10
0
    def __init__(self, menu, players):
        super().__init__()

        self.menu = menu

        self.setWindowTitle('Code with Fire')
        self.setGeometry(200, 50, 800, 650)

        self.player_names = players
        self.alive_players = len(players)

        self.game_engine = Engine()
        self.game_screen = Screen(self.game_engine)
        self.score_manager = ScoreManager(self.game_screen)

        self.setCentralWidget(self.game_screen)
        self.create_menu_bar()

        self.start_game(players)
Beispiel #11
0
    def __init__(self, config, max_moves):
        self.ai_configs = []
        for filename in config[AI_FIELD][AIType.REACHABLE.value]:
            self.ai_configs += read_file_into_configs(filename,
                                                      reachable_config)
        for filename in config[AI_FIELD][AIType.MODIFIED_REACHABLE.value]:
            self.ai_configs += read_file_into_configs(filename,
                                                      mod_reachable_config)
        for filename in config[AI_FIELD][AIType.PIECE_BASED_ADD.value]:
            self.ai_configs += read_file_into_configs(filename,
                                                      piecebased_config_add)
        for filename in config[AI_FIELD][AIType.PIECE_BASED_MUL.value]:
            self.ai_configs += read_file_into_configs(filename,
                                                      piecebased_config_mul)

        self.start_configs = []

        for filename in config[START_FIELD]:
            self.start_configs += read_file_into_configs(
                filename, flexible_start_config)

        self.engine = Engine(max_moves, None, None)

        self.max_moves = max_moves
Beispiel #12
0
import game.chapter_one.main
import game.chapter_two.main
from game.engine import Engine, SceneMap

print("Starting the engine...")
a_map = SceneMap()
a_game = Engine(a_map)
a_game.play()
Beispiel #13
0
def test_is_human():
    engine = Engine()
    player = Player(True, engine)
    assert player.is_human()
Beispiel #14
0
def test_contructor():
    #simple test to make sure that the constructor runs
    engine = Engine()
    player = Player(True, engine)
Beispiel #15
0
def test_constructor():
    #simple test to make sure that the constructor runs
    my_engine = Engine()
Beispiel #16
0
 def main(self):
     Engine(no_player=self.params.no_player).play()
Beispiel #17
0
"""
// Filename : Instances
// Created by: @ngeorgj

This file holds the base instances for the game, don't change anything!
"""

from game.engine import Engine
from game.cgame import Game

game_engine = Engine()

rpg = Game()
rpg.engine = game_engine
Beispiel #18
0
    # Run game options
    elif action in ['run', 'r']:
        # Additional args
        quiet = False

        if par_args.debug is not None:
            if par_args.debug >= 0:
                game.config.Debug.level = par_args.debug
            else:
                print('Valid debug input not found, using default value')

        if par_args.q_bool:
            quiet = True

        engine = Engine(quiet)
        engine.loop()

    # Boot up the scrimmage server client
    elif action in ['scrimmage', 's']:
        cl = Client()

    elif action in ['visualizer', 'v']:
        # Check operating system and run corresponding visualizer
        if plat == "win32":
            print("You're running Windows")
            subprocess.call(["./visualizer.exe"])
        elif plat == "linux":
            print("You're a linux man I see.")
            subprocess.call(["./visualizer.x86_64"])
        elif plat == "darwin":
Beispiel #19
0
def test_get_start_state_doesnt_fail():
    #simple test to make sure that the get_start_state runs
    engine = Engine()
    player = Player(True, engine)
    player.get_starting_state()
Beispiel #20
0
#!/usr/bin/env python2

# from network import Channel
# import socket
# import time
# from ctypes import cdll
import platform
# import sys
# import os

# sys.path.append(os.path.abspath())

from game.engine import Engine
engine = Engine()
engine.start()


def init_steam():
    #     arch, _ = platform.architecture()
    #     if arch == '64bit':
    #         i9c = cdll.LoadLibrary('./i9c_64.so')
    #     else:
    #         i9c = cdll.LoadLibrary('./i9c_32.so')
    #
    #     i9c.api_init()
    #     i9c.api_request_ticket()
    #     #time.sleep(3)
    #     #i9c.api_get_ticket()
    libsteam_api = cdll.LoadLibrary('old/libsteam_api.so')
    libsteam_api.SteamAPI_Init()
Beispiel #21
0
    #        get_image_data())
    #game_window.set_icon(icon)


    class Score:
        def __init__(self):
            self.meters = 0
            self.top = 0

        def __iadd__(self, value):
            self.meters += value
            if self.meters > self.top:
                self.top = self.meters
            return self

    score = Score()

    title = Title(assets, score)
    engine = Engine(assets, score)
    director = Director(constants.VWIDTH * 2,
                        constants.VHEIGHT * 2,
                        caption="Fuel4TheLight",
                        vwidth=constants.VWIDTH,
                        vheight=constants.VHEIGHT)
    director.set_background_color(0., 0., 0.)
    Director.add_scene("title", title)
    Director.add_scene("engine", engine)
    Director.set_scene("title")

    pyglet.app.run()
Beispiel #22
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.engine = Engine(consumer=self)
 def main(self):
     Engine(filename=self.params.file).play()
Beispiel #24
0
    def __init__(self, master):
        self.tiles = []
        self.textids = []
        self.master = master
        self.frame = Frame(master)
        self.canvas = Canvas(self.frame, width=510, height=510)

        Grid.rowconfigure(master, 0, weight=1)
        Grid.columnconfigure(master, 0, weight=1)
        self.frame.grid(row=0, column=0)

        # self.player1_config = {
        #         Settings.AI.value : True, #should this be Ai or person
        #         Settings.START_TYPE.value : StartType.RANDOM.value, #what kind of start state
        #         Settings.START_PARAMS.value : [], #any parameters for the stater
        #         Settings.SEARCH_TYPE.value : SearchType.RANDOM.value, #what kind of search is happening
        #         Settings.SEARCH_PARAMS.value : [], #any parameters for the search
        #         Settings.AI_TYPE.value : AIType.NONE.value, # what is the AI
        #         Settings.AI_PARAMS.value : [] #any params for the ai
        #     }
        self.player1_config = {
            'ai parameters': [
                -1, 1, 0, 0, 0, 0, -1, 1, -1, 0, 1, -1, -1, 1, 0, -1, 0, 0, 1,
                1, 0
            ],
            'eval_type':
            'modified_reachable',
            'search_parmeters': [],
            'FILENAME':
            'train/good_modified_reachable.txt',
            'params_for_start_state': [],
            'type_of_start_state':
            'champion',
            'is an ai':
            True,
            'type_of_search':
            'no searcher'
        }

        self.player2_config = {
            Settings.AI.value: True,  #should this be Ai or person
            Settings.START_TYPE.value:
            StartType.RANDOM.value,  #what kind of start state
            Settings.START_PARAMS.value: [],  #any parameters for the stater
            Settings.SEARCH_TYPE.value:
            SearchType.RANDOM.value,  #what kind of search is happening
            Settings.SEARCH_PARAMS.value: [],  #any parameters for the search
            Settings.AI_TYPE.value: AIType.NONE.value,  # what is the AI
            Settings.AI_PARAMS.value: []  #any params for the ai
        }

        self.tile_colors = [[
            "#DBE0FF", "#C7CCF7", "#B3B9EF", "#9FA6E8", "#8C92E0", "#787FD9",
            "#646CD1", "#5059CA", "#3D45C2", "#2932BB", "#151FB3", "#020CAC"
        ],
                            [
                                "#FFDBE0", "#F7C7CD", "#EFB3BB", "#E89FA8",
                                "#E08C96", "#D97884", "#D16471", "#CA505F",
                                "#C23D4D", "#BB293A", "#B31528", "#AC0216"
                            ]]

        self.hidden_color = ["#787FD9", "#D97884"]

        self.e = Engine(1000, self.player1_config, self.player2_config, False)
        self.e.setup_board()
        if not self.player1_config[Settings.AI.value]:
            board = self.e.get_board(1, True)
        else:
            board = self.e.get_board(None, True)
        self.win = False  #winner trigger
        self.player1_turn = True  #player 1 turn trigger
        self.winning_player = 0
        self.button_counter = 0
        self.clicked_buttons = []
        # board setup
        #print(board)
        for i in range(10):
            for j in range(10):
                tag = i * 10 + j
                if board[i][j] == 111:
                    text_item = ""
                    tile_color = "white"
                    tile_outline = "white"
                elif board[i][j] == 0:
                    text_item = ""
                    tile_outline = "black"
                    tile_color = "grey"
                elif board[i][j] % 1000 == piece_diplay_map[
                        pieces.HIDDEN.value]:
                    text_item = ""
                    tile_outline = "black"
                    tile_color = self.hidden_color[board[i][j] / 1000 - 2]
                else:
                    text_item = str(board[i][j] % 100)
                    tile_outline = "black"
                    #print(board[i][j])
                    #print(board[i][j]/100 - 2)
                    #print(board[i][j]%100 - 1)
                    tile_color = self.tile_colors[board[i][j] / 100 -
                                                  2][board[i][j] % 100 - 1]
                tile = self.canvas.create_rectangle(j * 50 + 10,
                                                    i * 50 + 10,
                                                    j * 50 + 50,
                                                    i * 50 + 50,
                                                    outline=tile_outline,
                                                    fill=tile_color,
                                                    activefill="cyan",
                                                    tags=tag)
                textid = self.canvas.create_text(j * 50 + 30,
                                                 i * 50 + 30,
                                                 text=text_item,
                                                 tags=str(tag) + "text")

                rect_handler = self.ind_map_click(9 - i, j)

                self.tiles.append(tile)
                self.textids.append(textid)
                self.canvas.tag_bind(tile, "<Button-1>", rect_handler)
        self.canvas.grid(row=0, column=0)