Esempio n. 1
0
def get_actions(state_map, x, y):
    piece = state_map[y][x]

    side = piece[0]

    action_list = []

    piece_type = kcu.GUARDIAN

    # 대각선 오른쪽 전진 길 체크
    if ((y == 9 and x == 3) or (y == 8 and x == 4)) and \
            not kcu.is_our_side(state_map, x + 1, y - 1, side):
        # and not kcu.is_losing_way(state_map, x, y, x + 1, y - 1, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x + 1,
            'to_y': y - 1,
            'direction': kcu.DIAGONAL_FORWARD_RIGHT1,
            'step': 1,
            'piece_type': piece_type
        })

    # 대각선 왼쪽 전진 길 체크
    if ((y == 9 and x == 5) or (y == 8 and x == 4)) and \
            not kcu.is_our_side(state_map, x - 1, y - 1, side):
        # and not kcu.is_losing_way(state_map, x, y, x - 1, y - 1, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x - 1,
            'to_y': y - 1,
            'direction': kcu.DIAGONAL_FORWARD_LEFT1,
            'step': 1,
            'piece_type': piece_type
        })

    # 대각선 오른쪽 후진 길 체크
    if ((y == 7 and x == 3) or (y == 8 and x == 4)) and \
            not kcu.is_our_side(state_map, x + 1, y + 1, side):
        # and not kcu.is_losing_way(state_map, x, y, x + 1, y + 1, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x + 1,
            'to_y': y + 1,
            'direction': kcu.DIAGONAL_BACKWARD_RIGHT1,
            'step': 1,
            'piece_type': piece_type
        })

    # 대각선 왼쪽 후진 길 체크
    if ((y == 7 and x == 5) or (y == 8 and x == 4)) and \
            not kcu.is_our_side(state_map, x - 1, y + 1, side):
        # and not kcu.is_losing_way(state_map, x, y, x - 1, y + 1, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x - 1,
            'to_y': y + 1,
            'direction': kcu.DIAGONAL_BACKWARD_LEFT1,
            'step': 1,
            'piece_type': piece_type
        })

    # 전진 길 체크
    if y in (8, 9) and not kcu.is_our_side(state_map, x, y - 1, side):
        # and   not kcu.is_losing_way(state_map, x, y, x, y - 1, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x,
            'to_y': y - 1,
            'direction': kcu.FORWARD,
            'step': 1,
            'piece_type': piece_type
        })

    # 오른쪽 길 체크
    if x in (3, 4) and not kcu.is_our_side(state_map, x + 1, y, side):
        # and  not kcu.is_losing_way(state_map, x, y, x + 1, y, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x + 1,
            'to_y': y,
            'direction': kcu.RIGHT,
            'step': 1,
            'piece_type': piece_type
        })

    # 왼쪽 길 체크
    if x in (4, 5) and not kcu.is_our_side(state_map, x - 1, y, side):
        # and   not kcu.is_losing_way(state_map, x, y, x - 1, y, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x - 1,
            'to_y': y,
            'direction': kcu.LEFT,
            'step': 1,
            'piece_type': piece_type
        })

    # 후진 길 체크
    if y in (7, 8) and not kcu.is_our_side(state_map, x, y + 1, side):
        # and   not kcu.is_losing_way(state_map, x, y, x, y + 1, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x,
            'to_y': y + 1,
            'direction': kcu.BACKWARD,
            'step': 1,
            'piece_type': piece_type
        })

    return action_list
Esempio n. 2
0
def get_actions(state_map, x, y):
    piece = state_map[y][x]
    side = piece[0]

    action_list = []

    piece_type = kcu.SOLDIER

    # 대각선 오른쪽 길 체크
    if ((y == 1 and x == 4) or (y == 2 and x == 3)) and \
            not kcu.is_our_side(state_map, x + 1, y - 1, side):
        # and not kcu.is_losing_way(state_map, x, y, x + 1, y - 1, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x + 1,
            'to_y': y - 1,
            'direction': kcu.DIAGONAL_FORWARD_RIGHT1,
            'step': 1,
            'piece_type': piece_type
        })

    # 대각선 왼쪽 길 체크
    if ((y == 1 and x == 4) or (y == 2 and x == 5)) and \
            not kcu.is_our_side(state_map, x - 1, y - 1, side):
        # and not kcu.is_losing_way(state_map, x, y, x - 1, y - 1, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x - 1,
            'to_y': y - 1,
            'direction': kcu.DIAGONAL_FORWARD_LEFT1,
            'step': 1,
            'piece_type': piece_type
        })

    # 전진 길 체크
    if y != 0 and not kcu.is_our_side(state_map, x, y - 1, side):
        # and not kcu.is_losing_way(state_map, x, y, x, y - 1, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x,
            'to_y': y - 1,
            'direction': kcu.FORWARD,
            'step': 1,
            'piece_type': piece_type
        })

    # 오른쪽 길 체크
    if x != 8 and not kcu.is_our_side(state_map, x + 1, y, side):
        # and   not kcu.is_losing_way(state_map, x, y, x + 1, y, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x + 1,
            'to_y': y,
            'direction': kcu.RIGHT,
            'step': 1,
            'piece_type': piece_type
        })

    # 왼쪽 길 체크
    if x != 0 and not kcu.is_our_side(state_map, x - 1, y, side):
        # and   not kcu.is_losing_way(state_map, x, y, x - 1, y, side):
        action_list.append({
            'x': x,
            'y': y,
            'to_x': x - 1,
            'to_y': y,
            'direction': kcu.LEFT,
            'step': 1,
            'piece_type': piece_type
        })

    return action_list
Esempio n. 3
0
def get_actions(state_map, x, y):
    piece = state_map[y][x]

    side = piece[0]

    action_list = []

    piece_type = kcu.HORSE

    # 대각선 오른쪽 전진 1 길 체크
    if x < kcu.RIGHT_WALL and y > kcu.TOP_WALL + 1:
        if kcu.is_empty_space(state_map, x, y - 1) and not kcu.is_our_side(
                state_map, x + 1, y - 2, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x + 1,
                'to_y': y - 2,
                'direction': kcu.DIAGONAL_FORWARD_RIGHT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 오른쪽 전진 2 길 체크
    if x < kcu.RIGHT_WALL - 1 and y > kcu.TOP_WALL:
        if kcu.is_empty_space(state_map, x + 1, y) and not kcu.is_our_side(
                state_map, x + 2, y - 1, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x + 2,
                'to_y': y - 1,
                'direction': kcu.DIAGONAL_FORWARD_RIGHT2,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 왼쪽 전진 1 길 체크
    if x > kcu.LEFT_WALL and y > kcu.TOP_WALL + 1:
        if kcu.is_empty_space(state_map, x, y - 1) and not kcu.is_our_side(
                state_map, x - 1, y - 2, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x - 1,
                'to_y': y - 2,
                'direction': kcu.DIAGONAL_FORWARD_LEFT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 왼쪽 전진 2 길 체크
    if x > kcu.LEFT_WALL + 1 and y > kcu.TOP_WALL:
        if kcu.is_empty_space(state_map, x - 1, y) and not kcu.is_our_side(
                state_map, x - 2, y - 1, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x - 2,
                'to_y': y - 1,
                'direction': kcu.DIAGONAL_FORWARD_LEFT2,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 오른쪽 후진 1 길 체크
    if x < kcu.RIGHT_WALL and y < kcu.BOTTOM_WALL - 1:
        if kcu.is_empty_space(state_map, x, y + 1) and not kcu.is_our_side(
                state_map, x + 1, y + 2, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x + 1,
                'to_y': y + 2,
                'direction': kcu.DIAGONAL_BACKWARD_RIGHT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 오른쪽 후진 2 길 체크
    if x < kcu.RIGHT_WALL - 1 and y < kcu.BOTTOM_WALL:
        if kcu.is_empty_space(state_map, x + 1, y) and not kcu.is_our_side(
                state_map, x + 2, y + 1, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x + 2,
                'to_y': y + 1,
                'direction': kcu.DIAGONAL_BACKWARD_RIGHT2,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 왼쪽 후진 1 길 체크
    if x > kcu.LEFT_WALL and y < kcu.BOTTOM_WALL - 1:
        if kcu.is_empty_space(state_map, x, y + 1) and not kcu.is_our_side(
                state_map, x - 1, y + 2, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x - 1,
                'to_y': y + 2,
                'direction': kcu.DIAGONAL_BACKWARD_LEFT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 왼쪽 후진 2 길 체크
    if x > kcu.LEFT_WALL + 1 and y < kcu.BOTTOM_WALL:
        if kcu.is_empty_space(state_map, x - 1, y) and not kcu.is_our_side(
                state_map, x - 2, y + 1, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x - 2,
                'to_y': y + 1,
                'direction': kcu.DIAGONAL_BACKWARD_LEFT2,
                'step': 1,
                'piece_type': piece_type
            })

    return action_list
Esempio n. 4
0
def get_actions(state_map, x, y):
    piece = state_map[y][x]

    side = piece[0]

    action_list = []

    piece_type = kcu.SANG

    # 대각선 오른쪽 전진 1 길 체크
    if x < 7 and y > 2:
        if kcu.is_empty_space(state_map, x, y - 1) \
                and kcu.is_empty_space(state_map, x + 1, y - 2) \
                and not kcu.is_our_side(state_map, x + 2, y - 3, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x + 2,
                'to_y': y - 3,
                'direction': kcu.DIAGONAL_FORWARD_RIGHT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 오른쪽 전진 2 길 체크
    if x < 6 and y > 1:
        if kcu.is_empty_space(state_map, x + 1, y) \
                and kcu.is_empty_space(state_map, x + 2, y - 1) \
                and not kcu.is_our_side(state_map, x + 3, y - 2, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x + 3,
                'to_y': y - 2,
                'direction': kcu.DIAGONAL_FORWARD_RIGHT2,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 왼쪽 전진 1 길 체크
    if x > 1 and y > 2:
        if kcu.is_empty_space(state_map, x, y - 1) \
                and kcu.is_empty_space(state_map, x - 1, y - 2) \
                and not kcu.is_our_side(state_map, x - 2, y - 3, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x - 2,
                'to_y': y - 3,
                'direction': kcu.DIAGONAL_FORWARD_LEFT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 왼쪽 전진 2 길 체크
    if x > 2 and y > 1:
        if kcu.is_empty_space(state_map, x - 1, y) \
                and kcu.is_empty_space(state_map, x - 2, y - 1) \
                and not kcu.is_our_side(state_map, x - 3, y - 2, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x - 3,
                'to_y': y - 2,
                'direction': kcu.DIAGONAL_FORWARD_LEFT2,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 오른쪽 후진 1 길 체크
    if x < 7 and y < 7:
        if kcu.is_empty_space(state_map, x, y + 1) \
                and kcu.is_empty_space(state_map, x + 1, y + 2) \
                and not kcu.is_our_side(state_map, x + 2, y + 3, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x + 2,
                'to_y': y + 3,
                'direction': kcu.DIAGONAL_BACKWARD_RIGHT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 오른쪽 후진 2 길 체크
    if x < 6 and y < 8:
        if kcu.is_empty_space(state_map, x + 1, y) \
                and kcu.is_empty_space(state_map, x + 2, y + 1) \
                and not kcu.is_our_side(state_map, x + 3, y + 2, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x + 3,
                'to_y': y + 2,
                'direction': kcu.DIAGONAL_BACKWARD_RIGHT2,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 왼쪽 후진 1 길 체크
    if x > 1 and y < 7:
        if kcu.is_empty_space(state_map, x, y + 1) \
                and kcu.is_empty_space(state_map, x - 1, y + 2) \
                and not kcu.is_our_side(state_map, x - 2, y + 3, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x - 2,
                'to_y': y + 3,
                'direction': kcu.DIAGONAL_BACKWARD_LEFT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 왼쪽 후진 2 길 체크
    if x > 2 and y < 8:
        if kcu.is_empty_space(state_map, x - 1, y) \
                and kcu.is_empty_space(state_map, x - 2, y + 1) \
                and not kcu.is_our_side(state_map, x - 3, y + 2, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x - 3,
                'to_y': y + 2,
                'direction': kcu.DIAGONAL_BACKWARD_LEFT2,
                'step': 1,
                'piece_type': piece_type
            })

    return action_list
Esempio n. 5
0
def get_actions(state_map, x, y):
    piece = state_map[y][x]

    side = piece[0]

    action_list = []

    piece_type = kcu.CANNON

    # 대각선 오른쪽 전진 길 체크
    if (y == 9 and x == 3) or (y == 2 and x == 3):
        # 왕자리에 디딤돌이 있는지 체크 (포가아니면서 빈자리가 아니면됨)

        step_stone_x = x + 1
        step_stone_y = y - 1
        if kcu.is_piece(state_map, step_stone_x, step_stone_y) \
          and not kcu.is_cannon(state_map, step_stone_x, step_stone_y):
            # 디딤돌 다음 자리에 상대편이나(포가 아니면서) 빈자리가 있는지 체크
            next_of_step_stone_x = step_stone_x + 1
            next_of_step_stone_y = step_stone_y - 1
            if kcu.is_empty_space(state_map, next_of_step_stone_x, next_of_step_stone_y) \
              or kcu.is_enemy(state_map, next_of_step_stone_x, next_of_step_stone_y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': next_of_step_stone_x,
                    'to_y': next_of_step_stone_y,
                    'direction': kcu.DIAGONAL_FORWARD_RIGHT1,
                    'step': 2,
                    'piece_type': piece_type
                })

    # 대각선 왼쪽 전진 길 체크
    if (y == 9 and x == 5) or (y == 2 and x == 5):
        # 왕자리에 디딤돌이 있는지 체크 (포가아니면서 빈자리가 아니면됨)
        step_stone_x = x - 1
        step_stone_y = y - 1
        if kcu.is_piece(state_map, step_stone_x, step_stone_y) \
          and not kcu.is_cannon(state_map, step_stone_x, step_stone_y):
            # 디딤돌 다음 자리에 상대편이나(포가 아니면서) 빈자리가 있는지 체크
            next_of_step_stone_x = step_stone_x - 1
            next_of_step_stone_y = step_stone_y - 1
            if kcu.is_empty_space(state_map, next_of_step_stone_x, next_of_step_stone_y) \
              or kcu.is_enemy(state_map, next_of_step_stone_x, next_of_step_stone_y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': next_of_step_stone_x,
                    'to_y': next_of_step_stone_y,
                    'direction': kcu.DIAGONAL_FORWARD_LEFT1,
                    'step': 2,
                    'piece_type': piece_type
                })

    # 대각선 오른쪽 후진 길 체크
    if (y == 7 and x == 3) or (y == 0 and x == 3):
        # 왕자리에 디딤돌이 있는지 체크 (포가아니면서 빈자리가 아니면됨)
        step_stone_x = x + 1
        step_stone_y = y + 1
        if kcu.is_piece(state_map, step_stone_x, step_stone_y) \
          and not kcu.is_cannon(state_map, step_stone_x, step_stone_y):
            # 디딤돌 다음 자리에 상대편이나(포가 아니면서) 빈자리가 있는지 체크
            next_of_step_stone_x = step_stone_x + 1
            next_of_step_stone_y = step_stone_y + 1
            if kcu.is_empty_space(state_map, next_of_step_stone_x, next_of_step_stone_y) \
              or kcu.is_enemy(state_map, next_of_step_stone_x, next_of_step_stone_y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': next_of_step_stone_x,
                    'to_y': next_of_step_stone_y,
                    'direction': kcu.DIAGONAL_BACKWARD_RIGHT1,
                    'step': 2,
                    'piece_type': piece_type
                })

    # 대각선 왼쪽 후진 길 체크
    if (y == 7 and x == 5) or (y == 0 and x == 5):
        # 왕자리에 디딤돌이 있는지 체크 (포가아니면서 빈자리가 아니면됨)
        step_stone_x = x - 1
        step_stone_y = y + 1
        if kcu.is_piece(state_map, step_stone_x, step_stone_y) \
          and not kcu.is_cannon(state_map, step_stone_x, step_stone_y):
            # 디딤돌 다음 자리에 상대편이나(포가 아니면서) 빈자리가 있는지 체크
            next_of_step_stone_x = step_stone_x - 1
            next_of_step_stone_y = step_stone_y + 1
            if kcu.is_empty_space(state_map, next_of_step_stone_x, next_of_step_stone_y) \
              or kcu.is_enemy(state_map, next_of_step_stone_x, next_of_step_stone_y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': next_of_step_stone_x,
                    'to_y': next_of_step_stone_y,
                    'direction': kcu.DIAGONAL_BACKWARD_LEFT1,
                    'step': 2,
                    'piece_type': piece_type
                })

    # 전진 길 체크
    if y > kcu.TOP_WALL + 1:
        moving_y = y - 1
        step_stone_y = 0
        while moving_y > kcu.TOP_WALL:
            # 건널수 있는게 있는지 검색
            # 가장먼저 포가 나오면 실패
            if kcu.is_cannon(state_map, x, moving_y):
                break

            if kcu.is_piece(state_map, x, moving_y) and not kcu.is_cannon(
                    state_map, x, moving_y):
                step_stone_y = moving_y
                break
            moving_y -= 1

        # 포가아닌 말의 한칸후부터 포이거나 우리편말이나오기 전칸까지 액션 추가
        if step_stone_y > kcu.TOP_WALL and step_stone_y < y:
            next_of_step_stone_y = step_stone_y - 1
            step = 1
            add_step = y - step_stone_y
            while next_of_step_stone_y >= kcu.TOP_WALL:
                # 포이거나 우리편이면 정지
                if kcu.is_cannon(state_map, x, next_of_step_stone_y) or \
                  kcu.is_our_side(state_map, x, next_of_step_stone_y, side):
                    break

                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': x,
                    'to_y': next_of_step_stone_y,
                    'direction': kcu.FORWARD,
                    'step': step + add_step,
                    'piece_type': piece_type
                })

                if kcu.is_enemy(state_map, x, next_of_step_stone_y, side):
                    break

                next_of_step_stone_y -= 1
                step += 1

    # 오른쪽 길 체크
    if x < kcu.RIGHT_WALL - 1:
        moving_x = x + 1
        step_stone_x = 0
        while moving_x < kcu.RIGHT_WALL:
            # 건널수 있는게 있는지 검색
            # 가장먼저 포가 나오면 실패
            if kcu.is_cannon(state_map, moving_x, y):
                break

            if kcu.is_piece(state_map, moving_x,
                            y) and not kcu.is_cannon(state_map, moving_x, y):
                step_stone_x = moving_x
                break
            moving_x += 1

        # 포가아닌 말의 한칸후부터 포이거나 우리편말이나오기 전칸까지 액션 추가
        if step_stone_x < kcu.RIGHT_WALL and step_stone_x > x:
            next_of_step_stone_x = step_stone_x + 1
            step = 1
            add_step = step_stone_x - x
            while next_of_step_stone_x <= kcu.RIGHT_WALL:
                # 포이거나 우리편이면 정지
                if kcu.is_cannon(state_map, next_of_step_stone_x, y) or \
                  kcu.is_our_side(state_map, next_of_step_stone_x, y, side):
                    break

                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': next_of_step_stone_x,
                    'to_y': y,
                    'direction': kcu.RIGHT,
                    'step': step + add_step,
                    'piece_type': piece_type
                })

                if kcu.is_enemy(state_map, next_of_step_stone_x, y, side):
                    break

                next_of_step_stone_x += 1
                step += 1

    # 왼쪽 길 체크
    if x > kcu.LEFT_WALL + 1:
        moving_x = x - 1
        step_stone_x = 0
        while moving_x > kcu.LEFT_WALL:
            # 건널수 있는게 있는지 검색
            # 가장먼저 포가 나오면 실패
            if kcu.is_cannon(state_map, moving_x, y):
                break

            if kcu.is_piece(state_map, moving_x,
                            y) and not kcu.is_cannon(state_map, moving_x, y):
                step_stone_x = moving_x
                break
            moving_x -= 1

        # 포가아닌 말의 한칸후부터 포이거나 우리편말이나오기 전칸까지 액션 추가
        if step_stone_x > kcu.LEFT_WALL and step_stone_x < x:
            next_of_step_stone_x = step_stone_x - 1
            step = 1
            add_step = x - step_stone_x
            while next_of_step_stone_x >= kcu.LEFT_WALL:
                # 포이거나 우리편이면 정지
                if kcu.is_cannon(state_map, next_of_step_stone_x, y) or \
                  kcu.is_our_side(state_map, next_of_step_stone_x, y, side):
                    break

                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': next_of_step_stone_x,
                    'to_y': y,
                    'direction': kcu.LEFT,
                    'step': step + add_step,
                    'piece_type': piece_type
                })

                if kcu.is_enemy(state_map, next_of_step_stone_x, y, side):
                    break

                next_of_step_stone_x -= 1
                step += 1

    # 후진 길 체크
    if y < kcu.BOTTOM_WALL - 1:
        moving_y = y + 1
        step_stone_y = 0
        while moving_y < kcu.BOTTOM_WALL:
            # 건널수 있는게 있는지 검색
            # 가장먼저 포가 나오면 실패
            if kcu.is_cannon(state_map, x, moving_y):
                break

            if kcu.is_piece(state_map, x, moving_y) and not kcu.is_cannon(
                    state_map, x, moving_y):
                step_stone_y = moving_y
                break
            moving_y += 1

        # 포가아닌 말의 한칸후부터 포이거나 우리편말이나오기 전칸까지 액션 추가
        if step_stone_y < kcu.BOTTOM_WALL and step_stone_y > y:
            next_of_step_stone_y = step_stone_y + 1
            step = 1
            add_step = step_stone_y - y
            while next_of_step_stone_y <= kcu.BOTTOM_WALL:
                # 포이거나 우리편이면 정지
                if kcu.is_cannon(state_map, x, next_of_step_stone_y) or \
                  kcu.is_our_side(state_map, x, next_of_step_stone_y, side):
                    break

                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': x,
                    'to_y': next_of_step_stone_y,
                    'direction': kcu.BACKWARD,
                    'step': step + add_step,
                    'piece_type': piece_type
                })

                if kcu.is_enemy(state_map, x, next_of_step_stone_y, side):
                    break

                next_of_step_stone_y += 1
                step += 1

    return action_list
Esempio n. 6
0
def get_actions(state_map, x, y):
    piece = state_map[y][x]

    side = piece[0]

    action_list = []

    piece_type = kcu.CAR

    # 대각선 오른쪽 전진 길 체크
    if (y == 9 and x == 3) or (y == 2 and x == 3):
        moving_y = y - 1
        moving_x = x + 1
        step = 1
        while moving_y >= y - 2:
            if not kcu.is_our_side(state_map, moving_x, moving_y, side):
                # if not kcu.is_losing_way(state_map, x, y, moving_x, moving_y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': moving_x,
                    'to_y': moving_y,
                    'direction': kcu.DIAGONAL_FORWARD_RIGHT1,
                    'step': step,
                    'piece_type': piece_type
                })
                if kcu.is_enemy(state_map, moving_x, moving_y, side):
                    break
            else:
                break
            moving_y -= 1
            moving_x += 1
            step += 1

    if (y == 8 and x == 4) or (y == 1 and x == 4):
        if not kcu.is_our_side(state_map, x + 1, y - 1, side):
            # if not kcu.is_losing_way(state_map, x, y, x + 1, y - 1, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x + 1,
                'to_y': y - 1,
                'direction': kcu.DIAGONAL_FORWARD_RIGHT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 왼쪽 전진 길 체크
    if (y == 9 and x == 5) or (y == 2 and x == 5):
        moving_y = y - 1
        moving_x = x - 1
        step = 1
        while moving_y >= y - 2:
            if not kcu.is_our_side(state_map, moving_x, moving_y, side):
                # if not kcu.is_losing_way(state_map, x, y, moving_x, moving_y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': moving_x,
                    'to_y': moving_y,
                    'direction': kcu.DIAGONAL_FORWARD_LEFT1,
                    'step': step,
                    'piece_type': piece_type
                })
                if kcu.is_enemy(state_map, moving_x, moving_y, side):
                    break
            else:
                break
            moving_y -= 1
            moving_x -= 1
            step += 1

    if (y == 8 and x == 4) or (y == 1 and x == 4):
        if not kcu.is_our_side(state_map, x - 1, y - 1, side):
            # if not kcu.is_losing_way(state_map, x, y, x - 1, y - 1, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x - 1,
                'to_y': y - 1,
                'direction': kcu.DIAGONAL_FORWARD_LEFT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 오른쪽 후진 길 체크
    if (y == 7 and x == 3) or (y == 0 and x == 3):
        moving_y = y + 1
        moving_x = x + 1
        step = 1
        while moving_y <= y + 2:
            if not kcu.is_our_side(state_map, moving_x, moving_y, side):
                # if not kcu.is_losing_way(state_map, x, y, moving_x, moving_y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': moving_x,
                    'to_y': moving_y,
                    'direction': kcu.DIAGONAL_BACKWARD_RIGHT1,
                    'step': step,
                    'piece_type': piece_type
                })
                if kcu.is_enemy(state_map, moving_x, moving_y, side):
                    break
            else:
                break
            moving_y += 1
            moving_x += 1
            step += 1

    if (y == 8 and x == 4) or (y == 1 and x == 4):
        if not kcu.is_our_side(state_map, x + 1, y + 1, side):
            # if not kcu.is_losing_way(state_map, x, y, x + 1, y + 1, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x + 1,
                'to_y': y + 1,
                'direction': kcu.DIAGONAL_BACKWARD_RIGHT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 대각선 왼쪽 후진 길 체크
    if (y == 7 and x == 5) or (y == 0 and x == 5):
        moving_y = y + 1
        moving_x = x - 1
        step = 1
        while moving_y <= y + 2:
            if not kcu.is_our_side(state_map, moving_x, moving_y, side):
                # if not kcu.is_losing_way(state_map, x, y, moving_x, moving_y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': moving_x,
                    'to_y': moving_y,
                    'direction': kcu.DIAGONAL_BACKWARD_LEFT1,
                    'step': step,
                    'piece_type': piece_type
                })
                if kcu.is_enemy(state_map, moving_x, moving_y, side):
                    break
            else:
                break
            moving_y += 1
            moving_x -= 1
            step += 1

    if (y == 8 and x == 4) or (y == 1 and x == 4):
        if not kcu.is_our_side(state_map, x - 1, y + 1, side):
            # if not kcu.is_losing_way(state_map, x, y, x - 1, y + 1, side):
            action_list.append({
                'x': x,
                'y': y,
                'to_x': x - 1,
                'to_y': y + 1,
                'direction': kcu.DIAGONAL_BACKWARD_LEFT1,
                'step': 1,
                'piece_type': piece_type
            })

    # 전진 길 체크
    if y > 0:
        moving_y = y - 1
        step = 1
        while moving_y >= 0:
            if not kcu.is_our_side(state_map, x, moving_y, side):
                # if not kcu.is_losing_way(state_map, x, y, x, moving_y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': x,
                    'to_y': moving_y,
                    'direction': kcu.FORWARD,
                    'step': step,
                    'piece_type': piece_type
                })
                if kcu.is_enemy(state_map, x, moving_y, side):
                    break
            else:
                break
            moving_y -= 1
            step += 1

    # 오른쪽 길 체크
    if x < 8:
        moving_x = x + 1
        step = 1
        while moving_x <= 8:
            if not kcu.is_our_side(state_map, moving_x, y, side):
                # if not kcu.is_losing_way(state_map, x, y, moving_x, y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': moving_x,
                    'to_y': y,
                    'direction': kcu.RIGHT,
                    'step': step,
                    'piece_type': piece_type
                })
                if kcu.is_enemy(state_map, moving_x, y, side):
                    break
            else:
                break
            moving_x += 1
            step += 1

    # 왼쪽 길 체크
    if x > 0:
        moving_x = x - 1
        step = 1
        while moving_x >= 0:
            if not kcu.is_our_side(state_map, moving_x, y, side):
                # if not kcu.is_losing_way(state_map, x, y, moving_x, y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': moving_x,
                    'to_y': y,
                    'direction': kcu.LEFT,
                    'step': step,
                    'piece_type': piece_type
                })
                if kcu.is_enemy(state_map, moving_x, y, side):
                    break
            else:
                break
            moving_x -= 1
            step += 1

    # 후진 길 체크
    if y < 9:
        moving_y = y + 1
        step = 1
        while moving_y <= 9:
            if not kcu.is_our_side(state_map, x, moving_y, side):
                # if not kcu.is_losing_way(state_map, x, y, x, moving_y, side):
                action_list.append({
                    'x': x,
                    'y': y,
                    'to_x': x,
                    'to_y': moving_y,
                    'direction': kcu.BACKWARD,
                    'step': step,
                    'piece_type': piece_type
                })

                if kcu.is_enemy(state_map, x, moving_y, side):
                    break
            else:
                break
            moving_y += 1
            step += 1

    return action_list