• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python game.Game类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: setUp

    def setUp(self):
        Board.SIZE = _BSIZE
        Game.SCORES_FILE = None
        self.g = Game(scores_file=None, store_file=None)
        self.b = self.g.board
        # don't print anything on stdout
        self.stdout = sys.stdout
        sys.stdout = DevNull()
        # mock os.system
        self.system = os.system
        self.sys_cmd = None
        def fake_system(*cmd):
            self.sys_cmd = cmd

        os.system = fake_system
开发者ID:Anykey228,项目名称:term2048_ai,代码行数:15,代码来源:test_game.py


示例17: TestGame

class TestGame(unittest.TestCase):

    def setUp(self):
        Board.SIZE = _BSIZE
        Game.SCORES_FILE = None
        self.g = Game(scores_file=None)
        self.b = self.g.board

    def test_init_with_size_3_goal_4(self):
        g = Game(size=3, goal=4, scores_file=None)
        self.assertEqual(g.board.size(), 3)

    # == .saveBestScore == #

    def test_save_best_score_no_file(self):
        self.g.score = 42
        self.g.saveBestScore()
        self.assertEqual(self.g.best_score, 42)

    # == .end == #

    def test_end_can_play(self):
        self.assertFalse(self.g.end())

    # == .getCellStr == #

    def test_getCellStr_unknown_number(self):
        self.b.setCell(0, 0, 0)
        self.assertEqual(self.g.getCellStr(0, 0), '  .')

    def test_getCellStr_unknown_number(self):
        self.b.setCell(0, 0, 42)
        self.assertEqual(self.g.getCellStr(0, 0),
                '%s 42%s' % (Fore.RESET, Fore.RESET))

    # == .boardToString == #

    def test_boardToString_height_no_margins(self):
        s = self.g.boardToString()
        self.assertEqual(len(s.split("\n")), self.b.size())

    # == .__str__ == #

    def test_str_height_no_margins(self):
        s = str(self.g)
        self.assertEqual(len(s.split("\n")), self.b.size())
开发者ID:JosephRedfern,项目名称:term2048,代码行数:46,代码来源:test_game.py


示例18: __init__

 def __init__(self, step):
     Game.__init__(self, scores_file=None, store_file=None)
     self.mdirs=[1,2,3,4]
     self.step=step
     self.count=0
     self.cell=[]
开发者ID:choupi,项目名称:NDHUDLWorkshop,代码行数:6,代码来源:my2048.py


示例19: setUp

 def setUp(self):
     Board.SIZE = _BSIZE
     Game.SCORES_FILE = None
     self.g = Game(scores_file=None)
     self.b = self.g.board
开发者ID:JosephRedfern,项目名称:term2048,代码行数:5,代码来源:test_game.py


示例20: test_getCellStr_unknown_number_azmode

 def test_getCellStr_unknown_number_azmode(self):
     g = Game(azmode=True)
     g.board.setCell(0, 0, 42)
     self.assertEqual(g.getCellStr(0, 0), '?')
开发者ID:Primer42,项目名称:term2048-AI,代码行数:4,代码来源:test_game.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ui.parse_cli_args函数代码示例发布时间:2022-05-27
下一篇:
Python board.Board类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap