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


Python Game.move方法代码示例

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


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

示例1: checknn

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import move [as 别名]
	def checknn(params):
		#create a network
		nn = buildNetwork(16, 5, 5, 4)

		#assign the parameters to be what we are testing
		i = 0
		for m in nn.connections.values():
			for c in m:
				for j in xrange(len(c.params)):
					c._params[j] = params[i]
					i += 1

		map = {
			0: Game.Direction.left,
			1: Game.Direction.right,
			2: Game.Direction.up,
			3: Game.Direction.down,
		}

		# run here
		game = Game()
		while not game.over:
			if random.random() < 0.95:
				inputs = np.hstack(game.state).tolist()
				outputs = nn.activate(inputs).tolist()
				#print outputs
				m = max(outputs)
				i = outputs.index(m)
				move = map[i]
				#print move
				game.move(move)
			else:
				move = map[random.randint(0, 3)]
				game.move(move)

		error = np.log2(2048 - game.max_block)

		print 'score', game.score
		print 'max block', game.max_block
		print 'error', error
		print

		return error
开发者ID:BrendanAnnable,项目名称:2048,代码行数:45,代码来源:train.py

示例2: handle

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import move [as 别名]
    def handle(self, *args, **options):
        player = options['first_player']

        # start a new game
        g = Game()
        g.print_board()

        while True:
            print "Player %c" % player

            x = self.get_input("Enter x-coordinate: ")
            if x is None:
                continue

            y = self.get_input("Enter y-coordinate: ")
            if y is None:
                continue

            try:
                g.move(player, x, y)
                g.print_board()

                end_game_status = g.get_winner_or_draw()

                if end_game_status:
                    if end_game_status == 'draw':
                        print "Draw."
                    else:
                        print "Player %c wins." % end_game_status
                    break

                # change player
                player = 'o' if player == 'x' else 'x'

            except AssertionError, msg:
                print "-----------\n%s\n-----------" % msg
开发者ID:NejcZupec,项目名称:tictactoe,代码行数:38,代码来源:play_game.py

示例3: Game

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

if __name__ == "__main__":
	while True:
		game = Game()
		moves = [
			Game.Direction.up,
			Game.Direction.left,
			Game.Direction.down,
			Game.Direction.right
		]
		i = 0
		while True:
			# move = random.choice(moves)
			move = moves[i]
			i = (i + 1) % len(moves)
			game.move(move)

			# print game.state

			if game.over:
				if game.won:
					print 'You Won!'
				else:
					print 'Game Over :( Moves:', game.num_moves, 'Score:', game.score
				break
开发者ID:BrendanAnnable,项目名称:2048,代码行数:29,代码来源:play_random.py

示例4: Game

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

if __name__ == "__main__":
    game = Game()
    while True:
        print "Score:", game.score
        print game.state
        m = raw_input("Move (wasd): ")
        if m == "w":
            game.move(Game.Direction.up)
        elif m == "a":
            game.move(Game.Direction.left)
        elif m == "s":
            game.move(Game.Direction.down)
        elif m == "d":
            game.move(Game.Direction.right)

        if game.over:
            if game.won:
                print "You Won!"
            else:
                print "Game Over :( Score:", game.score
            break
开发者ID:BrendanAnnable,项目名称:2048,代码行数:25,代码来源:play.py


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