Plisco/Macro/movePinned.pm untested

filter: Statementstmt 0.0% 0 / 13 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 29 SCAR -
1 #! /bin/false
2  
3 # Copyright (C) 2021-2026 Guido Flohr <guido.flohr@cantanea.com>,
4 # all rights reserved.
5  
6 # This program is free software. It comes without any warranty, to
7 # the extent permitted by applicable law. You can redistribute it
8 # and/or modify it under the terms of the Do What the Fuck You Want
9 # to Public License, Version 2, as published by Sam Hocevar. See
10 # http://www.wtfpl.net/ for more details.
11  
12 # This is a macro that is not intended to run standalone.
13  
14 ## no critic (TestingAndDebugging::RequireUseStrict)
15  
16 ( do {
17 my $pinned;
18  
19 # If the piece to move is on a common line with the king, it may be pinned.
20 my $king_ray = $common_lines[$from]->[$ks];
21 if ($king_ray) {
22 my ($is_rook, $ray_mask) = @$king_ray;
23  
24 # If the destination square is on the same line, the piece cannot be
25 # pinned. That also covers the case that the piece that moves captures
26 # the piece that pins.
27 if (!((1 << $to) & $ray_mask)) {
28 if ($is_rook) {
29 my $rmagic = cp_mm_rmagic($from, ($mp | $hp)) & $ray_mask;
30 $pinned = ($rmagic & (1 << $ks))
31 && ($rmagic & $hp
32 & (cp_pos_queens($p) | cp_pos_rooks($p)));
33 } else {
34 my $bmagic = cp_mm_bmagic($from, ($mp | $hp)) & $ray_mask;
35 $pinned = ($bmagic & (1 << $ks))
36 && ($bmagic & $hp
37 & (cp_pos_queens($p) | cp_pos_bishops($p)));
38 }
39 }
40 }
41  
42 $pinned;
43 })