Gann Square 9 Price Line Helper (Experimental)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RozaniGhani-RG
// Inspired by The Tunnel Thru The Air Or Looking Back From 1940, written by WD Gann
//
// Related build
// https://www.tradingview.com/script/WMeyD4Sy-Gann-Square-4-Cross-Cardinal-Table-Concept/
// https://www.tradingview.com/script/mEzLbIKm-Gann-Square-9-Cross-Cardinal-Table-Concept/
// https://www.tradingview.com/script/yH604xPv-Gann-Square-4-Table-Concept-Alternate-UI/
// https://www.tradingview.com/script/n0CPKM4g-Gann-Square-9-Table-Concept-Alternate-UI/


//@version=4
study("Gann Square 9 Price Line Helper (Experimental)", shorttitle = "GS9PLH_Experimental", overlay = true, max_bars_back = 5000, max_lines_count = 500, max_labels_count = 500)


// 0. Arrays
// 1. Variables and general inputs
// 2. Custom functions
// 3. if statament
// 4. Inputs for Cross and Cardinal


// 0. Arrays
//                            0   1   2   3    4    5    6    7    8
arr_cross_0      = array.from(2, 11, 28, 53,  86, 127, 176, 233, 298)
arr_cross_90     = array.from(4, 15, 34, 61,  96, 139, 190, 249, 316)
arr_cross_180    = array.from(6, 19, 40, 69, 106, 151, 204, 265, 334)
arr_cross_270    = array.from(8, 23, 46, 77, 116, 163, 218, 281, 352)
arr_cardinal_45  = array.from(3, 13, 31, 57,  91, 133, 183, 241, 307)
arr_cardinal_135 = array.from(5, 17, 37, 65, 101, 145, 197, 257, 325)
arr_cardinal_225 = array.from(7, 21, 43, 73, 111, 157, 211, 273, 343)
arr_cardinal_315 = array.from(9, 25, 49, 81, 121, 169, 225, 289, 361)
// sort array
array.sort(arr_cross_0,     order.descending)
array.sort(arr_cardinal_45, order.descending)
array.sort(arr_cross_90,    order.descending)


// 1. Variables and general inputs
G0 = "Cross"
G1 = "Cross Cardinal"
G2 = "       Cross          Cardinal"
G3 = "Color"

show_table     = input(true, "Show Table",                                inline = "Table")
input_pos      = input("Left", "", options = ["Left", "Middle", "Right"], inline = "Table")
input_font     = input("Normal", "", options = ["Tiny", "Small", "Normal", "Large", "Huge"], inline = "Table")
table_pos      = input_pos == "Left" ? position.middle_left : input_pos == "Right" ? position.middle_right : position.middle_center
font           = input_font == "Tiny" ? size.tiny  : input_font == "Small" ? size.small :
                 input_font == "Large" ? size.large : input_font == "Huge"  ? size.huge  :
                 size.normal
var testTable  = table.new(position  = table_pos,  columns  = 21,  rows =  21, bgcolor = color.black, border_width = 1)



n0                   = input(0,  "Line Position   ", minval = 0, inline = "Line Position")
n1                   = input(50, "",                 minval = 1, inline = "Line Position")
mult                 = input(1,  "Fixed Gann Multiply           ", options = [0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000, 100000])
style0               = input("Solid",  "Line  ",  options = ["Solid",  "Dash", "Dot"],           group = G2, inline = "Line")
style1               = input("Dash",   "",        options = ["Solid",  "Dash", "Dot"],           group = G2, inline = "Line")
extend0              = input("None",   "Extend",  options = ["None",   "Left", "Right", "Both"], group = G2, inline = "Extend")
extend1              = input("None",   "",        options = ["None",   "Left", "Right", "Both"], group = G2, inline = "Extend")
title0               = input("On",     "Title  ", options = ["On",     "Off"],                   group = G2, inline = "Title")
title1               = input("On",     "",        options = ["On",     "Off"],                   group = G2, inline = "Title")
label0               = input("Normal", "Label ",  options = ["Normal", "Reverse"],               group = G2, inline = "Label")
label1               = input("Normal", "",        options = ["Normal", "Reverse"],               group = G2, inline = "Label")
input_col_cross      = input(false,        "Cross   ",                                           group = G3, inline = "Cross")
input_col_cross_0    = input(color.red,    "",                                                   group = G3, inline = "Cross")
input_col_cross_1    = input(color.lime,   "",   tooltip = "Tick to reverse color",              group = G3, inline = "Cross")
input_col_cardinal   = input(false,        "Cardinal",                                           group = G3, inline = "Cardinal")
input_col_cardinal_0 = input(color.orange, "",                                                   group = G3, inline = "Cardinal")
input_col_cardinal_1 = input(color.teal,   "",   tooltip = "Tick to reverse color",              group = G3, inline = "Cardinal")


col_cross_0     = input_col_cross    ? input_col_cross_0      : input_col_cross_1
col_cross_1     = input_col_cross    ? input_col_cross_1      : input_col_cross_0
col_cardinal_0  = input_col_cardinal ? input_col_cardinal_0   : input_col_cardinal_1
col_cardinal_1  = input_col_cardinal ? input_col_cardinal_1   : input_col_cardinal_0
bar0            = label0 == "Normal" ? bar_index[n0] + 5      : bar_index[n1]
bar1            = label1 == "Normal" ? bar_index[n0] + 5      : bar_index[n1]
pos0            = label0 == "Normal" ? label.style_label_left : label.style_label_right
pos1            = label1 == "Normal" ? label.style_label_left : label.style_label_right

// 2. Custom functions
cell_default(_column, _row, _id, _index)=>
    table.cell(testTable, _column, _row, tostring(array.get(_id, _index)), bgcolor = color.gray, text_color = color.black, text_size = font)
fun_style(_style)   => _style  == "Solid" ? line.style_solid :  _style  == "Dash" ? line.style_dashed : line.style_dotted
fun_extend(_extend) => _extend == "None"  ? extend.none      :  _extend == "Left" ? extend.left : _extend == "Right" ? extend.right : extend.both
cross_title()       => title0  == "On"    ? "Cross : "       : na
cardinal_title()    => title1  == "On"    ? "Cardinal : "    : na

line_new(_arr, _y, _color, _style) =>
    line.new(x1 = bar_index[n1], y1 = array.get(_arr, _y) * mult, x2 = bar_index[n0], y2 = array.get(_arr, _y) * mult,
     color = _color, style = _style)
label_new_0(_text, _arr, _y, _color) =>
    label.new(x = bar0, y = array.get(_arr, _y) * mult,
     text = _text + tostring(array.get(_arr, _y) * mult),
     style = pos0,
     color = _color,
     textcolor = color.black, size = size.normal)
label_new_1(_text, _arr, _y, _color) =>
    label.new(x = bar1, y = array.get(_arr, _y) * mult,
     text = _text + tostring(array.get(_arr, _y) * mult),
     style = pos1,
     color = _color,
     textcolor = color.black, size = size.normal)


// cross custom functions
fun_cross_line(_y) =>
    var  line id0 = na,  line.delete(id0), id0 := line_new(arr_cross_0,   _y, col_cross_0, fun_style(style0)), line.set_extend(id0, fun_extend(extend0))
    var  line id1 = na,  line.delete(id1), id1 := line_new(arr_cross_90,  _y, col_cross_1, fun_style(style0)), line.set_extend(id1, fun_extend(extend0))
    var  line id2 = na,  line.delete(id2), id2 := line_new(arr_cross_180, _y, col_cross_0, fun_style(style0)), line.set_extend(id2, fun_extend(extend0))
    var  line id3 = na,  line.delete(id3), id3 := line_new(arr_cross_270, _y, col_cross_1, fun_style(style0)), line.set_extend(id3, fun_extend(extend0))
fun_cross_label(_y) =>
    var label id0 = na, label.delete(id0), id0 := label_new_0(cross_title(), arr_cross_0,   _y, col_cross_0)
    var label id1 = na, label.delete(id1), id1 := label_new_0(cross_title(), arr_cross_90,  _y, col_cross_1)
    var label id2 = na, label.delete(id2), id2 := label_new_0(cross_title(), arr_cross_180, _y, col_cross_0)
    var label id3 = na, label.delete(id3), id3 := label_new_0(cross_title(), arr_cross_270, _y, col_cross_1)
cross_set(_y, _input, _column0, _row0, _column1, _row1, _column2, _row2, _column3, _row3) =>
    if _input
        if show_table
            table.cell_set_bgcolor(testTable, _column0, _row0, col_cross_0)
            table.cell_set_bgcolor(testTable, _column1, _row1, col_cross_1)
            table.cell_set_bgcolor(testTable, _column2, _row2, col_cross_0)
            table.cell_set_bgcolor(testTable, _column3, _row3, col_cross_1)
        array.sort(arr_cross_0,     order.ascending)
        array.sort(arr_cross_90,    order.ascending)
        fun_cross_line(_y)
        fun_cross_label(_y)


// cardinal custom functions
fun_cardinal_line(_y) =>
    var line  id0 = na,  line.delete(id0), id0 := line_new(arr_cardinal_45,   _y, col_cardinal_0, fun_style(style1)), line.set_extend(id0, fun_extend(extend1))
    var line  id1 = na,  line.delete(id1), id1 := line_new(arr_cardinal_135,  _y, col_cardinal_1, fun_style(style1)), line.set_extend(id1, fun_extend(extend1))
    var line  id2 = na,  line.delete(id2), id2 := line_new(arr_cardinal_225,  _y, col_cardinal_0, fun_style(style1)), line.set_extend(id2, fun_extend(extend1))
    var line  id3 = na,  line.delete(id3), id3 := line_new(arr_cardinal_315,  _y, col_cardinal_1, fun_style(style1)), line.set_extend(id3, fun_extend(extend1))
fun_cardinal_label(_y) =>
    var label id0 = na, label.delete(id0), id0 := label_new_1(cardinal_title(), arr_cardinal_45,  _y, col_cardinal_0)
    var label id1 = na, label.delete(id1), id1 := label_new_1(cardinal_title(), arr_cardinal_135, _y, col_cardinal_1)
    var label id2 = na, label.delete(id2), id2 := label_new_1(cardinal_title(), arr_cardinal_225, _y, col_cardinal_0)
    var label id3 = na, label.delete(id3), id3 := label_new_1(cardinal_title(), arr_cardinal_315, _y, col_cardinal_1)
cardinal_set(_y, _input, _column0, _row0, _column1, _row1, _column2, _row2, _column3, _row3) =>
    if _input
        if show_table
            table.cell_set_bgcolor(testTable, _column0, _row0, col_cardinal_0)
            table.cell_set_bgcolor(testTable, _column1, _row1, col_cardinal_1)
            table.cell_set_bgcolor(testTable, _column2, _row2, col_cardinal_0)
            table.cell_set_bgcolor(testTable, _column3, _row3, col_cardinal_1)
        array.sort(arr_cardinal_45, order.ascending)
        fun_cardinal_line(_y)
        fun_cardinal_label(_y)

// single custom functions
fun_cross_line_style_0(_arr, _y) =>
    var line id = na,   line.delete(id), id := line_new(_arr,  _y, col_cross_0, fun_style(style0))
    line.set_extend(id, fun_extend(extend0))
fun_cross_line_style_1(_arr, _y) =>
    var line id = na,   line.delete(id), id := line_new(_arr,  _y, col_cross_1, fun_style(style0))
    line.set_extend(id, fun_extend(extend0))
fun_cardinal_line_style_0(_arr, _y) =>
    var line id = na,   line.delete(id), id := line_new(_arr,  _y, col_cardinal_0, fun_style(style1))
    line.set_extend(id, fun_extend(extend1))
fun_cardinal_line_style_1(_arr, _y) =>
    var line id = na,   line.delete(id), id := line_new(_arr,  _y, col_cardinal_1, fun_style(style1))
    line.set_extend(id, fun_extend(extend1))

fun_cross_label_0(_text, _arr, _y) =>
    var label id = na, label.delete(id), id := label_new_0(_text, _arr, _y, col_cross_0)
fun_cross_label_1(_text, _arr, _y) =>
    var label id = na, label.delete(id), id := label_new_0(_text, _arr, _y, col_cross_1)
fun_cardinal_label_0(_text, _arr, _y) =>
    var label id = na, label.delete(id), id := label_new_1(_text, _arr, _y, col_cardinal_0)
fun_cardinal_label_1(_text, _arr, _y) =>
    var label id = na, label.delete(id), id := label_new_1(_text, _arr, _y, col_cardinal_1)


fun_cross_set_0(_input, _column, _row, _arr, _y) =>
    if _input
        if show_table
            table.cell_set_bgcolor(testTable, _column, _row, col_cross_0)
        array.sort(arr_cross_0,     order.ascending)
        array.sort(arr_cross_90,    order.ascending)
        array.sort(arr_cardinal_45, order.ascending)
        fun_cross_line_style_0(        _arr, _y)
        fun_cross_label_0(cross_title(),      _arr, _y)
fun_cross_set_1(_input, _column, _row, _arr, _y) =>
    if _input
        if show_table
            table.cell_set_bgcolor(testTable, _column, _row, col_cross_1)
        array.sort(arr_cross_0,     order.ascending)
        array.sort(arr_cross_90,    order.ascending)
        array.sort(arr_cardinal_45, order.ascending)
        fun_cross_line_style_1(   _arr, _y)
        fun_cross_label_1(cross_title(), _arr, _y)


fun_cardinal_set_0(_input, _column, _row, _arr, _y) =>
    if _input
        if show_table
            table.cell_set_bgcolor(testTable, _column, _row, col_cardinal_0)
        array.sort(arr_cross_0,     order.ascending)
        array.sort(arr_cross_90,    order.ascending)
        array.sort(arr_cardinal_45, order.ascending)
        fun_cardinal_line_style_0(             _arr, _y)
        fun_cardinal_label_0(cardinal_title(), _arr, _y)

fun_cardinal_set_1(_input, _column, _row, _arr, _y) =>
    if _input
        if show_table
            table.cell_set_bgcolor(testTable, _column, _row, col_cardinal_1)
        array.sort(arr_cross_0,     order.ascending)
        array.sort(arr_cross_90,    order.ascending)
        array.sort(arr_cardinal_45, order.ascending)
        fun_cardinal_line_style_1(             _arr, _y)
        fun_cardinal_label_1(cardinal_title(), _arr, _y)


// 3. if statament
if barstate.islast
    if show_table
        for _id = 0 to 8
            cell_default(     _id,        9, arr_cross_0,      _id)
            cell_default(     _id,      _id, arr_cardinal_45,  _id)
            cell_default(      10,      _id, arr_cross_90,     _id)
            cell_default(11 + _id,  8 - _id, arr_cardinal_135, _id)
            cell_default(11 + _id,        9, arr_cross_180,    _id)
            cell_default(11 + _id, 11 + _id, arr_cardinal_225, _id)
            cell_default(      10, 11 + _id, arr_cross_270,    _id)
            cell_default(8  - _id, 11 + _id, arr_cardinal_315, _id)


// 4. Inputs for Cross and Cardinal
// input cross                                                                               0     90     180    270
//                                                                               id input    c  r   c  r   c  r  c  r
cross_0   = input(false, "2   4   6   8  ", group = G0, inline = "0"), cross_set(0, cross_0, 8, 9, 10, 8, 11, 9, 10, 11)
cross_1   = input(false, "11  15  19  23 ", group = G0, inline = "1"), cross_set(1, cross_1, 7, 9, 10, 7, 12, 9, 10, 12)
cross_2   = input(false, "28  34  40  46 ", group = G0, inline = "2"), cross_set(2, cross_2, 6, 9, 10, 6, 13, 9, 10, 13)
cross_3   = input(false, "53  61  69  77 ", group = G0, inline = "3"), cross_set(3, cross_3, 5, 9, 10, 5, 14, 9, 10, 14)
cross_4   = input(false, "86  96  106 116", group = G0, inline = "4"), cross_set(4, cross_4, 4, 9, 10, 4, 15, 9, 10, 15)
cross_5   = input(false, "127 139 151 163", group = G0, inline = "5"), cross_set(5, cross_5, 3, 9, 10, 3, 16, 9, 10, 16)
cross_6   = input(false, "176 190 204 218", group = G0, inline = "6"), cross_set(6, cross_6, 2, 9, 10, 2, 17, 9, 10, 17)
cross_7   = input(false, "233 249 265 281", group = G0, inline = "7"), cross_set(7, cross_7, 1, 9, 10, 1, 18, 9, 10, 18)
cross_8   = input(false, "298 316 334 352", group = G0, inline = "8"), cross_set(8, cross_8, 0, 9, 10, 0, 19, 9, 10, 19)

// arr_cross_0
cross_0_0   = input(false, "", group = G0, inline = "0"), fun_cross_set_0(cross_0_0,    8,   9, arr_cross_0,   0)
cross_0_1   = input(false, "", group = G0, inline = "1"), fun_cross_set_0(cross_0_1,    7,   9, arr_cross_0,   1)
cross_0_2   = input(false, "", group = G0, inline = "2"), fun_cross_set_0(cross_0_2,    6,   9, arr_cross_0,   2)
cross_0_3   = input(false, "", group = G0, inline = "3"), fun_cross_set_0(cross_0_3,    5,   9, arr_cross_0,   3)
cross_0_4   = input(false, "", group = G0, inline = "4"), fun_cross_set_0(cross_0_4,    4,   9, arr_cross_0,   4)
cross_0_5   = input(false, "", group = G0, inline = "5"), fun_cross_set_0(cross_0_5,    3,   9, arr_cross_0,   5)
cross_0_6   = input(false, "", group = G0, inline = "6"), fun_cross_set_0(cross_0_6,    2,   9, arr_cross_0,   6)
cross_0_7   = input(false, "", group = G0, inline = "7"), fun_cross_set_0(cross_0_7,    1,   9, arr_cross_0,   7)
cross_0_8   = input(false, "", group = G0, inline = "8"), fun_cross_set_0(cross_0_8,    0,   9, arr_cross_0,   8)

// arr_cross_90
cross_90_0  = input(false, "", group = G0, inline = "0"), fun_cross_set_1(cross_90_0,  10,   8, arr_cross_90,  0)
cross_90_1  = input(false, "", group = G0, inline = "1"), fun_cross_set_1(cross_90_1,  10,   7, arr_cross_90,  1)
cross_90_2  = input(false, "", group = G0, inline = "2"), fun_cross_set_1(cross_90_2,  10,   6, arr_cross_90,  2)
cross_90_3  = input(false, "", group = G0, inline = "3"), fun_cross_set_1(cross_90_3,  10,   5, arr_cross_90,  3)
cross_90_4  = input(false, "", group = G0, inline = "4"), fun_cross_set_1(cross_90_4,  10,   4, arr_cross_90,  4)
cross_90_5  = input(false, "", group = G0, inline = "5"), fun_cross_set_1(cross_90_5,  10,   3, arr_cross_90,  5)
cross_90_6  = input(false, "", group = G0, inline = "6"), fun_cross_set_1(cross_90_6,  10,   2, arr_cross_90,  6)
cross_90_7  = input(false, "", group = G0, inline = "7"), fun_cross_set_1(cross_90_7,  10,   1, arr_cross_90,  7)
cross_90_8  = input(false, "", group = G0, inline = "8"), fun_cross_set_1(cross_90_8,  10,   0, arr_cross_90,  8)

// arr_cross_180 
cross_180_0 = input(false, "", group = G0, inline = "0"), fun_cross_set_0(cross_180_0, 11,   9, arr_cross_180, 0)
cross_180_1 = input(false, "", group = G0, inline = "1"), fun_cross_set_0(cross_180_1, 12,   9, arr_cross_180, 1)
cross_180_2 = input(false, "", group = G0, inline = "2"), fun_cross_set_0(cross_180_2, 13,   9, arr_cross_180, 2)
cross_180_3 = input(false, "", group = G0, inline = "3"), fun_cross_set_0(cross_180_3, 14,   9, arr_cross_180, 3)
cross_180_4 = input(false, "", group = G0, inline = "4"), fun_cross_set_0(cross_180_4, 15,   9, arr_cross_180, 4)
cross_180_5 = input(false, "", group = G0, inline = "5"), fun_cross_set_0(cross_180_5, 16,   9, arr_cross_180, 5)
cross_180_6 = input(false, "", group = G0, inline = "6"), fun_cross_set_0(cross_180_6, 17,   9, arr_cross_180, 6)
cross_180_7 = input(false, "", group = G0, inline = "7"), fun_cross_set_0(cross_180_7, 18,   9, arr_cross_180, 7)
cross_180_8 = input(false, "", group = G0, inline = "8"), fun_cross_set_0(cross_180_8, 19,   9, arr_cross_180, 8)

// arr_cross_270
cross_270_0 = input(false, "", group = G0, inline = "0"), fun_cross_set_1(cross_270_0, 10,  11, arr_cross_270, 0)
cross_270_1 = input(false, "", group = G0, inline = "1"), fun_cross_set_1(cross_270_1, 10,  12, arr_cross_270, 1)
cross_270_2 = input(false, "", group = G0, inline = "2"), fun_cross_set_1(cross_270_2, 10,  13, arr_cross_270, 2)
cross_270_3 = input(false, "", group = G0, inline = "3"), fun_cross_set_1(cross_270_3, 10,  14, arr_cross_270, 3)
cross_270_4 = input(false, "", group = G0, inline = "4"), fun_cross_set_1(cross_270_4, 10,  15, arr_cross_270, 4)
cross_270_5 = input(false, "", group = G0, inline = "5"), fun_cross_set_1(cross_270_5, 10,  16, arr_cross_270, 5)
cross_270_6 = input(false, "", group = G0, inline = "6"), fun_cross_set_1(cross_270_6, 10,  17, arr_cross_270, 6)
cross_270_7 = input(false, "", group = G0, inline = "7"), fun_cross_set_1(cross_270_7, 10,  18, arr_cross_270, 7)
cross_270_8 = input(false, "", group = G0, inline = "8"), fun_cross_set_1(cross_270_8, 10,  19, arr_cross_270, 8)

// input cardinal                                                                                    45    135     225    315
//                                                                                    id input       c  r   c  r   c   r  c  r
cardinal_0 = input(false, "3   5   7   9  ", group = G1, inline =  "9"), cardinal_set(0, cardinal_0, 8, 8, 11, 8, 11, 11, 8, 11)  
cardinal_1 = input(false, "13  17  21  25 ", group = G1, inline = "10"), cardinal_set(1, cardinal_1, 7, 7, 12, 7, 12, 12, 7, 12)
cardinal_2 = input(false, "31  37  43  49 ", group = G1, inline = "11"), cardinal_set(2, cardinal_2, 6, 6, 13, 6, 13, 13, 6, 13)
cardinal_3 = input(false, "57  65  73  81 ", group = G1, inline = "12"), cardinal_set(3, cardinal_3, 5, 5, 14, 5, 14, 14, 5, 14)
cardinal_4 = input(false, "91  101 111 121", group = G1, inline = "13"), cardinal_set(4, cardinal_4, 4, 4, 15, 4, 15, 15, 4, 15)
cardinal_5 = input(false, "133 145 157 169", group = G1, inline = "14"), cardinal_set(5, cardinal_5, 3, 3, 16, 3, 16, 16, 3, 16)
cardinal_6 = input(false, "183 197 211 225", group = G1, inline = "15"), cardinal_set(6, cardinal_6, 2, 2, 17, 2, 17, 17, 2, 17)
cardinal_7 = input(false, "241 257 273 289", group = G1, inline = "16"), cardinal_set(7, cardinal_7, 1, 1, 18, 1, 18, 18, 1, 18)
cardinal_8 = input(false, "307 325 343 361", group = G1, inline = "17"), cardinal_set(8, cardinal_8, 0, 0, 19, 0, 19, 19, 0, 19)

// arr_cardinal_45
cardinal_45_0  = input(false, "", group = G1, inline =  "9"), fun_cardinal_set_0(cardinal_45_0,   8,  8, arr_cardinal_45,  0)
cardinal_45_1  = input(false, "", group = G1, inline = "10"), fun_cardinal_set_0(cardinal_45_1,   7,  7, arr_cardinal_45,  1)
cardinal_45_2  = input(false, "", group = G1, inline = "11"), fun_cardinal_set_0(cardinal_45_2,   6,  6, arr_cardinal_45,  2)
cardinal_45_3  = input(false, "", group = G1, inline = "12"), fun_cardinal_set_0(cardinal_45_3,   5,  5, arr_cardinal_45,  3)
cardinal_45_4  = input(false, "", group = G1, inline = "13"), fun_cardinal_set_0(cardinal_45_4,   4,  4, arr_cardinal_45,  4)
cardinal_45_5  = input(false, "", group = G1, inline = "14"), fun_cardinal_set_0(cardinal_45_5,   3,  3, arr_cardinal_45,  5)
cardinal_45_6  = input(false, "", group = G1, inline = "15"), fun_cardinal_set_0(cardinal_45_6,   2,  2, arr_cardinal_45,  6)
cardinal_45_7  = input(false, "", group = G1, inline = "16"), fun_cardinal_set_0(cardinal_45_7,   1,  1, arr_cardinal_45,  7)
cardinal_45_8  = input(false, "", group = G1, inline = "17"), fun_cardinal_set_0(cardinal_45_8,   0,  0, arr_cardinal_45,  8)

// arr_cardinal_135
cardinal_135_0 = input(false, "", group = G1, inline =  "9"), fun_cardinal_set_1(cardinal_135_0, 11,  8, arr_cardinal_135, 0)
cardinal_135_1 = input(false, "", group = G1, inline = "10"), fun_cardinal_set_1(cardinal_135_1, 12,  7, arr_cardinal_135, 1)
cardinal_135_2 = input(false, "", group = G1, inline = "11"), fun_cardinal_set_1(cardinal_135_2, 13,  6, arr_cardinal_135, 2)
cardinal_135_3 = input(false, "", group = G1, inline = "12"), fun_cardinal_set_1(cardinal_135_3, 14,  5, arr_cardinal_135, 3)
cardinal_135_4 = input(false, "", group = G1, inline = "13"), fun_cardinal_set_1(cardinal_135_4, 15,  4, arr_cardinal_135, 4)
cardinal_135_5 = input(false, "", group = G1, inline = "14"), fun_cardinal_set_1(cardinal_135_5, 16,  3, arr_cardinal_135, 5)
cardinal_135_6 = input(false, "", group = G1, inline = "15"), fun_cardinal_set_1(cardinal_135_6, 17,  2, arr_cardinal_135, 6)
cardinal_135_7 = input(false, "", group = G1, inline = "16"), fun_cardinal_set_1(cardinal_135_7, 18,  1, arr_cardinal_135, 7)
cardinal_135_8 = input(false, "", group = G1, inline = "17"), fun_cardinal_set_1(cardinal_135_8, 19,  0, arr_cardinal_135, 8)

// arr_cardinal_225
cardinal_225_0 = input(false, "", group = G1, inline =  "9"), fun_cardinal_set_0(cardinal_225_0, 11, 11, arr_cardinal_225, 0)
cardinal_225_1 = input(false, "", group = G1, inline = "10"), fun_cardinal_set_0(cardinal_225_1, 12, 12, arr_cardinal_225, 1)
cardinal_225_2 = input(false, "", group = G1, inline = "11"), fun_cardinal_set_0(cardinal_225_2, 13, 13, arr_cardinal_225, 2)
cardinal_225_3 = input(false, "", group = G1, inline = "12"), fun_cardinal_set_0(cardinal_225_3, 14, 14, arr_cardinal_225, 3)
cardinal_225_4 = input(false, "", group = G1, inline = "13"), fun_cardinal_set_0(cardinal_225_4, 15, 15, arr_cardinal_225, 4)
cardinal_225_5 = input(false, "", group = G1, inline = "14"), fun_cardinal_set_0(cardinal_225_5, 16, 16, arr_cardinal_225, 5)
cardinal_225_6 = input(false, "", group = G1, inline = "15"), fun_cardinal_set_0(cardinal_225_6, 17, 17, arr_cardinal_225, 6)
cardinal_225_7 = input(false, "", group = G1, inline = "16"), fun_cardinal_set_0(cardinal_225_7, 18, 18, arr_cardinal_225, 7)
cardinal_225_8 = input(false, "", group = G1, inline = "17"), fun_cardinal_set_0(cardinal_225_8, 19, 19, arr_cardinal_225, 8)

// arr_cardinal_315
cardinal_315_0 = input(false, "", group = G1, inline =  "9"), fun_cardinal_set_1(cardinal_315_0,  8, 11, arr_cardinal_315, 0)
cardinal_315_1 = input(false, "", group = G1, inline = "10"), fun_cardinal_set_1(cardinal_315_1,  7, 12, arr_cardinal_315, 1)
cardinal_315_2 = input(false, "", group = G1, inline = "11"), fun_cardinal_set_1(cardinal_315_2,  6, 13, arr_cardinal_315, 2)
cardinal_315_3 = input(false, "", group = G1, inline = "12"), fun_cardinal_set_1(cardinal_315_3,  5, 14, arr_cardinal_315, 3)
cardinal_315_4 = input(false, "", group = G1, inline = "13"), fun_cardinal_set_1(cardinal_315_4,  4, 15, arr_cardinal_315, 4)
cardinal_315_5 = input(false, "", group = G1, inline = "14"), fun_cardinal_set_1(cardinal_315_5,  3, 16, arr_cardinal_315, 5)
cardinal_315_6 = input(false, "", group = G1, inline = "15"), fun_cardinal_set_1(cardinal_315_6,  2, 17, arr_cardinal_315, 6)
cardinal_315_7 = input(false, "", group = G1, inline = "16"), fun_cardinal_set_1(cardinal_315_7,  1, 18, arr_cardinal_315, 7)
cardinal_315_8 = input(false, "", group = G1, inline = "17"), fun_cardinal_set_1(cardinal_315_8,  0, 19, arr_cardinal_315, 8)
