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


Python Vote.summary方法代码示例

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


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

示例1: GET

# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import summary [as 别名]
    def GET(self, seq=None):
        now = time.localtime()
        hours_left = 23 - now.tm_hour
        mins_left = 59 - now.tm_min
        time_left = "%02d:%02d" % (hours_left, mins_left)

        current_seq = web.ctx.game.current_seq
        if seq is None:
            seq = current_seq
        else:
            seq = int(seq)

        if web.ctx.game.your_turn or seq != current_seq:
            vote_counts = Vote.summary(web.ctx.game.id, seq)
            top_votes = [
                {
                    'pos': vote.move,
                    'count': int(vote.cnt),
                    'label': vote.move != 'tt' and chr(i + 65) or 'Pass',
                }
                for i, vote in enumerate(vote_counts)
            ]
            comment_counts = Comment.summary(web.ctx.game.id, seq)
            comments = [
                {
                    'pos': comment.move,
                }
                for i, comment in enumerate(comment_counts)
            ]
        else:
            top_votes = []
            comments = []
        turn = seq % 2 == 1 and "Black's turn." or "White's turn."
        game_state = GameState.get(
            game_id=web.ctx.game.id,
            seq=seq - 1,
        )

        system_message = SystemMessage.get()
        if system_message:
            system_message = system_message.message

        return json.dumps({
            'id': web.ctx.game.id,
            'seq': seq,
            'turn': turn,
            'current_seq': current_seq,
            'board_size': 19,
            'board': json.loads(game_state.board),
            'last_move': game_state.move,
            'illegal': json.loads(game_state.illegal),
            'black_captures': game_state.black_captures,
            'white_captures': game_state.white_captures,
            'votes': top_votes,
            'comments': comments,
            'time_left': time_left,
            'system_message': system_message,
        })
开发者ID:dwt,项目名称:congo,代码行数:60,代码来源:game.py

示例2: next_move

# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import summary [as 别名]
def next_move():

    game = Game.current()
    last_state = GameState.get(
        game_id=game.id,
        seq=game.current_seq - 1
    )

    if last_state is None:
        GameState.insert(
            game_id=game.id,
            seq=0,
            black_captures=0,
            white_captures=0,
            illegal=json.dumps([]),
            board=json.dumps([[0] * 19] * 19),
            sgf=DEFAULT_SGF,
        )
        return True

    top_moves = Vote.summary(game.id, game.current_seq)
    if not top_moves:
        return False

    top_move = top_moves[0].move
    result = call_gnugo(
        last_state.sgf,
        game.current_seq,
        top_move,
    )

    next_state = parse_gnugo(result)

    next_state['black_captures'] += last_state['black_captures']
    next_state['white_captures'] += last_state['white_captures']

    GameState.insert(
        game_id=game.id,
        seq=game.current_seq,
        move=top_move,
        **next_state
    )

    Game.insert_or_update(
        keys=('id',),
        id=game.id,
        current_seq=game.current_seq + 1,
    )

    message = 'Move %d, %s plays %s.' % (
        game.current_seq,
        game.current_seq % 2 and "Black" or "White",
        Pretty.pos(top_move),
    )
    for room_id in (1, 2):
        ChatMessage.insert(
            room_id=room_id,
            user_id=0,
            message=message,
        )
        signal_message(room_id, 'send')
开发者ID:justecorruptio,项目名称:congo,代码行数:63,代码来源:logic.py

示例3: GET

# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import summary [as 别名]
    def GET(self):

        game = Game.current()

        web.header(
            'Content-Disposition',
            'attachment; filename="ConGo-game-%s.sgf"' % (game.id,),
        )
        web.header('Content-Type', 'application/x-go-sgf')

        data = [
            '(;GM[1]FF[4]CA[UTF-8]AP[ConGo:0.1]ST[2]',
            'RU[Japanese]SZ[19]KM[6.50]',
            'GN[ConGo Game %s]PW[White Team]PB[Black Team]' % (game.id,),
            'CP[2015 Jay Chan]RO[%s]' % (game.id),
        ]

        end_seq = game.current_seq + 1

        for seq in range(1, end_seq):
            vote_counts = Vote.summary(game.id, seq)
            show_current_move = seq < end_seq - 1

            if seq > 1:
                data.append(';%s[%s]' % (
                    (seq - 1) % 2 == 1 and 'B' or 'W',
                    prev_chosen_move,
                ))

            if show_current_move:
                data.append('LB')
            vote_data = []

            for i, vote in enumerate(list(vote_counts)[:7]):
                label = chr(i + 65)
                if i == 0:
                    chosen_move = vote.move
                if vote.move != 'tt':
                    if show_current_move:
                        data.append('[%s:%s]' % (vote.move, label))
                    vote_data.append('%s: %s votes\n' % (label, vote.cnt))
                else:
                    vote_data.append('Pass: %s votes\n' % (vote.cnt,))

            if seq == 1:
                data.append('C[con-go.net\n\n')
            else:
                data.append('C[')
                votes = Vote.details(game.id, seq - 1, prev_chosen_move)
                for vote in list(votes)[:5]:
                    data.append('%s (%s)\\: ' % (vote.name, Pretty.rating(vote.rating)))
                    notes = re.sub('\n', ' ', vote.notes)
                    notes = re.sub('\[', '(', notes)
                    notes = re.sub('\]', ')', notes)
                    notes = re.sub(r'\\', '\\\\', notes)
                    notes = re.sub(r':', '\\:', notes)
                    data.append(notes + '\n\n')
                data.append('\n')

            if show_current_move:
                data.extend(vote_data)
            data.append(']')
            prev_chosen_move = chosen_move

        data.append(')')

        return ''.join(data)
开发者ID:dwt,项目名称:congo,代码行数:69,代码来源:sgf.py


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