本文整理汇总了Python中term2048.game.Game.incScore方法的典型用法代码示例。如果您正苦于以下问题:Python Game.incScore方法的具体用法?Python Game.incScore怎么用?Python Game.incScore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类term2048.game.Game
的用法示例。
在下文中一共展示了Game.incScore方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_ai
# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import incScore [as 别名]
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()
示例2: TestGame
# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import incScore [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
# 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
def tearDown(self):
sys.stdout = self.stdout
os.system = self.system
kp._setCtrlC(False)
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):
s = 42
self.g.score = s
self.g.saveBestScore()
self.assertEqual(self.g.best_score, s)
def test_save_best_score_with_file(self):
s = 1000
scores_file = NamedTemporaryFile(delete=True)
g = Game(scores_file=scores_file.name)
g.best_score = 0
g.score = s
g.saveBestScore()
self.assertEqual(g.best_score, s)
# == .loadBestScore == #
def test_init_with_local_scores_file(self):
s = 4241
scores_file = NamedTemporaryFile(delete=False)
scores_file.write(str(s).encode())
scores_file.close()
g = Game(scores_file=scores_file.name)
self.assertEqual(g.best_score, s)
remove(scores_file.name)
def test_init_with_local_scores_file_fail(self):
scores_file = NamedTemporaryFile(delete=False)
scores_file.close()
Game(scores_file=scores_file.name)
remove(scores_file.name)
# == .incScore == #
def test_inc_0_score(self):
s = 3
self.g.score = s
self.g.best_score = s
self.g.incScore(0)
self.assertEqual(self.g.score, s)
self.assertEqual(self.g.best_score, s)
def test_inc_2_score(self):
s = 3
i = 2
self.g.score = s
self.g.best_score = s
self.g.incScore(i)
self.assertEqual(self.g.score, s + i)
self.assertEqual(self.g.best_score, s + i)
def test_inc_score_update_best_score(self):
s = 3
i = 2
self.g.score = s
self.g.best_score = 0
self.g.incScore(i)
self.assertEqual(self.g.score, s + i)
self.assertEqual(self.g.best_score, s + i)
def test_inc_score_dont_update_best_score_if_higher(self):
s = 3
bs = 80
i = 2
self.g.score = s
self.g.best_score = bs
#.........这里部分代码省略.........
示例3: TestGame
# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import incScore [as 别名]
class TestGame(unittest.TestCase):
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
def tearDown(self):
sys.stdout = self.stdout
os.system = self.system
kp._setCtrlC(False)
def setWindows(self, game, isWin=True):
setattr(game, '_Game__is_windows', isWin)
def assertFileIsNotEmpty(self, path):
with open(path, 'r') as f:
f.seek(0, 2)
size = f.tell()
self.assertNotEqual(0, size)
# == .init == #
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):
s = 42
self.g.score = s
self.g.saveBestScore()
self.assertEqual(self.g.best_score, s)
def test_save_best_score_with_file(self):
s = 1000
scores_file = NamedTemporaryFile(delete=True)
g = Game(scores_file=scores_file.name)
g.best_score = 0
g.score = s
g.saveBestScore()
self.assertEqual(g.best_score, s)
# == .loadBestScore == #
def test_init_with_local_scores_file(self):
s = 4241
scores_file = NamedTemporaryFile(delete=False)
scores_file.write(str(s).encode())
scores_file.close()
g = Game(scores_file=scores_file.name)
self.assertEqual(g.best_score, s)
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)
self.assertEqual(g.best_score, 0)
remove(scores_file.name)
# == .incScore == #
def test_inc_0_score(self):
s = 3
self.g.score = s
self.g.best_score = s
self.g.incScore(0)
self.assertEqual(self.g.score, s)
self.assertEqual(self.g.best_score, s)
def test_inc_2_score(self):
s = 3
i = 2
self.g.score = s
self.g.best_score = s
self.g.incScore(i)
self.assertEqual(self.g.score, s+i)
self.assertEqual(self.g.best_score, s+i)
def test_inc_score_update_best_score(self):
s = 3
i = 2
self.g.score = s
#.........这里部分代码省略.........