def play(cfg: Config): pg.init() game = Game(**cfg.get_game_config()) controller = GameController(game) view = GameView(game, **cfg.get_view_config()) clock = pg.time.Clock() while game.is_running: clock.tick(cfg.fps) controller.handle_user_input() if not controller.pause and game.is_running: game.run() view.update() pg.quit()
class TestBaiDu(unittest.TestCase): URL = Config().get('URL') locator_kw = (By.ID, 'kw') locator_su = (By.ID, 'su') locator_result = (By.XPATH, '//div[contains(@class, "result")]/h3/a') def setUp(self): self.driver = webdriver.Chrome(executable_path=DRIVER_PATH + '\chromedriver.exe') self.driver.get(self.URL) def tearDown(self): self.driver.quit() def test_search_0(self): self.driver.find_element(*self.locator_kw).send_keys('selenium 灰蓝') self.driver.find_element(*self.locator_su).click() time.sleep(2) links = self.driver.find_elements(*self.locator_result) for link in links: logger.info(link.text) def test_search_1(self): self.driver.find_element(*self.locator_kw).send_keys('Python selenium') self.driver.find_element(*self.locator_su).click() time.sleep(2) links = self.driver.find_elements(*self.locator_result) for link in links: logger.info(link.text)
class TestBaiDu(unittest.TestCase): URL = Config().get('URL') excel=DATA_PATH+'/baidu.xlsx' locator_kw = (By.ID, 'kw') locator_su = (By.ID, 'su') locator_result = (By.XPATH, '//div[contains(@class, "result")]/h3/a') def setUp(self): self.driver = webdriver.Chrome(executable_path=DRIVER_PATH+'\chromedriver.exe') self.driver.get(self.URL) def tearDown(self): self.driver.quit() def test_search(self): datas=ExcelReader(self.excel).data for d in datas: with self.subTest(data=d): self.sub.setUp() self.driver.find_element(*self.locator_kw).send_keys(d['search']) self.driver.find_element(*self.locator_su).click() time.sleep(2) links=self.driver.find_element(*self.locator_result) for link in links: logger.info(link.text) self.sub_tearDown()
def create(self, level, levels: Config.Levels=Config.Levels()) -> Unit: stats_calculator = StatsCalculator(self._unit_traits) unit = Unit(self._unit_traits, levels) unit.level = level unit.max_hp = stats_calculator.hp(level) unit.hp = unit.max_hp unit.max_mp = stats_calculator.mp(level) unit.mp = unit.max_mp unit.attack = stats_calculator.attack(level) unit.defense = stats_calculator.defense(level) unit.luck = stats_calculator.luck(level) if self._spell_traits is not None: unit.set_spell(self, self._spell_traits, level) return unit
async def on_start(app): config = Config() client = AsyncIOMotorClient(config.mongodb_uri) app['db_client'] = client app['db'] = client.get_default_database() # defined in mongodb_uri app['config'] = config app['ping_task'] = asyncio.ensure_future(ping(app)) app['online'] = set() app['rooms'] = set() app['waiting'] = None # slot for waiting user await app['db'].users.create_index('name', unique=True)
def start(): SnakeGame.config = Config() SnakeGame.game_manager = GameManager() SnakeGame.game_manager.run()
def to_game_date(date): return Config.to_game_date(date)
def current_game_date(): return Config.current_game_date()
def run(cfg: Config): game = Game(**cfg.get_game_config()) game.run()
'--replay', action="store_true", help='Replay the last simulation without do any' ' calculations') parser.add_argument('-e', '--entropy', type=float, default=0.2, help='Set the entropy for the terrain generation') return parser.parse_args() if __name__ == '__main__': parameters = parser_arguments() if parameters.play: config = Config() config.update(**vars(parameters)) config.tile_size = 16 config.width = 100 config.height = 50 config.save() play(config) elif parameters.replay: pass else: config = Config() config.update(**vars(parameters)) config.save() if parameters.entropy: config.entropy = parameters.entropy run(config)
@author: XuGang """ from __future__ import print_function from __future__ import absolute_import import numpy as np from .rlutil import get_state, get_actions, combine from mcts.mcts import MCTS from mcts.tree_policies import UCB1 from mcts.default_policies import random_terminal_roll_out from mcts.backups import monte_carlo import copy import time from rl.init_model import model_init from game.config import Config RL_g = model_init(Config(), rl_model="prioritized_dqn", e_greedy=1, start_iter=5950000) #发牌 def game_init(players, playrecords, cards, train): if train: #洗牌 np.random.shuffle(cards.cards) #排序 p1_cards = cards.cards[:18] p1_cards.sort(key=lambda x: x.rank) p2_cards = cards.cards[18:36]