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


Python Game.getCellStr方法代码示例

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


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

示例1: TestGame

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import getCellStr [as 别名]
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,代码行数:48,代码来源:test_game.py

示例2: TestGame

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import getCellStr [as 别名]

#.........这里部分代码省略.........
        self.g.incScore(i)
        self.assertEqual(self.g.score, s + i)
        self.assertEqual(self.g.best_score, bs)

    # == .end == #

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

    # == .readMove == #

    def test_read_unknown_move(self):
        kp._setNextKey(-1)
        self.assertEqual(self.g.readMove(), None)

    def test_read_known_move(self):
        kp._setNextKey(kp.LEFT)
        self.assertEqual(self.g.readMove(), Board.LEFT)

    # == .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()

    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',))

    def test_loop_interrupt(self):
        kp._setCtrlC(True)
        g = Game(goal=4, size=2)
        self.assertEqual(g.loop(), None)

    # == .getCellStr == #

    def test_getCellStr_0(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, Style.RESET_ALL))

    def test_getCellStr_0_azmode(self):
        g = Game(azmode=True)
        g.board.setCell(0, 0, 0)
        self.assertEqual(g.getCellStr(0, 0), '.')

    def test_getCellStr_2(self):
        g = Game()
        g.board.setCell(0, 0, 2)
        self.assertRegexpMatches(g.getCellStr(0, 0), r'  2\x1b\[0m$')

    def test_getCellStr_1k(self):
        g = Game()
        g.board.setCell(0, 0, 1024)
        self.assertRegexpMatches(g.getCellStr(0, 0), r' 1k\x1b\[0m$')

    def test_getCellStr_2k(self):
        g = Game()
        g.board.setCell(0, 0, 2048)
        self.assertRegexpMatches(g.getCellStr(0, 0), r' 2k\x1b\[0m$')

    def test_getCellStr_2_azmode(self):
        g = Game(azmode=True)
        g.board.setCell(0, 0, 2)
        self.assertRegexpMatches(g.getCellStr(0, 0), r'a\x1b\[0m$')

    def test_getCellStr_unknown_number_azmode(self):
        g = Game(azmode=True)
        g.board.setCell(0, 0, 42)
        self.assertEqual(g.getCellStr(0, 0), '?')

    # == .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:Primer42,项目名称:term2048-AI,代码行数:104,代码来源:test_game.py

示例3: test_getCellStr_unknown_number_azmode

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import getCellStr [as 别名]
 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,代码行数:6,代码来源:test_game.py

示例4: test_getCellStr_2k

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import getCellStr [as 别名]
 def test_getCellStr_2k(self):
     g = Game()
     g.board.setCell(0, 0, 2048)
     self.assertRegexpMatches(g.getCellStr(0, 0), r' 2k\x1b\[0m$')
开发者ID:Primer42,项目名称:term2048-AI,代码行数:6,代码来源:test_game.py

示例5: test_getCellStr_2_azmode

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import getCellStr [as 别名]
 def test_getCellStr_2_azmode(self):
     g = Game(azmode=True)
     g.board.setCell(0, 0, 2)
     self.assertRegexpMatches(g.getCellStr(0, 0), r'a\x1b\[0m$')
开发者ID:Primer42,项目名称:term2048-AI,代码行数:6,代码来源:test_game.py

示例6: test_getCellStr_1k

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import getCellStr [as 别名]
 def test_getCellStr_1k(self):
     g = Game()
     g.board.setCell(0, 0, 1024)
     self.assertRegexpMatches(g.getCellStr(0, 0), r' 1k\x1b\[0m$')
开发者ID:Primer42,项目名称:term2048-AI,代码行数:6,代码来源:test_game.py

示例7: test_getCellStr_0_azmode

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import getCellStr [as 别名]
 def test_getCellStr_0_azmode(self):
     g = Game(azmode=True)
     g.board.setCell(0, 0, 0)
     self.assertEqual(g.getCellStr(0, 0), '.')
开发者ID:Primer42,项目名称:term2048-AI,代码行数:6,代码来源:test_game.py

示例8: TestGame

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import getCellStr [as 别名]

#.........这里部分代码省略.........
    # == .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]
        ]
        self.assertEqual(4, g.loop())

    def test_simple_win_loop_clear(self):
        kp._setNextKey(kp.UP)
        g = Game(goal=4, size=2, scores_file=None)
        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',))

    def test_loop_interrupt(self):
        kp._setCtrlC(True)
        g = Game(goal=4, size=2, scores_file=None)
        self.assertEqual(g.loop(), None)

    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)

    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)

    # == .getCellStr == #

    def test_getCellStr_0(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, Style.RESET_ALL))

    def test_getCellStr_0_azmode(self):
        g = Game(azmode=True)
        g.board.setCell(0, 0, 0)
        self.assertEqual(g.getCellStr(0, 0), '.')

    def test_getCellStr_2(self):
        g = Game()
        g.board.setCell(0, 0, 2)
        self.assertRegexpMatches(g.getCellStr(0, 0), r'  2\x1b\[0m$')

    def test_getCellStr_1k(self):
        g = Game()
        g.board.setCell(0, 0, 1024)
        self.assertRegexpMatches(g.getCellStr(0, 0), r' 1k\x1b\[0m$')

    def test_getCellStr_2k(self):
        g = Game()
        g.board.setCell(0, 0, 2048)
        self.assertRegexpMatches(g.getCellStr(0, 0), r' 2k\x1b\[0m$')

    def test_getCellStr_2_azmode(self):
        g = Game(azmode=True)
        g.board.setCell(0, 0, 2)
        self.assertRegexpMatches(g.getCellStr(0, 0), r'a\x1b\[0m$')

    def test_getCellStr_unknown_number_azmode(self):
        g = Game(azmode=True)
        g.board.setCell(0, 0, 42)
        self.assertEqual(g.getCellStr(0, 0), '?')

    # == .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:Anykey228,项目名称:term2048_ai,代码行数:104,代码来源:test_game.py

示例9: test_getCellStr_2

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import getCellStr [as 别名]
 def test_getCellStr_2(self):
     g = Game()
     g.board.setCell(0, 0, 2)
     self.assertRegexpMatches(g.getCellStr(0, 0), r"  2\x1b\[0m$")
开发者ID:jasimmk,项目名称:term2048,代码行数:6,代码来源:test_game.py

示例10: TestGame

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import getCellStr [as 别名]
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)

    # == .end == #

    # == .saveBestScore == #

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

    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)

    # == .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))

    def test_getCellStr_unknown_number_azmode(self):
        g = Game(azmode=True)
        g.board.setCell(0, 0, 0)
        self.assertEqual(g.getCellStr(0, 0), '.')

    def test_getCellStr_unknown_number_azmode(self):
        g = Game(azmode=True)
        g.board.setCell(0, 0, 42)
        self.assertEqual(g.getCellStr(0, 0), '?')

    # == .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())

    # == .loadBestScore == #

    def test_init_with_local_scores_file(self):
        scores_file = NamedTemporaryFile(delete=False)
        scores_file.write('2048'.encode())
        scores_file.close()

        g = Game(scores_file=scores_file.name)
        self.assertEqual(g.best_score, 2048)

        remove(scores_file.name)

    def test_init_with_local_scores_file_fail(self):
        scores_file = NamedTemporaryFile(delete=False)
        scores_file.close()

        g = Game(scores_file=scores_file.name)

        remove(scores_file.name)
开发者ID:techgaun,项目名称:term2048,代码行数:88,代码来源:test_game.py


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