本文整理汇总了Python中game.models.Game类的典型用法代码示例。如果您正苦于以下问题:Python Game类的具体用法?Python Game怎么用?Python Game使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Game类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_play_auto_computer_to_computer
def test_play_auto_computer_to_computer(self):
"Two computers playing against themselves."
random.seed(0)
game = Game(player_o="game.players.RandomPlayer", player_x="game.players.RandomPlayer")
game.play_auto()
self.assertEqual(game.board, "X XOOOXOX" if six.PY3 else "OOXOX OXX")
self.assertEqual(game.is_game_over, "O")
示例2: test_play_second
def test_play_second(self):
"The second play is O"
game = Game(board="X ")
game.play(1)
self.assertEqual(game.board, "XO ")
self.assertEqual(game.next_player, "X")
示例3: test_is_game_over_tie
def test_is_game_over_tie(self):
"A game board that is a tie is a game over."
g = Game()
g.board_state = [['X', 'O', 'X'],
['X', 'O', 'X'],
['O', 'X', 'O']]
self.assertTrue(g.is_game_over())
示例4: test_play_auto_computer_to_computer
def test_play_auto_computer_to_computer(self):
"Two computers playing against themselves."
random.seed(0)
game = Game(player_o='game.players.RandomPlayer', player_x='game.players.RandomPlayer')
game.play_auto()
self.assertEqual(game.board, "OOXOX OXX")
self.assertEqual(game.is_game_over, 'O')
示例5: test_play_auto_computer_human
def test_play_auto_computer_human(self):
"At the start of the game, computer starts."
random.seed(0)
game = Game(player_o="human", player_x="game.players.RandomPlayer")
game.play_auto()
self.assertEqual(game.board, " X " if six.PY3 else " X ")
self.assertEqual(game.next_player, "O")
示例6: test_play_first
def test_play_first(self):
"X always goes first"
game = Game()
game.play(0)
self.assertEqual(game.board, "X ")
self.assertEqual(game.next_player, "O")
示例7: new_game
def new_game(request,pk):
if request.method=='GET':
player = Player.objects.get(pk=pk)
players = Player.objects.all()
genres = Genre.objects.all()
return render(request,'player/new_game.html',{'players':players,'genres':genres,'player':player})
else:
print '## Adding New Game ##'
game = Game(name = request.POST['name'],date = timezone.now(),active=False)
genres = request.POST.getlist('genres')
game.save()
for genre in genres:
game.genres.add(Genre.objects.get(pk=genre))
game.save()
print '## Saved Game ID: %s with name %s ##' % (game.id,game.name)
player = Player.objects.get(pk=pk)
PG = Player_Game(game = game, player = player, score = 0,accepted = True, declined = False)
print '## The first player in the game is %s with ID %s ##' % (player.name, player.id)
PG.save()
players = request.POST.getlist('players')
for p in players:
player = Player.objects.get(pk = int(p))
PG = Player_Game(game = game, player = player, score = 0, accepted = False, declined = False)
PG.save()
print '## Player %s with ID %s was invited to this game ##' % (player.name,player.id)
return HttpResponseRedirect("/player/%s/"%pk)
示例8: test_play_error_square_taken
def test_play_error_square_taken(self):
"You can't play a square that is taken."
game = Game(board="XOX ")
with self.assertRaises(ValueError):
game.play(1)
game.play(2)
示例9: test_play_auto_computer_human
def test_play_auto_computer_human(self):
"At the start of the game, computer starts."
random.seed(0)
game = Game(player_o='human', player_x='game.players.RandomPlayer')
game.play_auto()
self.assertEqual(game.board, " X ")
self.assertEqual(game.next_player, "O")
示例10: test_random
def test_random(self):
"Basic testing."
random.seed(0) # For testing
game = Game()
p1 = RandomPlayer()
game.play(p1.play(game))
self.assertEqual(game.board, " X " if six.PY3 else " X ")
示例11: test_add_user_to_game
def test_add_user_to_game(self):
game, _ = Game.create_new_game(self.aMap.id, self.user)
# Perform the join logic
_, players_json, player_id = Game.add_user_to_game(game.id, self.joiner)
# Check a bunch of conditions
self.assertEqual(len(players_json), 3)
self.assertEqual(players_json[0], "hosting_player")
self.assertEqual(players_json[1], "joining_player")
示例12: accept
def accept(self, accepted):
wait = GameRequest.check_last_time(self.requester)
if wait:
return wait
self.accepted = accepted
self.accept_time = timezone.now()
if accepted:
Game.create([self.requestee, self.requester], game_conf=self.game_config)
self.save()
示例13: test_get_winner_column
def test_get_winner_column(self):
"Three in a column is a winner."
for i in xrange(0, 3):
g = Game()
g.board_state[0][i] = g.board_state[1][i] = g.board_state[2][i] = 'X'
self.assertEquals(g.get_winner(), 'X')
g = Game()
g.board_state[0][i] = g.board_state[1][i] = g.board_state[2][i] = 'O'
self.assertEquals(g.get_winner(), 'O')
示例14: test_get_winner_rows
def test_get_winner_rows(self):
"Three in a row is a winner."
for i in xrange(0, 3):
g = Game()
g.board_state[i][0] = g.board_state[i][1] = g.board_state[i][2] = 'X'
self.assertEquals(g.get_winner(), 'X')
g = Game()
g.board_state[i][0] = g.board_state[i][1] = g.board_state[i][2] = 'O'
self.assertEquals(g.get_winner(), 'O')
示例15: validate_rolls
def validate_rolls(self, rolls):
"""Make sure incoming rolls arrays are good"""
# create a game object which won't be saved to the database
# so we can check that our rolls list is valid
test_game = Game(name="test_game", _rolls='[]')
try:
for roll in rolls:
test_game.add_roll(roll)
except:
raise serializers.ValidationError("Rolls list was invald")
return rolls