当前位置: 首页>>代码示例>>Python>>正文


Python game.Game类代码示例

本文整理汇总了Python中term2048.game.Game的典型用法代码示例。如果您正苦于以下问题:Python Game类的具体用法?Python Game怎么用?Python Game使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Game类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_show_cursor_windows

 def test_show_cursor_windows(self):
     g = Game(scores_file=None, store_file=None, clear_screen=True)
     self.setWindows(g)
     g.hideCursor()
     g.showCursor()
     # these don't do anything for now
     self.assertEqual(sys.stdout.read(), '')
开发者ID:Anykey228,项目名称:term2048_ai,代码行数:7,代码来源:test_game.py

示例2: test_store_non_empty_file

 def test_store_non_empty_file(self):
     store = NamedTemporaryFile(delete=False)
     store.close()
     g = Game(scores_file=None, store_file=store.name)
     self.assertTrue(g.store())
     self.assertFileIsNotEmpty(store.name)
     remove(store.name)
开发者ID:Anykey228,项目名称:term2048_ai,代码行数:7,代码来源:test_game.py

示例3: test_save_best_score_with_file

 def test_save_best_score_with_file(self):
     scores_file = NamedTemporaryFile(delete=True)
     g = Game(scores_file=scores_file.name)
     g.best_score = 0
     g.score = 1000
     g.saveBestScore()
     self.assertEqual(g.best_score, 1000)
开发者ID:techgaun,项目名称:term2048,代码行数:7,代码来源:test_game.py

示例4: test_simple_win_loop

 def test_simple_win_loop(self):
     kp._setNextKey(kp.UP)
     g = Game(goal=4, size=2, clear_screen=False)
     g.board.cells = [
         [2, 0],
         [2, 0]
     ]
     g.loop()
开发者ID:Primer42,项目名称:term2048-AI,代码行数:8,代码来源:test_game.py

示例5: test_store_fail_return_false

 def test_store_fail_return_false(self):
     store = NamedTemporaryFile(delete=False)
     store.close()
     os.chmod(store.name, 0)  # no rights at all
     g = Game(scores_file=None, store_file=store.name)
     self.assertFalse(g.store())
     os.chmod(store.name, 0o200)  # give me writing rights back
     remove(store.name)
开发者ID:Anykey228,项目名称:term2048_ai,代码行数:8,代码来源:test_game.py

示例6: test_start_game_no_resume

    def test_start_game_no_resume(self):
        g1 = Game(scores_file=None)
        g1.board.setCell(0, 0, 16)
        self.assertTrue(g1.store())

        sys.argv = ['term2048']
        g2 = ui.start_game(debug=True)
        self.assertIn(g2.board.getCell(0, 0), [0, 2, 4])
开发者ID:jasonkliu,项目名称:term2048,代码行数:8,代码来源:test_ui.py

示例7: test_loop_pause

 def test_loop_pause(self):
     store = NamedTemporaryFile(delete=False)
     store.close()
     kp._setNextKey(kp.SPACE)
     g = Game(scores_file=None, store_file=store.name)
     self.assertEqual(g.loop(), 0)
     self.assertFileIsNotEmpty(store.name)
     remove(store.name)
开发者ID:Anykey228,项目名称:term2048_ai,代码行数:8,代码来源:test_game.py

示例8: test_loop_pause_error

 def test_loop_pause_error(self):
     store = NamedTemporaryFile(delete=False)
     store.close()
     os.chmod(store.name, 0)  # no rights at all
     kp._setNextKey(kp.SPACE)
     g = Game(scores_file=None, store_file=store.name)
     self.assertIs(None, g.loop())
     os.chmod(store.name, 0o200)  # give me writing rights back
     remove(store.name)
开发者ID:Anykey228,项目名称:term2048_ai,代码行数:9,代码来源:test_game.py

示例9: test_store_restore_empty_game

 def test_store_restore_empty_game(self):
     store = NamedTemporaryFile(delete=False)
     store.close()
     g1 = Game(scores_file=None, store_file=store.name)
     self.assertTrue(g1.store())
     g2 = Game(scores_file=None, store_file=store.name)
     g2.board.setCell(0, 0, 16)
     self.assertTrue(g2.restore())
     self.assertIn(g2.board.getCell(0, 0), [0, 2, 4])
     remove(store.name)
开发者ID:Anykey228,项目名称:term2048_ai,代码行数:10,代码来源:test_game.py

示例10: test_start_game_resume

    def test_start_game_resume(self):
        cellvalue = 2
        g1 = Game(scores_file=None)
        g1.board.setCell(0, 0, cellvalue)
        g1.score = 42
        self.assertTrue(g1.store())

        sys.argv = ['term2048', '--resume']
        g2 = ui.start_game(debug=True)
        self.assertEqual(cellvalue, g2.board.getCell(0, 0))
        self.assertEqual(g1.score, g2.score)
开发者ID:jasonkliu,项目名称:term2048,代码行数:11,代码来源:test_ui.py

示例11: test_simple_win_loop_clear

 def test_simple_win_loop_clear(self):
     kp._setNextKey(kp.UP)
     g = Game(goal=4, size=2)
     g.board.cells = [
         [2, 0],
         [2, 0]
     ]
     self.assertEqual(g.loop(), 4)
     if os.name == 'nt':
         self.assertEqual(self.sys_cmd, ('cls',))
     else:
         self.assertEqual(self.sys_cmd, ('clear',))
开发者ID:Primer42,项目名称:term2048-AI,代码行数:12,代码来源:test_game.py

示例12: setUp

 def setUp(self):
     Board.SIZE = _BSIZE
     Game.SCORES_FILE = None
     self.g = Game(scores_file=None)
     self.b = self.g.board
     # don't print anything on stdout
     self.stdout = sys.stdout
     sys.stdout = DevNull()
开发者ID:jasimmk,项目名称:term2048,代码行数:8,代码来源:test_game.py

示例13: __init__

	def __init__(self, iterations=1, print_interval=1, delay=0, heuristic='most_empty', **kws):
		self.delay = delay
		self.heuristic = getattr(self, heuristic)
		total_won, total_score, start_time = 0, 0, time()

		for i in range(1, iterations):
			game = Game(self.get_move, **kws)
			self.board = game.board
			won, score = game.play()
			total_score += score
			total_won += won

			if i % print_interval == 0:
				system('cls')
				print 'iterations completed: ' + str(i)
				print 'simulations per second: ' + str(i / (time() - start_time))
				print 'average score: ' + str(total_score / i)
				print 'total won: ' + str(total_won)
				print 'proportion won: ' + str(total_won / i)
开发者ID:harrisse,项目名称:term2048,代码行数:19,代码来源:ai.py

示例14: start_ai

def start_ai():
    #make a game to use
    g = Game(scores_file='./score.txt')
    #start the ai loop
    numMoves = 0
    try:
        while True:
            numMoves += 1
            print "\nMove %d\n" % numMoves
            print g.__str__(margins={'left': 4, 'top': 1, 'bottom': 1})
            if g.board.won() or not g.board.canMove():
                break
            m = chooseMove(g)
            g.incScore(g.board.move(m))
        g.saveBestScore()
    except KeyboardInterrupt:
        g.saveBestScore()
开发者ID:Primer42,项目名称:term2048-AI,代码行数:17,代码来源:treeSearch.py

示例15: start_game

def start_game(debug=False):
    """
    Start a new game. If ``debug`` is set to ``True``, the game object is
    returned and the game loop isn't fired.
    """
    args = parse_cli_args()

    if args['version']:
        print_version_and_exit()

    if args['rules']:
        print_rules_and_exit()

    game = Game(**args)
    if args['resume']:
        game.restore()

    if debug:
        return game

    return game.loop()
开发者ID:bfontaine,项目名称:term2048,代码行数:21,代码来源:ui.py


注:本文中的term2048.game.Game类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。