$pval{join'',@{$prop{$_}}}='1';# Instead of skipping if the allied king is taken in a branch, we can assign infinite value to the king. That doesn't work well with premature calculations, though, so we assign it (more than) the combined value of all other allied pieces at this point.
# if (exists($prop{$_})) {$default_iboard[$y][$x] = join '', @{$prop{$_}}}
# if (exists($prop{$_})) {$default_iboard[$y][$x]{'isPiece'} = 1; $default_iboard[$y][$x]{'value'} = join '', @{$prop{$_}}; $default_iboard[$y][$x]{'prettyName'} = join ' ', $pplayer[$prop{$_}[0]], $ppiece{$prop{$_}[1]}} else {$default_iboard[$y][$x]{'isPiece'} = 0; $default_iboard[$y][$x]{'value'} = undef}; # HoA for Template Toolkit.
$default_iboard[$y][$x]{'isPiece'}=1;$default_iboard[$y][$x]{'id'}=join'',@{$prop{$_}};$default_iboard[$y][$x]{'img'}=join'',@{$prop{$_}}[0..1];$default_iboard[$y][$x]{'prettyName'}=join' ',$pplayer[$prop{$_}[0]],$ppiece{$prop{$_}[1]};# HoA for Template Toolkit.
my%diff=&PROGRAM(route_parameters->get('src'),route_parameters->get('dst'),session);# Includes player input.
encode_json(\%diff);
}
#}
};
any['get','post']=>'/'=>sub{
my$session=session;# TODO: I only want %{session}{'id'}.
$session=%{$session}{'id'};
$sth11->execute($session);
print$session,"\n";
my@sth11=$sth11->fetchrow_array();
print$#sth11,"\n";
if(session('init')ordefined($sth11[0])){
if(request->method()eq"POST"){
if(length(body_parameters->get('id'))==1andbody_parameters->get('id')=~m/\A[1-7]\z/){# Sanitize user input (even if in a session).
my$setting_id=body_parameters->get('id');
redirect'/aaaaa';
}
}else{
# $sth8->execute($session); # TODO: The column name in the hash is without the table name, even if the SQL query includes table names for tables with the same column name (resulting in silently overwritten keys). Workaround with multiple queries.
$sth8->execute($sth11[1]);
$sth9->execute($sth11[0]);
# &INIT_BOARD($sth8->fetchrow_hashref(), $sth9->fetchrow_hashref()); # Complains about attempted modification of RO-value when a piece takes an enemy piece.
my$r1=$sth8->fetchrow_hashref();
my$r2=$sth9->fetchrow_hashref();
&INIT_BOARD($r1,$r2);
# $sth8->execute($session);
# my $hr = $sth8->fetchrow_hashref();
# &INIT_BOARD($hr);
template'index'=>{board=>\@session_iboard};
}
}elsif(request->method()eq"GET"){
session'init'=>true;
#$jar->add_cookie_header($session);
template'index'=>{board=>\@default_iboard};
}
get'/'=>sub{
send_file'/index.html';
};
#any ['get', 'post'] => '/' => sub {
# my $session = session; # TODO: I only want %{session}{'id'}.
# $session = %{$session}{'id'};
# $sth11->execute($session);
#print $session, "\n";
# my @sth11 = $sth11->fetchrow_array();
#print $#sth11, "\n";
# if (session('init') or defined($sth11[0])) {
# if (request->method() eq "POST") {
# if (length(body_parameters->get('id')) == 1 and body_parameters->get('id') =~ m/\A[1-7]\z/) { # Sanitize user input (even if in a session).
# my $setting_id = body_parameters->get('id');
# redirect '/aaaaa';
# }
# } else {
## $sth8->execute($session); # TODO: The column name in the hash is without the table name, even if the SQL query includes table names for tables with the same column name (resulting in silently overwritten keys). Workaround with multiple queries.
# $sth8->execute($sth11[1]);
# $sth9->execute($sth11[0]);
## &INIT_BOARD($sth8->fetchrow_hashref(), $sth9->fetchrow_hashref()); # Complains about attempted modification of RO-value when a piece takes an enemy piece.
<olid="y-co"><olid="x-co"><liclass="x-co">A</li><liclass="x-co">B</li><liclass="x-co">C</li><liclass="x-co">D</li><liclass="x-co">E</li><liclass="x-co">F</li><liclass="x-co">G</li><liclass="x-co">H</li></ol>[% FOREACH row IN board %]<li><ol>[% FOREACH object IN row %][% IF object.isPiece %]<liid="[% GET object.pco %]"class="coord piece"><imgid="[% GET object.id %]"src="i/[% GET object.img %].png"alt="[% GET object.prettyName %] on [% GET object.pco %]"width="32px"></li>[% ELSE %]<liid="[% GET object.pco %]"class="coord empty"></li>[% END %][% END %]</ol></li>[% END %]
<olid="y-co"></ol>
<!-- [% FOREACH row IN board %]<li><ol>[% FOREACH object IN row %][% IF object.isPiece %]<li id="[% GET object.pco %]" class="coord piece"><img id="[% GET object.id %]" src="i/[% GET object.img %].png" alt="[% GET object.prettyName %] on [% GET object.pco %]" width="32px"></li>[% ELSE %]<li id="[% GET object.pco %]" class="coord empty"></li>[% END %][% END %]</ol></li>[% END %] -->