Beispiel #1
0
 def _move_str(self, move):
     to_sq = cshogi.move_to(move)
     move_to = KIFU_TO_SQUARE_NAMES[to_sq]
     if self.prev_move:
         if cshogi.move_to(self.prev_move) == to_sq:
             move_to = "同 "
     if not cshogi.move_is_drop(move):
         from_sq = cshogi.move_from(move)
         move_piece = cshogi.PIECE_JAPANESE_SYMBOLS[cshogi.move_from_piece_type(move)]
         if cshogi.move_is_promotion(move):
             return '{}{}成({})'.format(
                 move_to,
                 move_piece,
                 KIFU_FROM_SQUARE_NAMES[from_sq],
                 )
         else:
             return '{}{}({})'.format(
                 move_to,
                 move_piece,
                 KIFU_FROM_SQUARE_NAMES[from_sq],
                 )
     else:
         move_piece = cshogi.HAND_PIECE_JAPANESE_SYMBOLS[cshogi.move_drop_hand_piece(move)]
         return '{}{}打'.format(
             move_to,
             move_piece
             )
def get_move_label(move, color):
    if not move_is_drop(move):
        from_sq = move_from(move)
        to_sq = move_to(move)
        if color == cshogi.WHITE:
            to_sq = 80 - to_sq
            from_sq = 80 - from_sq

        # file: 筋, rank: 段
        from_file, from_rank = divmod(from_sq, 9)
        to_file, to_rank = divmod(to_sq, 9)
        dir_file = to_file - from_file
        dir_rank = to_rank - from_rank
        if dir_rank < 0 and dir_file == 0:
            move_direction = UP
        elif dir_rank == -2 and dir_file == -1:
            move_direction = UP2_RIGHT
        elif dir_rank == -2 and dir_file == 1:
            move_direction = UP2_LEFT
        elif dir_rank < 0 and dir_file < 0:
            move_direction = UP_RIGHT
        elif dir_rank < 0 and dir_file > 0:
            move_direction = UP_LEFT
        elif dir_rank == 0 and dir_file < 0:
            move_direction = RIGHT
        elif dir_rank == 0 and dir_file > 0:
            move_direction = LEFT
        elif dir_rank > 0 and dir_file == 0:
            move_direction = DOWN
        elif dir_rank > 0 and dir_file < 0:
            move_direction = DOWN_RIGHT
        elif dir_rank > 0 and dir_file > 0:
            move_direction = DOWN_LEFT
        else:
            raise RuntimeError

        # promote
        if move_is_promotion(move):
            move_direction = MOVE_DIRECTION_PROMOTED[move_direction]

    else:
        # 持ち駒
        move_direction = len(MOVE_DIRECTION) + move_drop_hand_piece(move) - 1
        to_sq = move_to(move)
        if color == cshogi.WHITE:
            to_sq = 80 - to_sq

    # labelのmaxは27*81-1=2186
    move_label = move_direction * 81 + to_sq
    return move_label
Beispiel #3
0
def move_to_san(move):
    move_to = PGN_SQUARE_NAMES[cshogi.move_to(move)]

    if cshogi.move_is_drop(move):
        return PGN_HAND_PIECES[cshogi.move_drop_hand_piece(
            move)] + '@' + move_to

    move_from = PGN_SQUARE_NAMES[cshogi.move_from(move)]
    promotion = '+' if cshogi.move_is_promotion(move) else ''
    return PGN_PIECE_TYPES[cshogi.move_from_piece_type(
        move)] + move_from + move_to + promotion