本文整理汇总了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
示例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
示例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
示例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