def test_parse_keyword_only_sentence(self): test_keyword_name = 'keyword1' test_re = 'test_re' engine = Engine('test_engine', {test_keyword_name: test_re}, {}, {}, [], {}) result = engine.parse(test_re, []) expected_list = [(test_keyword_name, test_re)] self.assertListEqual(expected_list, result.entities)
def test_parse_sentence_contain_keyword(self): test_keyword_name = 'keyword1' test_re = 'test_re' engine = Engine('test_engine', {test_keyword_name: test_re}, {}, {}, [], {}) test_query = 'test_prefix' + test_re + 'test_postfix' result = engine.parse(test_query, []) expected_list = [(test_keyword_name, test_re)] self.assertListEqual(expected_list, result.entities)
def test_parse_from_None_sate_to_None_state(self): state_id_list = [self.NONE_STATE_ID] test_intent_id = 1 test_re = 'test_re' engine = Engine('test_engine', {}, {}, [ ReIntentMapping(test_re, test_intent_id, self.NONE_STATE_ID, self.NONE_STATE_ID) ], [], {}) test_query = test_re result = engine.parse(test_query, state_id_list) self.assertEqual(test_intent_id, result.intent_id)
def test_parse_no_answer(self): state_id_list = [self.NONE_STATE_ID] test_intent_id = 1 no_answer_id = 0 test_re = 'test_re(test_para)' engine = Engine('test_engine', {}, {}, [ ReIntentMapping(test_re, test_intent_id, self.NONE_STATE_ID, self.NONE_STATE_ID) ], [], {}) test_query = '' result = engine.parse(test_query, state_id_list) self.assertEqual(no_answer_id, result.intent_id)
def test_parse_extract_group_name(self): test_intent_id = 1 test_re = 'testprefix(?P<test_group_name>test_para)testpostfix' engine = Engine('test_engine', {}, {}, [ ReIntentMapping(test_re, test_intent_id, self.NONE_STATE_ID, self.NONE_STATE_ID) ], [], {}) test_query = 'testprefixtest_paratestpostfix' state_id_list = [self.NONE_STATE_ID] result = engine.parse(test_query, state_id_list) self.assertEqual(1, len(result.intent_parameters)) self.assertEqual('test_para', result.intent_parameters['test_group_name'])
def get_mock_engine_list(): with patch.object(Engine, "__init__", lambda x: None): mock_engine = Engine() mock_engine.get_engine_name = lambda: self.TEST_DOMAIN_NAME mock_engine._preprocess = Mock(return_value=self.TEST_USER_INPUT) mock_engine._extract_entities = Mock(return_value=[]) mock_engine._map_utterance = Mock( return_value=(self.TEST_INTENT_ID, self.DETERMINISTIC_RESULT_PROB, self.TEST_TO_STATE_ID, None)) return [mock_engine]
if __name__ == '__main__': # Build blank board time.sleep(5) game_board = Board.Board() cwd = os.getcwd() parent = os.path.join(cwd, os.path.join(os.path.dirname(__file__))) player_color = sys.stdin.readline() # while player_color != 'w\n' or player_color != 'b\n': # player_color = sys.stdin.readline() sys.stderr.write(player_color) sys.stderr.flush() # print(Board.get_board_str(game_board)) if 'b' in player_color: opponent_color = 'w' engine = Engine(model_path=parent + '/Engine/nn_data/white/model.json', weights_path=parent + '/Engine/nn_data/white/model.h5') engine_move = engine.make_move() # find (row, col, row, col) coordinate of piece and target and print to stdout opponent_coord_move = ChessLogic.get_move_coordinates_from_algebraic_move(engine_move, opponent_color, game_board) game_board.read_and_update(engine_move) sys.stderr.write(opponent_coord_move) sys.stderr.flush() else: opponent_color = 'b' engine = Engine(model_path=parent + '/Engine/nn_data/black/model.json', weights_path=parent + '/Engine/nn_data/black/model.h5') # !! is a character meaning that a player has made a move, otherwise it is a query of possible moves for piece at # "row,col" player_move = '' while 'quit' not in player_move:
from Engine.Engine import Engine if __name__ == '__main__': myEngine = Engine()
from Engine.Engine import Engine from GameManager import GameManager if __name__ == "__main__": e = Engine(GameManager) e.game_loop()
self.jobs.append(new_job) job_cache.append((rx, ry)) def update(self, dt): self.sidebar.update(dt) for ant in self.ants: ant.update(dt) def draw(self, canvas): self.sidebar.draw(canvas) pygame.draw.rect(canvas, (40, 0, 0), self.game_area) for ant in self.ants: ant.draw(canvas) for job in self.jobs: job.draw(canvas) for job in self.working_jobs: job.draw(canvas) pygame.draw.rect(canvas, (255, 255, 255), self.drop_off) def handle_event(self, event): pass if __name__ == "__main__": set_screensize(1280, 720) e = Engine(Game) e.game_loop()
dx = target.x - origin.x dy = target.y - origin.y rads = math.atan2(-dy, dx) rads %= 2 * math.pi degs = math.degrees(rads) return int(degs) def rot_center(self, image, angle): """rotate an image while keeping its center and size""" orig_rect = image.get_rect() rot_image = pygame.transform.rotate(image, angle) rot_rect = orig_rect.copy() rot_rect.center = rot_image.get_rect().center rot_image = rot_image.subsurface(rot_rect).copy() return rot_image def update(self, dt): self.last_move += dt if self.last_move > 100: self.degrees += 1 if self.degrees > 359: self.degrees = 0 self.last_move = 0 def handle_event(self, event): pass if __name__ == '__main__': e = Engine(GameObject) e.game_loop()
import pygame from Engine.Engine import Engine class ExampleGame(object): def __init__(self): self.box = [32, 32] self.move_step = 8 def draw(self, canvas): pygame.draw.rect(canvas, (100, 0, 100), (self.box[0], self.box[1], 25, 25)) def update(self, dt): pass def handle_event(self, event): if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: self.box[1] -= self.move_step elif event.key == pygame.K_DOWN: self.box[1] += self.move_step elif event.key == pygame.K_LEFT: self.box[0] -= self.move_step elif event.key == pygame.K_RIGHT: self.box[0] += self.move_step if __name__ == "__main__": e = Engine(ExampleGame) e.game_loop()
import sys from Engine.Engine import Engine import Utils.DateConverter as dateConv file_name = sys.argv[1] start_date = sys.argv[2] end_date = sys.argv[3] if not dateConv.is_date_str_valid_format(start_date): raise ValueError( 'Date format for start date is not acceptable Sir. It should be yyyy.MM.dd' ) if not dateConv.is_date_str_valid_format(end_date): raise ValueError( 'Date format for end date is not acceptable Sir. It should be yyyy.MM.dd' ) if not dateConv.after(start_date, end_date): raise ValueError( 'Date of simulation start should be before date of simulation end, Sir' ) parsed_file = open(file_name) engine = Engine(start_date, end_date, parsed_file) engine.invest()
def main(): set_base_folder("assets/images/") e = Engine(Game) e.game_loop()
from Engine.Engine import Engine parsed_file = open('program.txt') engine = Engine('2016.05.11', '2016.05.15', parsed_file) engine.invest()