示例#1
0
	def test_lazy_term(self):
		cond = lambda: True
		true_clause = lambda: 3
		else_clause = lambda: 3 / 0

		ai = AI.AI([[ifTerm, cond, true_clause, else_clause]])
		result = ai.run()
		self.assertEqual(result, 3)
示例#2
0
	def test_nested_terms(self):
		cond = lambda: True
		ifTrue = lambda: 3
		ifFalse = lambda: 4
		bad_operand =  lambda: 3/0

		nested_if = [ifTerm, lambda: False, ifTrue, ifFalse]
		terminals = [[ifTerm, cond, nested_if, bad_operand]]
		ai = AI.AI(terminals)
		result = ai.run()
		self.assertEqual(result, 4)
示例#3
0
 def check_input(self):
     self.move_cursor()
     if self.game.BACK_KEY:
         self.game.curr_menu = self.game.main_menu
         self.run_display = False
     if self.game.START_KEY:
         if self.state == 'Start':
             self.game.playing = True
             player_loop()
             if self.game.BACK_KEY:
                 os.system("main_screen.py")
             if self.game.ESCAPE_KEY:
                 self.game.curr_menu = self.game.main_menu
                 self.run_display = False
         elif self.state == 'BOT Game':
             if self.run_display:
                 local_dir = os.path.dirname(__file__)
                 config_path = os.path.join(local_dir,
                                            'config-feedforward.txt')
                 run(config_path)
                 # to close the game and return to the menu
                 if self.game.BACK_KEY:
                     self.game.curr_menu = self.game.main_menu
                     self.run_display = False
                     pygame.quit()
                     quit()
                     sys.exit()
                 # to finish the game
                 if self.game.ESCAPE_KEY:
                     self.game.curr_menu = self.game.main_menu
                     self.run_display = False
                     pygame.quit()
                     quit()
                     sys.exit()
         elif self.state == 'Options':
             self.game.curr_menu = self.game.options
         elif self.state == 'Credits':
             self.game.curr_menu = self.game.credits
         elif self.state == 'Quit':
             sys.exit()
         self.run_display = False
示例#4
0
	def test_evaluate(self):
		ai = AI.AI(self._terminals)
		result = ai.run()
		self.assertEqual(result, 7)