當前位置: 首頁>>代碼示例>>Python>>正文


Python models.Game類代碼示例

本文整理匯總了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")
開發者ID:M-V-Mounica,項目名稱:django-tictactoe,代碼行數:7,代碼來源:test_models.py

示例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")
開發者ID:dgdavis00,項目名稱:django-tictactoe,代碼行數:7,代碼來源:test_models.py

示例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())
開發者ID:mirhampt,項目名稱:Tic-Tac-Toe,代碼行數:7,代碼來源:tests.py

示例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')
開發者ID:dgdavis00,項目名稱:django-tictactoe,代碼行數:7,代碼來源:test_models.py

示例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")
開發者ID:M-V-Mounica,項目名稱:django-tictactoe,代碼行數:7,代碼來源:test_models.py

示例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")
開發者ID:dgdavis00,項目名稱:django-tictactoe,代碼行數:7,代碼來源:test_models.py

示例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)
開發者ID:rlmeyers,項目名稱:FiveWordsOrLess,代碼行數:26,代碼來源:views.py

示例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)
開發者ID:dgdavis00,項目名稱:django-tictactoe,代碼行數:7,代碼來源:test_models.py

示例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")
開發者ID:dgdavis00,項目名稱:django-tictactoe,代碼行數:7,代碼來源:test_models.py

示例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 ")
開發者ID:M-V-Mounica,項目名稱:django-tictactoe,代碼行數:9,代碼來源:test_players.py

示例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")
開發者ID:hellochar,項目名稱:the_game_bazaar,代碼行數:10,代碼來源:tests.py

示例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()
開發者ID:SharifAIChallenge,項目名稱:AIC_game_runner,代碼行數:10,代碼來源:models.py

示例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')
開發者ID:mirhampt,項目名稱:Tic-Tac-Toe,代碼行數:10,代碼來源:tests.py

示例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')
開發者ID:mirhampt,項目名稱:Tic-Tac-Toe,代碼行數:10,代碼來源:tests.py

示例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
開發者ID:jamescleary,項目名稱:bowling-score-v2,代碼行數:12,代碼來源:serializers.py


注:本文中的game.models.Game類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。