\ProvidesFile{pgf-go-profiles.sty}[2026/10/30 v0.2026.10.30 pgf-go: profiles]
\ExplSyntaxOn
%UN PERFIL ES UNA LISTA DE CLAVES CON NOMBRE: LOS DE TABLERO VAN EN \g_pgfgo_profile_goban_prop (CLAVES DE
%/pgfgo/goban) Y LOS DE JUGADOR EN \g_pgfgo_profile_player_prop (CLAVES DE UN JUGADOR DE /pgfgo/players).
\prop_new:N \g_pgfgo_profile_player_prop
\prop_new:N \g_pgfgo_profile_goban_prop

\tl_new:N \l_pgfgo_profile_define_goban_name_tl
\tl_new:N \l_pgfgo_profile_define_player_name_tl
\tl_new:N \l_pgfgo_profile_goban_from_tl
\tl_new:N \l_pgfgo_profile_player_from_tl
\tl_new:N \l__pgfgo_profile_options_tl

\msg_new:nnn {pgfgo} {unknown-goban-profile} {Unknown~goban~profile~'#1'.}
\msg_new:nnn {pgfgo} {unknown-player-profile} {Unknown~player~profile~'#1'.}

%#1: goban O player. #2: NOMBRE DEL PERFIL. DEJA SUS CLAVES EN \l__pgfgo_profile_options_tl (VACIO Y UN
%ERROR SI NO EXISTE).
\cs_new_protected:Npn \__pgfgo_profile_get:nn #1#2 {
	\prop_get:cnNF {g_pgfgo_profile_ #1 _prop} {#2} \l__pgfgo_profile_options_tl {
		\tl_clear:N \l__pgfgo_profile_options_tl
		\msg_error:nnn {pgfgo} {unknown- #1 -profile} {#2}
	}
}
\cs_generate_variant:Nn \__pgfgo_profile_get:nn {nv}

%EL REINICIO: LOS VALORES DEL ASPECTO DEL TABLERO Y DE CADA JUGADOR AL TERMINAR DE CARGAR EL PAQUETE (CON EL
%PERFIL default). USAR UN PERFIL VUELVE A ELLOS ANTES DE PONER SUS CLAVES, ASI NO HEREDA LO QUE NO DEFINE.
%DEL TABLERO NO SE TOCA LO QUE NO ES ASPECTO: LAS VARIABLES CON ESTOS NOMBRES (EL TAMANO Y use i NO SON
%VARIABLES DEL ESTILO). LAS DE LAS FLECHAS Y LINEAS (l__pgfgo_arrow_..., l__pgfgo_line_...) SON DEL TABLERO.
\clist_const:Nn \c__pgfgo_profile_keep_goban_clist {
	captures, captured_marks, notes, scale, partial, layers, bbox, labels_pos, label_columns, label_rows, hoshi_at
}
\tl_new:N \g__pgfgo_profile_reset_goban_tl
\clist_map_inline:nn {neutral, black, white} {\tl_new:c {g__pgfgo_profile_reset_ #1 _tl}}
\str_new:N \l__pgfgo_profile_var_str
\bool_new:N \l__pgfgo_profile_keep_bool

%SE LLAMA UNA VEZ, AL FINAL DE pgf-go.sty. USA LAS VARIABLES DEL ESTILO (\g_pgfgo_style_vars_seq) Y
%\__pgfgo_style_value:nN (pgf-go-goban.sty).
\cs_new_protected:Npn \pgfgo_profile_save_reset: {
	\seq_map_inline:Nn \g_pgfgo_style_vars_seq {\__pgfgo_profile_save_reset:nN ##1}
	\clist_map_inline:nn {neutral, black, white} {
		\clist_map_inline:nn {move_label_format:n, mark_sequence_format:n} {
			\cs_gset_eq:cc {pgfgo~profile~reset~##1~####1} {pgfgo_players_ ##1 _ ####1}
			\tl_gput_right:ce {g__pgfgo_profile_reset_ ##1 _tl}
				{\exp_not:N \cs_set_eq:cc {pgfgo_players_ ##1 _ ####1} {pgfgo~profile~reset~##1~####1}}
		}
	}
}
%SIN REGEX: SE LLAMA UNA VEZ POR VARIABLE DEL ESTILO (CIENTOS) Y COMPILAR UNA REGEX EN CADA LLAMADA COSTABA
%LA MITAD DEL TIEMPO DE CARGA DEL PAQUETE.
\prg_new_conditional:Npnn \__pgfgo_profile_var_prefix:n #1 {p, TF} {
	\str_if_eq:eeTF {\str_range:Nnn \l__pgfgo_profile_var_str {1} {\str_count:n {#1}}} {#1}
		{\prg_return_true:} {\prg_return_false:}
}
\cs_new_protected:Npn \__pgfgo_profile_save_reset:nN #1#2 {
	\str_set:Ne \l__pgfgo_profile_var_str {\cs_to_str:N #2}
	\bool_lazy_any:nTF {
		{\__pgfgo_profile_var_prefix_p:n {l_pgfgo_goban_}}
		{\__pgfgo_profile_var_prefix_p:n {l__pgfgo_arrow_}}
		{\__pgfgo_profile_var_prefix_p:n {l__pgfgo_line_}}
	}{
		\bool_set_false:N \l__pgfgo_profile_keep_bool
		\clist_map_inline:Nn \c__pgfgo_profile_keep_goban_clist {
			\str_if_in:NnT \l__pgfgo_profile_var_str {##1} {\bool_set_true:N \l__pgfgo_profile_keep_bool}
		}
		\bool_if:NF \l__pgfgo_profile_keep_bool
			{\tl_gput_right:Ne \g__pgfgo_profile_reset_goban_tl {\__pgfgo_style_value:nN {#1} #2}}
	}{
		%LAS DE UN JUGADOR, SALVO l_pgfgo_players_<jugador>_bool (SI LA PIEDRA ES DE ESE JUGADOR).
		\clist_map_inline:nn {neutral, black, white} {
			\__pgfgo_profile_var_prefix:nTF {l_pgfgo_players_ ##1 _} {
				\str_if_eq:eeF {\str_range:Nnn \l__pgfgo_profile_var_str {\str_count:n {l_pgfgo_players_ ##1 _} + 1} {-1}}
					{bool} {\tl_gput_right:ce {g__pgfgo_profile_reset_ ##1 _tl} {\__pgfgo_style_value:nN {#1} #2}}
				\clist_map_break:
			} {}
		}
	}
}
\cs_generate_variant:Nn \tl_gput_right:Nn {ce}

\cs_new_protected:Npn \pgfgo_profile_use_goban:n #1 {
	\prop_if_in:NnT \g_pgfgo_profile_goban_prop {#1} {\tl_use:N \g__pgfgo_profile_reset_goban_tl}
	\__pgfgo_profile_get:nn {goban} {#1}
	\pgfgo_set:e {goban = {\exp_not:V \l__pgfgo_profile_options_tl}}
}

%#1: neutral, black O white. #2: NOMBRE DEL PERFIL.
\cs_new_protected:Npn \pgfgo_profile_use_player:nn #1#2 {
	\prop_if_in:NnT \g_pgfgo_profile_player_prop {#2} {\tl_use:c {g__pgfgo_profile_reset_ #1 _tl}}
	\__pgfgo_profile_get:nn {player} {#2}
	\pgfgo_set:e {players = {#1 = {\exp_not:V \l__pgfgo_profile_options_tl}}}
}

%players profile = <nombre>: LOS JUGADORES <nombre>-neutral, <nombre>-black Y <nombre>-white. profile = <nombre>:
%ADEMAS, EL TABLERO <nombre>. EL DEL TABLERO SOLO ES goban profile (NO goban/profile: EN LAS OPCIONES DE UN goban,
%profile SERIA EL DEL TABLERO).
\cs_new_protected:Npn \pgfgo_profile_use_players:n #1 {
	\clist_map_inline:nn {neutral, black, white} {\pgfgo_profile_use_player:nn {##1} {#1-##1}}
}
\cs_new_protected:Npn \pgfgo_profile_use_profile:n #1 {
	\pgfgo_profile_use_goban:n {#1}
	\pgfgo_profile_use_players:n {#1}
}
\keys_define:nn {pgfgo} {
	profile					.code:n	= {\pgfgo_profile_use_profile:n {#1}},
	goban~profile		.code:n	= {\pgfgo_profile_use_goban:n {#1}},
	players~profile	.code:n	= {\pgfgo_profile_use_players:n {#1}},
}

%OPCIONES DE \pgfgodefinegoban Y \pgfgodefineplayer: from = <PERFIL> EMPIEZA CON LAS CLAVES DE ESE PERFIL;
%append, CON LAS DEL PERFIL QUE SE ESTA DEFINIENDO.
\keys_define:nn {pgfgo / profiles / goban} {
	from 		.tl_set:N = \l_pgfgo_profile_goban_from_tl,
	append 	.code:n = {\tl_set_eq:NN \l_pgfgo_profile_goban_from_tl \l_pgfgo_profile_define_goban_name_tl}
}
\keys_define:nn {pgfgo / profiles / player} {
	from 		.tl_set:N = \l_pgfgo_profile_player_from_tl,
	append 	.code:n = {\tl_set_eq:NN \l_pgfgo_profile_player_from_tl \l_pgfgo_profile_define_player_name_tl}
}

%#1: goban O player. #2: OPCIONES. #3: NOMBRE DEL PERFIL. #4: SUS CLAVES.
\cs_new_protected:Npn \__pgfgo_profile_define:nnnn #1#2#3#4 {
	\tl_set:cn {l_pgfgo_profile_define_ #1 _name_tl} {#3} %OJO PORQUE SE CONSERVA EL NOMBRE
	\tl_clear:c {l_pgfgo_profile_ #1 _from_tl} %CADA DEFINICION EMPIEZA SIN from
	\keys_set:nn {pgfgo / profiles / #1} {#2}
	\tl_if_empty:cTF {l_pgfgo_profile_ #1 _from_tl}
		{\tl_clear:N \l__pgfgo_profile_options_tl}
		{
			\__pgfgo_profile_get:nv {#1} {l_pgfgo_profile_ #1 _from_tl}
			\tl_put_right:Nn \l__pgfgo_profile_options_tl {,}
		}
	\prop_gput:cno {g_pgfgo_profile_ #1 _prop} {#3} {\l__pgfgo_profile_options_tl, #4}
}

\DeclareDocumentCommand{\pgfgodefinegoban}{O{}mm}{\__pgfgo_profile_define:nnnn {goban} {#1} {#2} {#3}}
\DeclareDocumentCommand{\pgfgodefineplayer}{O{}mm}{\__pgfgo_profile_define:nnnn {player} {#1} {#2} {#3}}

%\pgfgodefineprofile[from = <perfil>]{<nombre>}{goban = .., all = .., neutral = .., black = .., white = ..}
%DEFINE DE UNA VEZ EL PERFIL <nombre> (PARA profile = <nombre>): EL TABLERO <nombre> Y LOS JUGADORES
%<nombre>-neutral, <nombre>-black Y <nombre>-white. all VA A LOS TRES JUGADORES, ANTES DE LO DE CADA UNO.
%CON from, CADA PARTE EMPIEZA CON LA DEL PERFIL <perfil> (<perfil>, <perfil>-neutral, ...).
\tl_new:N \l__pgfgo_profile_from_tl
\clist_map_inline:nn {goban, all, neutral, black, white} {\tl_new:c {l__pgfgo_profile_ #1 _tl}}
\keys_define:nn {pgfgo / profiles / profile} {
	from			.tl_set:N	= \l__pgfgo_profile_from_tl,
	goban			.tl_set:N	= \l__pgfgo_profile_goban_tl,
	all				.tl_set:N	= \l__pgfgo_profile_all_tl,
	neutral		.tl_set:N	= \l__pgfgo_profile_neutral_tl,
	black			.tl_set:N	= \l__pgfgo_profile_black_tl,
	white			.tl_set:N	= \l__pgfgo_profile_white_tl,
}
\DeclareDocumentCommand{\pgfgodefineprofile}{O{}mm}{
	\group_begin:
		\clist_map_inline:nn {from, goban, all, neutral, black, white} {\tl_clear:c {l__pgfgo_profile_ ##1 _tl}}
		\keys_set:nn {pgfgo / profiles / profile} {#1, #3}
		\use:e {
			\exp_not:N \__pgfgo_profile_define:nnnn {goban}
				{\tl_if_empty:NF \l__pgfgo_profile_from_tl {from = {\exp_not:V \l__pgfgo_profile_from_tl}}}
				{\exp_not:n {#2}} {\exp_not:V \l__pgfgo_profile_goban_tl}
		}
		\clist_map_inline:nn {neutral, black, white} {
			\use:e {
				\exp_not:N \__pgfgo_profile_define:nnnn {player}
					{\tl_if_empty:NF \l__pgfgo_profile_from_tl {from = {\exp_not:V \l__pgfgo_profile_from_tl - ##1}}}
					{\exp_not:n {#2} - ##1}
					{\exp_not:V \l__pgfgo_profile_all_tl, \exp_not:v {l__pgfgo_profile_ ##1 _tl}}
			}
		}
	\group_end:
}

\ExplSyntaxOff




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%------------DEFAULT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pgfgodefinegoban{default}{
	background = {
		line = {
			true,
			color = black,
			opacity = 1,
			width = 0.75pt,
		},
		fill = {
			true,
			color = white,
			opacity = 1
		},
		rounded corners = 0pt,
		sep = 8.25pt,
		shadow = false,
	},
	grid = {
		line = {
			color = black,
			opacity = 1,
			width = 0.55pt,
		}, 
		sep = 12.5pt,
	},
	label = {
		color = black,
		sep = 0.35cm},
	arrow = {
		color = black,
		width = 1.2pt,
		halo = true
	},
	line = {
		color = black,
		width = 1.2pt,
		halo = true
	}
}



\pgfgodefineplayer{default-neutral}{
	stone = {
		line = {
			true,
			color = black,
			width = 0.7pt,
			opacity = 1
		},
		fill = {
			true,
			color = gray,
			opacity = 1
		},
		radius = 5.5pt,
		scale = 1,
		shadow = false,
		shine = false,
	},
	move = {
		label = {
			color = black,
			format = arabic
		}
	},
	mark = {
		line = {
			color = black,
			width = 1pt
		},
		fill = {
			true,
			color = gray
		},
		label = {
			color = black
		},
	}
}




\pgfgodefineplayer[from = default-neutral]{default-white}{
	stone = {fill = {color = white}}
}



\pgfgodefineplayer[from = default-neutral]{default-black}{
	stone = {fill = {color = black}},
	move = {
		label = {
			color = white,
			format = arabic,
		}
	},
	mark = {
		line = 	{color = white},
		label = {color = white},
	}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%---------------WAIN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\definecolor{waingoban}{HTML}{402A2D}
\definecolor{waingoban-s}{HTML}{493739}
\definecolor{waingrid}{HTML}{FAE0B2}
\definecolor{wainblack}{HTML}{4B4B4D} %PIEDRA NEGRA
\definecolor{wainshade}{HTML}{E6E7E8}
\definecolor{wainwhite}{HTML}{EFEFEF} %PIEDRA BLANCA



\pgfgodefinegoban[from = default]{wain}{
	background = {
		fill = {
			color = waingoban,
			opacity = 1},
		line = {
			color = waingrid,
			opacity = 1}},
	grid = {
		line = {
			color = waingrid,
			width = 1pt}
		},
	label = {color = waingoban},
	arrow = {color = waingrid},
	line = {color = waingrid}
}





\pgfgodefineplayer[from = default-neutral]{wain-neutral}{
	stone = {
		line = {
			true,
			color = waingrid,
			width = 0.2pt,
			opacity = 1,
		},
		fill = {
			true,
			color = wainblack!50!wainwhite,
			opacity = 1,
		},
		radius = 0.17cm,
		scale = 1,
		shadow = {true, opacity = 0.5, offset = 1pt, angle = -45},
		shine = {true, angle = 45, color = wainshade}
	},
	move = {
		label = {
			color = black,
			format = arabic,
		}
	},
	mark = {
		line = {
			color = waingoban,
			width = 1pt,
		},
		label = {
			color = waingoban,
			format = arabic
		},
	}
}





\pgfgodefineplayer[from = wain-neutral]{wain-white}{
	stone = {
		fill = {
			color = wainwhite
		}
	},
	move = {
		label = {
			color = waingoban
		}
	},
	mark = {
		line = {
			color = waingoban,
		},
		label = {color = waingoban}
	}
}





\pgfgodefineplayer[from = wain-neutral]{wain-black}{
	stone = {
		fill = {
			color = wainblack
		}
	},
	move = {
		label = {
			color = waingrid
		}
	},
	mark = {
		line = {
			color = waingrid,
		},
		label = {color = waingrid}
	}
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%---------------PGFGO
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




\pgfgodefinegoban{pgfgo}{
	background = {
		fill = {
			color = pgfgo,
			opacity = 1},
		line = {
			color = pgfgo!10!black,
			opacity = 1},
		shadow = {true},
		rounded corners = {
			inner = 0pt,
			outer = 2pt
		}},
	grid = {
		line = {
			color = pgfgo!10!black,
			width = 1pt}},
	label = {
		color = black
	},
	arrow = {color = red!80!black},
	line = {color = red!80!black}
}



\pgfgodefineplayer{pgfgo-neutral}{
	stone = {
		line = {
			true,
			color = black,
			width = 0.3pt,
			opacity = 1,
		},
		fill = {
			true,
			color = gray,
			opacity = 1,
		},
		radius = 0.17cm,
		scale = 1,
		shadow = {true, opacity = 0.5, offset = 1pt, angle = -45},
		shine = {true, angle = 45, color = wainshade}
	},
	move = {
		label = {
			color = black,
			format = arabic,
		}
	},
	mark = {
		line = {
			color = black,
			width = 1pt,
		},
		fill = {true, color = gray},
		label = {
			color = black,
			format = arabic
		}
	}
}

\pgfgodefineplayer[from = pgfgo-neutral]{pgfgo-white}{
	stone = {
		fill = {color = wainwhite},
		shine = {color = white}
	},
	move = {
		label = {
			color = black
		}
	},
	mark = {
		line 	= {color = black},
		label = {color = black}
	}
}




\pgfgodefineplayer[from = pgfgo-neutral]{pgfgo-black}{
	stone = {
		fill = {
			color = wainblack
		}
	},
	move = {
		label = {
			color = pgfgo
		}
	},
	mark = {
		line = {
			color = pgfgo,
		},
		label = {color = black}
	}
}





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%PGFGOSMOOTH
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\definecolor{pgfgosmooth-grid}{HTML}{C7A253}

\pgfgodefinegoban[from = pgfgo]{pgfgosmooth}{
	background = {
		line = false,
		rounded corners = {
			inner = 2pt,
			outer = 8pt
		},
		shadow = {true}},
	grid = {
		line = {color = pgfgosmooth-grid}
		}
}




\pgfgodefineplayer[from = pgfgo-neutral]{pgfgosmooth-neutral}{
	stone = {
		line = false,
		radius = 0.19cm,
		shine = {opacity = 0.5}}
}

\pgfgodefineplayer[from = pgfgo-black]{pgfgosmooth-black}{
	stone = {line = false, shine = {opacity = 0.5}}
}
	
\pgfgodefineplayer[from = pgfgo-white]{pgfgosmooth-white}{
	stone = {line = false}	
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%SIMPLE (SIN BORDE, LINEAS FINAS; PARA VISTAS, POR EJEMPLO)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pgfgodefineprofile[from = default]{simple}{
	goban = {
		background = {line = false},
		grid = {line = {width = 0.4pt}},
		arrow = {width = 0.8pt},
		line = {width = 0.6pt}
	},
	all = {stone = {line = {width = 0.5pt}}}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%DRAFT (BLANCO Y NEGRO, RAYADO DONDE HAY RELLENO; PARA IMPRIMIR O FOTOCOPIAR)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pgfgodefineprofile[from = default]{draft}{
	goban = {
		background = {line = false},
		grid = {line = {width = 0.4pt}},
		arrow = {width = 0.6pt},
		line = {width = 0.4pt}
	},
	all = {
		stone = {line = {width = 0.4pt}},
		mark = {
			line = {width = 0.6pt},
			fill = {
				color = white,
				pattern = {name = {Lines[angle = 45, distance = 1.2pt, line width = 0.3pt]}}
			}
		}
	},
	black = {
		stone = {
			fill = {
				color = white,
				pattern = {name = {Lines[angle = 45, distance = 1.5pt, line width = 0.4pt]}, color = black!50}
			}
		},
		move = {label = {color = black}},
		mark = {line = {color = black}, label = {color = black}},
		territory = {
			fill = {
				color = none,
				pattern = {name = {Lines[angle = 45, distance = 2pt, line width = 0.4pt]}, color = black!50}
			}
		}
	},
	white = {
		territory = {
			fill = {
				color = none,
				pattern = {name = {Lines[angle = -45, distance = 2pt, line width = 0.4pt]}, color = black!50}
			}
		}
	}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%SHELL (MADERA, PIZARRA Y CONCHA, CON IMAGENES; LOS ARCHIVOS ESTAN JUNTO A pgf-go.sty)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pgfgodefineprofile[from = default]{shell}{
	goban = {
		background = {
			line = false,
			fill = {image = {file = pgfgo-board.jpg}}
		},
		arrow = {halo = false},
		line = {halo = false}
	},
	all = {
		stone = {
			shadow = {
				true,
				angle = -45,
				offset = 0.75pt,
				scale = 1.2,
				opacity = 0.6,
				image = {file = pgfgo-shadow.png}
			}
		}
	},
	black = {stone = {image = {file = pgfgo-shell-black.png}}},
	white = {
		stone = {
			image = {
				file = {pgfgo-shell-white-1.png, pgfgo-shell-white-2.png, pgfgo-shell-white-3.png,
					pgfgo-shell-white-4.png, pgfgo-shell-white-5.png},
				rotate = -15:15
			}
		}
	}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%YUNZI (MADERA Y PIEDRAS MATES, CON IMAGENES; LOS ARCHIVOS ESTAN JUNTO A pgf-go.sty)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pgfgodefineprofile[from = shell]{yunzi}{
	black = {stone = {image = {file = pgfgo-yunzi-black.png}}},
	white = {
		stone = {
			image = {
				file = {pgfgo-yunzi-white-1.png, pgfgo-yunzi-white-2.png},
				rotate = 0
			}
		}
	}
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%BADUK TV
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\pgfgodefineprofile[from = default]{baduktv}{
	goban = {
		background = {
			line = false,
			fill = {image = {file = pgfgo-baduktv-goban.png}}
		},
		arrow = {halo = false},
		line = {halo = false}
	},
	all = {
		stone = {
			shadow = {
				true,
				angle = -45,
				offset = 0.75pt,
				scale = 1.2,
				opacity = 0.6,
				image = {file = pgfgo-shadow.png}
			}
		}
	},
	black = {stone = {image = {file = pgfgo-baduktv-black.png}}},
	white = {stone = {image = {file = pgfgo-baduktv-white.png}}}
}