-- コマンド実行
function execute_command(reversal_command, reversal_is_skill)
  local previous_input_type = 0
  -- 非想天則の場合
  -- 先行入力の6 = 起き上がり終わった際のfront だと思われる
  
  -- 起き上がり終わった際のfrontを予測
  -- my_speed, enemy_speedは前方へ向かう速度であるため、
  -- 相手側へ向かう速度を別途算出 -> my_xspeed_to_front, enemy_xspeed_to_front
  local my_xspeed_vector
  if is_dir_front then
    my_xspeed_vector = 1
  else
    my_xspeed_vector = -1
  end
  local enemy_xspeed_vector
  if ((enemy_dir==-1 and back==ACT_LEFT) or
    (enemy_dir==1 and back==ACT_RIGHT))
  then
    enemy_xspeed_vector = 1
  else
    enemy_xspeed_vector = -1
  end
  local my_xspeed_to_front = my_xspeed * my_xspeed_vector
  local enemy_xspeed_to_front = enemy_xspeed * enemy_xspeed_vector
  
  local pre_frame
  if reversal_is_skill then
    pre_frame = reversal_skill_pre_frame
  else
    pre_frame = reversal_no_skill_pre_frame
  end
  debug_print(pre_frame)
  -- -1: 開始時のX座標はxpeedの影響を受けない
  -- -2: 起き上がりきる1〜0フレーム前にxspeedが0以外を取るキャラはいない
  if dis-(my_xspeed_to_front*(pre_frame-3)+enemy_xspeed_to_front*(pre_frame-1))<0 and
    ((ex<x and ex+enemy_xspeed_to_front*(pre_frame-1)>MIN_X) or
      (x<ex and ex-enemy_xspeed_to_front*(pre_frame-1)<MAX_X))
  then
    debug_print("hoge:", dis, "-", (my_xspeed_to_front*(pre_frame-1)+enemy_xspeed_to_front*(pre_frame-3)), "=", dis-(my_xspeed_to_front*(pre_frame-1)+enemy_xspeed_to_front*(pre_frame-3)))
    reversal_front = back
    reversal_back = front
  else
    reversal_front = front
    reversal_back = back
  end
  
  local input, input_type
  for input in string.gmatch( reversal_command, ".") do
    input_type = get_input_type(input)
    local reversal_str = "右"
    if reversal_front==ACT_LEFT then
      reversal_str = "左"
    end
    local _str = "右"
    if front==ACT_LEFT then
      _str = "左"
    end
    debug_print("input", input, _str, reversal_str)
    if previous_input_type==0 then
      -- nothing
    elseif previous_input_type==1 then
      -- 方向キー
      if input_type==1 then
        yield()
        key_reset()
      elseif input_type==2 then
        -- nothing
      elseif input_type==3 then
        -- nothing
      end
    elseif previous_input_type==2 then
      -- A or B or C
      if input_type==1 then
        yield()
        yield()
        key_reset()
      elseif input_type==2 then
        yield()
        yield()
        key_reset()
      elseif input_type==3 then
        yield()
        yield()
        key_reset()
      end
    elseif previous_input_type==3 then
      -- D or E or F
      if input_type==1 then
        yield()
        key_reset()
      elseif input_type==2 then
        yield()
        key_reset()
      elseif input_type==3 then
        yield()
        key_reset()
      end
    end
    
    if input=='1' then
      key_on(ACT_DOWN)
      key_on(reversal_back)
    elseif input=='2' then
      key_on(ACT_DOWN)
    elseif input=='3' then
      key_on(ACT_DOWN)
      key_on(reversal_front)
    elseif input=='4' then
      key_on(reversal_back)
    elseif input=='5' then
      -- nothing
    elseif input=='6' then
      key_on(reversal_front)
    elseif input=='7' then
      key_on(reversal_back)
      key_on(ACT_UP)
    elseif input=='8' then
      key_on(ACT_UP)
    elseif input=='9' then
      key_on(reversal_front)
      key_on(ACT_UP)
    elseif input=='A' or input=='a' then
      key_on(ACT_A)
    elseif input=='B' or input=='b' then
      key_on(ACT_B)
    elseif input=='C' or input=='c' then
      key_on(ACT_C)
    elseif input=='D' or input=='d' then
      key_on(ACT_D)
    elseif input=='E' or input=='e' then
      key_on(ACT_AB)
    elseif input=='F' or input=='f' then
      key_on(ACT_BC)
    end
    previous_input_type = input_type
  end
  yield()
end
