\usepackage{tikz}
\usetikzlibrary{patterns}
\usepackage{xparse}

\definecolor{pgfgo}{RGB}{220,179,92}
\colorlet{tablero2}{red!10!blue!10}
\colorlet{tablero3}{blue!10!green!10}
\definecolor{tablero4}{HTML}{9B8465}



\ExplSyntaxOn

\cs_set:Npn\pgfgo_set:n #1 {\keys_set:nn {pgfgo}{#1}}
\cs_generate_variant:Nn \pgfgo_set:n {f, e}


\let\pgfgoset\pgfgo_set:n

\NewDocumentCommand{\pgfgosetallplayers}{m}{\keys_set:nn {pgfgo / players / all}{#1}}


\IfFileExists{../../latex/pgf-go-remember.sty}{\usepackage{../../latex/pgf-go-remember}}{\usepackage{pgf-go-remember}}
\IfFileExists{../../latex/pgf-go-profiles.sty}{\usepackage{../../latex/pgf-go-profiles}}{\usepackage{pgf-go-profiles}}
\IfFileExists{../../latex/pgf-go-players.sty}{\usepackage{../../latex/pgf-go-players}}{\usepackage{pgf-go-players}}
\IfFileExists{../../latex/pgf-go-coordinate-parser.sty}{\usepackage{../../latex/pgf-go-coordinate-parser}}{\usepackage{pgf-go-coordinate-parser}}
\IfFileExists{../../latex/pgf-go-stones.sty}{\usepackage{../../latex/pgf-go-stones}}{\usepackage{pgf-go-stones}}
\IfFileExists{../../latex/pgf-go-goban.sty}{\usepackage{../../latex/pgf-go-goban}}{\usepackage{pgf-go-goban}}
\IfFileExists{../../latex/pgf-go-marks.sty}{\usepackage{../../latex/pgf-go-marks}}{\usepackage{pgf-go-marks}}




\cs_set_eq:NN\pgfgo_old_mark:\mark
\cs_set_eq:NN\pgfgo_old_marks:\marks






\cs_generate_variant:Nn \int_from_alph:n {V, x, e}






\int_new:N\l_pgfgo_parsed_x_coordinate_int
\int_new:N\l_pgfgo_parsed_y_coordinate_int

\cs_set:Nn\pgfgo_parse_coordinate:n{
    \regex_extract_once:nnN{([A-Za-z]*)\s*(\d*)}{#1}\l_coordinates_seq

    \tl_set:Nx\l_pgfgo_parsed_aux_x_coordinate_tl{\seq_item:Nn\l_coordinates_seq{2}}
    \int_set:Nn
        \l_pgfgo_parsed_x_coordinate_int
        {\int_from_alph:V\l_pgfgo_parsed_aux_x_coordinate_tl}

    \bool_if:NF\l_pgfgo_use_i_bool{
        \int_compare:nNnT{\l_pgfgo_parsed_x_coordinate_int}>{9}{ %BAJAR A 8
            \int_decr:N\l_pgfgo_parsed_x_coordinate_int
        }
    }

    \tl_gset:Nn\l_pgfgo_parsed_x_coordinate_tl{\int_use:N\l_pgfgo_parsed_x_coordinate_int}
    \tl_gset:Nn\l_pgfgo_parsed_y_coordinate_tl{\seq_item:Nn\l_coordinates_seq{3}}
}

\cs_set_eq:NN\pgfgo_parse_coordinate:n\pgfgo_parse_coordinate:n

\cs_generate_variant:Nn\pgfgo_parse_coordinate:n {x}




\cs_set:Npn\pgfgo_parse_goban_size:n #1{
    \regex_extract_once:nnNTF{\A([\d]{1,2})\s*x\s*([\d]{1,2})\Z}{#1}\l_pgfgo_goban_dimen_seq{
        \int_set:Nf\l_pgfgo_goban_to_x_int{\seq_item:Nn\l_pgfgo_goban_dimen_seq{2}}
        \int_set:Nf\l_pgfgo_goban_to_y_int{\seq_item:Nn\l_pgfgo_goban_dimen_seq{3}}
      	\int_log:N\l_pgfgo_goban_to_x_int
      	\int_log:N\l_pgfgo_goban_to_y_int
    }{
        \regex_extract_once:nnNTF{\A([\d]{1,2})\Z}{#1}\l_pgfgo_goban_dimen_seq{
            \int_set:Nf\l_pgfgo_goban_to_x_int{\seq_item:Nn\l_pgfgo_goban_dimen_seq{2}}
            \int_set:Nf\l_pgfgo_goban_to_y_int{\seq_item:Nn\l_pgfgo_goban_dimen_seq{2}}
        }{
            You~tried~to~set~key~’\l_keys_key_str’~to~’#1’.
        }
    }
}

\cs_generate_variant:Nn\pgfgo_parse_goban_size:n {V}


\cs_set:Npn\pgfgo_parse_goban_partial_from:n #1 {
    \regex_extract_once:nnN {

        \A\s*
        ([a-zA-Z]{1}\s*\d{1,2})
        \s* to \s*
        ([a-zA-Z]{1}\s*\d{1,2})
        \s*\Z

        }{#1}\l_seq


    \tl_set:Nx\l_temp_a_tl{\seq_item:Nn\l_seq{2}}
    \tl_set:Nx\l_temp_b_tl{\seq_item:Nn\l_seq{3}}
}





\cs_generate_variant:Nn \pgfgo_parse_coordinate:n{V}
\cs_generate_variant:Nn \int_if_odd_p:n{V}
\cs_generate_variant:Nn \int_if_odd:nT{VT}
\cs_generate_variant:Nn \int_if_even_p:n{V}
\cs_generate_variant:Nn \int_if_even:nF{VF}
\cs_generate_variant:Nn \int_set:Nn {Nx}
\cs_generate_variant:Nn \int_to_Alph:n{V}
\cs_generate_variant:Nn \clist_put_right:Nn{Nx}
\cs_generate_variant:Nn \regex_match:nnT {nVT}
\cs_generate_variant:Nn \regex_match:nnTF {nVTF}
\cs_generate_variant:Nn \regex_extract_once:nnNTF {nVNTF}
\cs_generate_variant:Nn \seq_gset:Nn {Nx}


\bool_set_true:N\l_pgfgo_remember_bool
\bool_set_true:N\l_pgfgo_use_i_bool





\keys_define:nn {pgfgo}{
    goban                   .code:n = {\keys_set:nn {pgfgo / goban}         				{#1}},

    stone                   .code:n = {\keys_set:nn {pgfgo / players } 	{all = {stone = {#1}}}},

    move                   .code:n = 	{\keys_set:nn {pgfgo / players } 	{all = {move = {#1}}}},

		mark                    .code:n = {\keys_set:nn {pgfgo / mark}          {#1}},
	
    territory           		.code:n = {\keys_set:nn {pgfgo / territory} {#1}},

    players              		.code:n = {\keys_set:nn {pgfgo / players}    {#1}},

    use~i                   .bool_set:N = \l_pgfgo_use_i_bool,
    
    use~i                   .default:n  = {true}
}


\ExplSyntaxOff






\pgfgouseprofile{default}