defmodule RiichiAdvanced.YakuTest.RiichiPaoTest do
  use ExUnit.Case, async: true
  alias RiichiAdvanced.TestUtils, as: TestUtils

  test "riichi - daisangen pao ron split" do
    TestUtils.test_yaku_advanced("riichi", [%{name: "honba", config: %{"value" => 100}}, "pao"], """
    {
      "starting_hand": {
        "east": ["2m", "3m", "4m", "4m", "5m", "6m", "7m", "5z", "5z", "6z", "6z", "7z", "7z"],
        "south": ["1m", "3m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "1z", "2z", "3z", "4z"],
        "west": ["1m", "3m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "1z", "2z", "3z", "4z"],
        "north": ["1m", "3m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "1z", "2z", "3z", "4z"]
      },
      "starting_draws": ["1z", "5z", "6z", "7z", "2m", "1m"],
      "starting_honba": 1
    }
    """, [
      %{"type" => "discard", "tile" => "1z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "5z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "7m", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "6z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "6m", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "7z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "5m", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "2m", "player" => 1, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "1m", "player" => 2, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "ron"}, nil, nil, nil]}
    ], %{}, %{delta_scores: [48300, -24300, -24000, 0]})
  end

  test "riichi - daisangen pao ron split reverse honba" do
    TestUtils.test_yaku_advanced("riichi", [%{name: "honba", config: %{"value" => 100}}, "pao"], """
    {
      "starting_hand": {
        "east": ["2m", "3m", "4m", "4m", "5m", "6m", "7m", "5z", "5z", "6z", "6z", "7z", "7z"],
        "south": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "9s", "1z", "2z", "3z", "4z"],
        "west": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "9s", "1z", "2z", "3z", "4z"],
        "north": ["1m", "3m", "7m", "2p", "5p", "8p", "3s", "6s", "9s", "1z", "2z", "3z", "4z"]
      },
      "starting_draws": ["1z", "5z", "6z", "1p", "7z", "1m"],
      "starting_honba": 1
    }
    """, [
      %{"type" => "discard", "tile" => "1z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "5z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "7m", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "6z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "6m", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "1p", "player" => 1, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "7z", "player" => 2, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "5m", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "1m", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "ron"}, nil, nil, nil]}
    ], %{}, %{delta_scores: [48300, -24000, -24300, 0]})
  end

  test "riichi - daisangen pao kan rinshan" do
    TestUtils.test_yaku_advanced("riichi", [%{name: "honba", config: %{"value" => 100}}, "pao"], """
    {
      "starting_hand": {
        "east": ["2m", "3m", "4m", "5m", "6m", "7m", "5z", "5z", "6z", "6z", "7z", "7z", "7z"],
        "south": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "1z", "2z", "3z", "4z"],
        "west": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "1z", "2z", "3z", "4z"],
        "north": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "1z", "2z", "3z", "4z"]
      },
      "starting_draws": ["1z", "5z", "6z", "7z", "2m"],
      "starting_dead_wall": ["2m"],
      "starting_honba": 1
    }
    """, [
      %{"type" => "discard", "tile" => "1z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "5z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "7m", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "6z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "6m", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "7z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "tsumo"}, nil, nil, nil]}
    ], %{}, %{delta_scores: [48300, -48300, 0, 0]})
  end

  test "riichi - daisuushii suukantsu not pao" do
    TestUtils.test_yaku_advanced("riichi", [%{name: "honba", config: %{"value" => 100}}, "pao"], """
    {
      "starting_hand": {
        "east": ["2p", "3p", "1z", "1z", "2z", "2z", "2z", "3z", "3z", "3z", "4z", "4z", "4z"],
        "south": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "5z", "6z", "7z"],
        "west": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "5z", "6z", "7z"],
        "north": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "5z", "6z", "7z"]
      },
      "starting_draws": ["5z", "1z", "2z"],
      "starting_dead_wall": ["1z", "3z", "4z", "3p"],
      "starting_honba": 1
    }
    """, [
      %{"type" => "discard", "tile" => "5z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "1z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "2p", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "2z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "kakan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "ankan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "ankan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "tsumo"}, nil, nil, nil]}
    ], %{}, %{delta_scores: [144300, -48100, -48100, -48100]})
  end

  test "riichi - daisuushii suukantsu pao tsumo" do
    TestUtils.test_yaku_advanced("riichi", [%{name: "honba", config: %{"value" => 100}}, "pao"], """
    {
      "starting_hand": {
        "east": ["2p", "3p", "1z", "1z", "2z", "2z", "2z", "3z", "3z", "3z", "4z", "4z", "4z"],
        "south": ["1m", "2m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "6z", "7z"],
        "west": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "5z", "6z", "7z"],
        "north": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "5z", "6z", "7z"]
      },
      "starting_draws": ["5z", "1z", "2z", "4z"],
      "starting_dead_wall": ["1z", "3z", "5z", "3p"],
      "starting_honba": 1
    }
    """, [
      %{"type" => "discard", "tile" => "5z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "1z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "2p", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "2z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "kakan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "ankan"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "5z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "4z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "tsumo"}, nil, nil, nil]}
    ], %{}, %{delta_scores: [144300, -112300, -16000, -16000]})
  end

  test "riichi - daisuushii suukantsu double pao tsumo" do
    TestUtils.test_yaku_advanced("riichi", [%{name: "honba", config: %{"value" => 100}}, "pao", "pao_suukantsu"], """
    {
      "starting_hand": {
        "east": ["2p", "3p", "1z", "1z", "2z", "2z", "2z", "3z", "3z", "3z", "4z", "4z", "4z"],
        "south": ["1m", "2m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "6z", "7z"],
        "west": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "5z", "6z", "7z"],
        "north": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "5z", "6z", "7z"]
      },
      "starting_draws": ["5z", "1z", "2z", "4z"],
      "starting_dead_wall": ["1z", "3z", "5z", "3p"],
      "starting_honba": 1
    }
    """, [
      %{"type" => "discard", "tile" => "5z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "1z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "2p", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "2z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "kakan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "ankan"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "5z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "4z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "tsumo"}, nil, nil, nil]}
    ], %{}, %{delta_scores: [144300, -144300, 0, 0]})
  end

  test "riichi - rinshan no pao" do
    TestUtils.test_yaku_advanced("riichi", [%{name: "honba", config: %{"value" => 100}}], """
    {
      "starting_hand": {
        "east": ["2m", "3m", "4m", "4m", "5m", "6m", "7m", "5z", "5z", "5z", "7z", "7z", "7z"],
        "south": ["1m", "3m", "7m", "2p", "5p", "8p", "3s", "6s", "9s", "1z", "2z", "3z", "4z"],
        "west": ["1m", "3m", "7m", "2p", "5p", "8p", "3s", "6s", "9s", "1z", "2z", "3z", "4z"],
        "north": ["1m", "3m", "7m", "2p", "5p", "8p", "3s", "6s", "9s", "1z", "2z", "3z", "4z"]
      },
      "starting_draws": ["1z", "5z"],
      "starting_dead_wall": ["4m"],
      "starting_honba": 1
    }
    """, [
      %{"type" => "discard", "tile" => "1z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "5z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "tsumo"}, nil, nil, nil]}
    ], %{east: %{yaku: [{"Chun", 1}, {"Haku", 1}, {"Honitsu", 2}, {"Rinshan", 1}]}}, %{delta_scores: [12300, -4100, -4100, -4100]})
  end

  test "riichi - rinshan pao" do
    TestUtils.test_yaku_advanced("riichi", [%{name: "honba", config: %{"value" => 100}}, "pao_rinshan"], """
    {
      "starting_hand": {
        "east": ["2m", "3m", "4m", "4m", "5m", "6m", "7m", "5z", "5z", "5z", "7z", "7z", "7z"],
        "south": ["1m", "3m", "7m", "2p", "5p", "8p", "3s", "6s", "9s", "1z", "2z", "3z", "4z"],
        "west": ["1m", "3m", "7m", "2p", "5p", "8p", "3s", "6s", "9s", "1z", "2z", "3z", "4z"],
        "north": ["1m", "3m", "7m", "2p", "5p", "8p", "3s", "6s", "9s", "1z", "2z", "3z", "4z"]
      },
      "starting_draws": ["1z", "5z"],
      "starting_dead_wall": ["4m"],
      "starting_honba": 1
    }
    """, [
      %{"type" => "discard", "tile" => "1z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "5z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "tsumo"}, nil, nil, nil]}
    ], %{east: %{yaku: [{"Chun", 1}, {"Haku", 1}, {"Honitsu", 2}, {"Rinshan", 1}]}}, %{delta_scores: [12300, -12300, 0, 0]})
  end

  test "riichi - suukantsu no pao" do
    TestUtils.test_yaku_advanced("riichi", [%{name: "honba", config: %{"value" => 100}}], """
    {
      "starting_hand": {
        "east": ["2p", "3p", "1z", "1z", "2z", "2z", "2z", "3z", "3z", "3z", "7z", "7z", "7z"],
        "south": ["1m", "2m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "4z", "6z"],
        "west": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "4z", "5z", "6z"],
        "north": ["1m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "4z", "5z", "6z"]
      },
      "starting_draws": ["5z", "1z", "2z", "7z"],
      "starting_dead_wall": ["1z", "3z", "5z", "3p"],
      "starting_honba": 1
    }
    """, [
      %{"type" => "discard", "tile" => "5z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "1z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "2p", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "2z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "kakan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "ankan"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "5z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "7z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "tsumo"}, nil, nil, nil]}
    ], %{}, %{delta_scores: [48300, -16100, -16100, -16100]})
  end

  test "riichi - suukantsu pao" do
    TestUtils.test_yaku_advanced("riichi", [%{name: "honba", config: %{"value" => 100}}, "pao_suukantsu"], """
    {
      "starting_hand": {
        "east": ["2p", "3p", "1z", "1z", "2z", "2z", "2z", "3z", "3z", "3z", "7z", "7z", "7z"],
        "south": ["1m", "2m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "4z", "6z"],
        "west": ["1m", "2m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "4z", "6z"],
        "north": ["1m", "2m", "4m", "7m", "2p", "5p", "8p", "3s", "6s", "8s", "9s", "4z", "6z"]
      },
      "starting_draws": ["5z", "1z", "2z", "7z"],
      "starting_dead_wall": ["1z", "3z", "5z", "3p"],
      "starting_honba": 1
    }
    """, [
      %{"type" => "discard", "tile" => "5z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "1z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "pon"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "2p", "player" => 0, "tsumogiri" => false},
      %{"type" => "discard", "tile" => "2z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "kakan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "ankan"}, nil, nil, nil]},
      %{"type" => "discard", "tile" => "5z", "player" => 0, "tsumogiri" => true},
      %{"type" => "discard", "tile" => "7z", "player" => 1, "tsumogiri" => true},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "daiminkan"}, nil, nil, nil]},
      %{"type" => "buttons_pressed", "buttons" => [%{"button" => "tsumo"}, nil, nil, nil]}
    ], %{}, %{delta_scores: [48300, -48300, 0, 0]})
  end

end
