| 1 | /* |
| 2 | This Software is distributed with the following X11 License, |
| 3 | sometimes also known as MIT license. |
| 4 | |
| 5 | Copyright (c) 2010 Miguel A. Ballicora |
| 6 | |
| 7 | Permission is hereby granted, free of charge, to any person |
| 8 | obtaining a copy of this software and associated documentation |
| 9 | files (the "Software"), to deal in the Software without |
| 10 | restriction, including without limitation the rights to use, |
| 11 | copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | copies of the Software, and to permit persons to whom the |
| 13 | Software is furnished to do so, subject to the following |
| 14 | conditions: |
| 15 | |
| 16 | The above copyright notice and this permission notice shall be |
| 17 | included in all copies or substantial portions of the Software. |
| 18 | |
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 21 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 23 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 24 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 25 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 26 | OTHER DEALINGS IN THE SOFTWARE. |
| 27 | */ |
| 28 | |
| 29 | #include <stdlib.h> |
| 30 | #include <stdio.h> |
| 31 | #include "gtb-att.h"cxx . . $ `<file>/gtb-att.h`/ |
| 32 | |
| 33 | #if 0 |
| 34 | |
| 35 | #include "mtypes.h" |
| 36 | #include "bool_t.h" |
| 37 | #include "maindef.h" |
| 38 | |
| 39 | #else |
| 40 | |
| 41 | /* mtypes.h */ |
| 42 | |
| 43 | typedef unsigned int SQUAREcxx . . $ SQUARE#; |
| 44 | typedef unsigned char SQ_CONTENTcxx . . $ SQ_CONTENT#; |
| 45 | |
| 46 | /* bool_t.h */ |
| 47 | |
| 48 | #if !defined(bool_t) |
| 49 | typedef int bool_tcxx . . $ bool_t#; |
| 50 | #endif |
| 51 | |
| 52 | #if !defined(TRUE) |
| 53 | #define TRUEcxx . . $ `gtb-att.c:53:9`! ((bool_t)1) |
| 54 | #endif |
| 55 | |
| 56 | #if !defined(FALSE) |
| 57 | #define FALSEcxx . . $ `gtb-att.c:57:9`! ((bool_t)0) |
| 58 | #endif |
| 59 | |
| 60 | /* maindef.h */ |
| 61 | |
| 62 | #define NOPIECEcxx . . $ `gtb-att.c:62:9`! 0u |
| 63 | #define PAWNcxx . . $ `gtb-att.c:63:9`! 1u |
| 64 | #define KNIGHTcxx . . $ `gtb-att.c:64:9`! 2u |
| 65 | #define BISHOPcxx . . $ `gtb-att.c:65:9`! 3u |
| 66 | #define ROOKcxx . . $ `gtb-att.c:66:9`! 4u |
| 67 | #define QUEENcxx . . $ `gtb-att.c:67:9`! 5u |
| 68 | #define KINGcxx . . $ `gtb-att.c:68:9`! 6u |
| 69 | #define PIECE_MASKcxx . . $ `gtb-att.c:69:9`! (KING|PAWN|KNIGHT|BISHOP|ROOK|QUEEN) |
| 70 | |
| 71 | /*Whites*/ |
| 72 | #define wKcxx . . $ `gtb-att.c:72:9`! (KINGcxx . . $ `gtb-att.c:68:9`! | WHITEScxx . . $ `gtb-att.c:89:9`!) |
| 73 | #define wPcxx . . $ `gtb-att.c:73:9`! (PAWNcxx . . $ `gtb-att.c:63:9`! | WHITEScxx . . $ `gtb-att.c:89:9`!) |
| 74 | #define wNcxx . . $ `gtb-att.c:74:9`! (KNIGHTcxx . . $ `gtb-att.c:64:9`! | WHITEScxx . . $ `gtb-att.c:89:9`!) |
| 75 | #define wBcxx . . $ `gtb-att.c:75:9`! (BISHOPcxx . . $ `gtb-att.c:65:9`! | WHITEScxx . . $ `gtb-att.c:89:9`!) |
| 76 | #define wRcxx . . $ `gtb-att.c:76:9`! (ROOKcxx . . $ `gtb-att.c:66:9`! | WHITEScxx . . $ `gtb-att.c:89:9`!) |
| 77 | #define wQcxx . . $ `gtb-att.c:77:9`! (QUEENcxx . . $ `gtb-att.c:67:9`! | WHITEScxx . . $ `gtb-att.c:89:9`!) |
| 78 | |
| 79 | /*Blacks*/ |
| 80 | #define bKcxx . . $ `gtb-att.c:80:9`! (KINGcxx . . $ `gtb-att.c:68:9`! | BLACKScxx . . $ `gtb-att.c:90:9`!) |
| 81 | #define bPcxx . . $ `gtb-att.c:81:9`! (PAWNcxx . . $ `gtb-att.c:63:9`! | BLACKScxx . . $ `gtb-att.c:90:9`!) |
| 82 | #define bNcxx . . $ `gtb-att.c:82:9`! (KNIGHTcxx . . $ `gtb-att.c:64:9`! | BLACKScxx . . $ `gtb-att.c:90:9`!) |
| 83 | #define bBcxx . . $ `gtb-att.c:83:9`! (BISHOPcxx . . $ `gtb-att.c:65:9`! | BLACKScxx . . $ `gtb-att.c:90:9`!) |
| 84 | #define bRcxx . . $ `gtb-att.c:84:9`! (ROOKcxx . . $ `gtb-att.c:66:9`! | BLACKScxx . . $ `gtb-att.c:90:9`!) |
| 85 | #define bQcxx . . $ `gtb-att.c:85:9`! (QUEENcxx . . $ `gtb-att.c:67:9`! | BLACKScxx . . $ `gtb-att.c:90:9`!) |
| 86 | |
| 87 | /*Bits that define color */ |
| 88 | |
| 89 | #define WHITEScxx . . $ `gtb-att.c:89:9`! (1u<<6) |
| 90 | #define BLACKScxx . . $ `gtb-att.c:90:9`! (1u<<7) |
| 91 | |
| 92 | /*squares*/ |
| 93 | enum SQUAREScxx . . $ SQUARES# { |
| 94 | A1cxx . . $ A1.,B1cxx . . $ B1.,C1cxx . . $ C1.,D1cxx . . $ D1.,E1cxx . . $ E1.,F1cxx . . $ F1.,G1cxx . . $ G1.,H1cxx . . $ H1., |
| 95 | A2cxx . . $ A2.,B2cxx . . $ B2.,C2cxx . . $ C2.,D2cxx . . $ D2.,E2cxx . . $ E2.,F2cxx . . $ F2.,G2cxx . . $ G2.,H2cxx . . $ H2., |
| 96 | A3cxx . . $ A3.,B3cxx . . $ B3.,C3cxx . . $ C3.,D3cxx . . $ D3.,E3cxx . . $ E3.,F3cxx . . $ F3.,G3cxx . . $ G3.,H3cxx . . $ H3., |
| 97 | A4cxx . . $ A4.,B4cxx . . $ B4.,C4cxx . . $ C4.,D4cxx . . $ D4.,E4cxx . . $ E4.,F4cxx . . $ F4.,G4cxx . . $ G4.,H4cxx . . $ H4., |
| 98 | A5cxx . . $ A5.,B5cxx . . $ B5.,C5cxx . . $ C5.,D5cxx . . $ D5.,E5cxx . . $ E5.,F5cxx . . $ F5.,G5cxx . . $ G5.,H5cxx . . $ H5., |
| 99 | A6cxx . . $ A6.,B6cxx . . $ B6.,C6cxx . . $ C6.,D6cxx . . $ D6.,E6cxx . . $ E6.,F6cxx . . $ F6.,G6cxx . . $ G6.,H6cxx . . $ H6., |
| 100 | A7cxx . . $ A7.,B7cxx . . $ B7.,C7cxx . . $ C7.,D7cxx . . $ D7.,E7cxx . . $ E7.,F7cxx . . $ F7.,G7cxx . . $ G7.,H7cxx . . $ H7., |
| 101 | A8cxx . . $ A8.,B8cxx . . $ B8.,C8cxx . . $ C8.,D8cxx . . $ D8.,E8cxx . . $ E8.,F8cxx . . $ F8.,G8cxx . . $ G8.,H8cxx . . $ H8., |
| 102 | NOSQUAREcxx . . $ NOSQUARE., |
| 103 | ERRSQUAREcxx . . $ ERRSQUARE. = 128 |
| 104 | }; |
| 105 | #endif |
| 106 | |
| 107 | /*----------------------------------------------------------------------*/ |
| 108 | |
| 109 | #ifndef NDEBUG |
| 110 | #define NDEBUGcxx . . $ `gtb-att.c:110:9`! |
| 111 | #endif |
| 112 | #ifdef DEBUG |
| 113 | #undef NDEBUG |
| 114 | #endif |
| 115 | #include "assert.h" |
| 116 | |
| 117 | /*----------------------------------------------------------------------*/ |
| 118 | |
| 119 | /* global variables */ |
| 120 | uint64_tcxx . . $ uint64_t# Reachcxx . . $ Reach. [7] [64]; |
| 121 | |
| 122 | /* static variables */ |
| 123 | static unsigned char attmapcxx . . $ attmap. [64] [64]; |
| 124 | static unsigned int attmskcxx . . $ attmsk. [256]; |
| 125 | |
| 126 | /* static functions */ |
| 127 | static unsigned int mapx88cxx . . $ mapx88(2141b656ce2cc063). (unsigned int x); |
| 128 | |
| 129 | /* macros */ |
| 130 | #define BB_ISBITONcxx . . $ `gtb-att.c:130:9`!(bb,bit) (0 != (((bb)>>(bit)) & U64cxx . . $ `sysport/sysport.h:80:10`!(1))) |
| 131 | |
| 132 | #define map88cxx . . $ `gtb-att.c:132:9`!(x) ( (x) + ((x)&070) ) |
| 133 | #define unmap88cxx . . $ `gtb-att.c:133:9`!(x) ( ( (x) + ((x)& 07) ) >> 1 ) |
| 134 | |
| 135 | /*----------------------------------------------------------------------*/ |
| 136 | |
| 137 | static unsigned int |
| 138 | mapx88cxx . . $ mapx88(2141b656ce2cc063). (unsigned int x) |
| 139 | { |
| 140 | return ((x & 070) << 1) | (x & 07); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | void |
| 145 | attack_maps_initcxx . . $ attack_maps_init(49f6e7a06ebc5aa8).(void) |
| 146 | { |
| 147 | int i; |
| 148 | unsigned int m, from, to; |
| 149 | unsigned int to88, fr88; |
| 150 | int diff; |
| 151 | |
| 152 | uint64_tcxx . . $ uint64_t# rook, bishop, queen, knight, king; |
| 153 | |
| 154 | if (!reach_was_initializedcxx . . $ reach_was_initialized(b126dc7c1de90089).()) { |
| 155 | printfcxx . . $ printf(581fddd72a8db8fc). ("Wrong initialization order of data\n"); |
| 156 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!); |
| 157 | } |
| 158 | |
| 159 | for (i = 0; i < 256; ++i) { |
| 160 | attmskcxx . . $ attmsk. [i] = 0; |
| 161 | } |
| 162 | attmskcxx . . $ attmsk.[wPcxx . . $ `gtb-att.c:73:9`!] = 1 << 0; |
| 163 | attmskcxx . . $ attmsk.[bPcxx . . $ `gtb-att.c:81:9`!] = 1 << 1; |
| 164 | |
| 165 | attmskcxx . . $ attmsk.[KNIGHTcxx . . $ `gtb-att.c:64:9`!] = 1 << 2; |
| 166 | attmskcxx . . $ attmsk.[wNcxx . . $ `gtb-att.c:74:9`!] = 1 << 2; |
| 167 | attmskcxx . . $ attmsk.[bNcxx . . $ `gtb-att.c:82:9`!] = 1 << 2; |
| 168 | |
| 169 | attmskcxx . . $ attmsk.[BISHOPcxx . . $ `gtb-att.c:65:9`!] = 1 << 3; |
| 170 | attmskcxx . . $ attmsk.[wBcxx . . $ `gtb-att.c:75:9`!] = 1 << 3; |
| 171 | attmskcxx . . $ attmsk.[bBcxx . . $ `gtb-att.c:83:9`!] = 1 << 3; |
| 172 | |
| 173 | attmskcxx . . $ attmsk.[ROOKcxx . . $ `gtb-att.c:66:9`! ] = 1 << 4; |
| 174 | attmskcxx . . $ attmsk.[wRcxx . . $ `gtb-att.c:76:9`!] = 1 << 4; |
| 175 | attmskcxx . . $ attmsk.[bRcxx . . $ `gtb-att.c:84:9`!] = 1 << 4; |
| 176 | |
| 177 | attmskcxx . . $ attmsk.[QUEENcxx . . $ `gtb-att.c:67:9`! ] = 1 << 5; |
| 178 | attmskcxx . . $ attmsk.[wQcxx . . $ `gtb-att.c:77:9`!] = 1 << 5; |
| 179 | attmskcxx . . $ attmsk.[bQcxx . . $ `gtb-att.c:85:9`!] = 1 << 5; |
| 180 | |
| 181 | attmskcxx . . $ attmsk.[KINGcxx . . $ `gtb-att.c:68:9`! ] = 1 << 6; |
| 182 | attmskcxx . . $ attmsk.[wKcxx . . $ `gtb-att.c:72:9`!] = 1 << 6; |
| 183 | attmskcxx . . $ attmsk.[bKcxx . . $ `gtb-att.c:80:9`!] = 1 << 6; |
| 184 | |
| 185 | for (to = 0; to < 64; ++to) { |
| 186 | for (from = 0; from < 64; ++from) { |
| 187 | m = 0; |
| 188 | rook = Reachcxx . . $ Reach. [ROOKcxx . . $ `gtb-att.c:66:9`!] [from]; |
| 189 | bishop = Reachcxx . . $ Reach. [BISHOPcxx . . $ `gtb-att.c:65:9`!] [from]; |
| 190 | queen = Reachcxx . . $ Reach. [QUEENcxx . . $ `gtb-att.c:67:9`!] [from]; |
| 191 | knight = Reachcxx . . $ Reach. [KNIGHTcxx . . $ `gtb-att.c:64:9`!] [from]; |
| 192 | king = Reachcxx . . $ Reach. [KINGcxx . . $ `gtb-att.c:68:9`!] [from]; |
| 193 | |
| 194 | if (BB_ISBITONcxx . . $ `gtb-att.c:130:9`! (knight, to)) { |
| 195 | m |= attmskcxx . . $ attmsk.[wNcxx . . $ `gtb-att.c:74:9`!]; |
| 196 | } |
| 197 | if (BB_ISBITONcxx . . $ `gtb-att.c:130:9`! (king, to)) { |
| 198 | m |= attmskcxx . . $ attmsk.[wKcxx . . $ `gtb-att.c:72:9`!]; |
| 199 | } |
| 200 | if (BB_ISBITONcxx . . $ `gtb-att.c:130:9`! (rook, to)) { |
| 201 | m |= attmskcxx . . $ attmsk.[wRcxx . . $ `gtb-att.c:76:9`!]; |
| 202 | } |
| 203 | if (BB_ISBITONcxx . . $ `gtb-att.c:130:9`! (bishop, to)) { |
| 204 | m |= attmskcxx . . $ attmsk.[wBcxx . . $ `gtb-att.c:75:9`!]; |
| 205 | } |
| 206 | if (BB_ISBITONcxx . . $ `gtb-att.c:130:9`! (queen, to)) { |
| 207 | m |= attmskcxx . . $ attmsk.[wQcxx . . $ `gtb-att.c:77:9`!]; |
| 208 | } |
| 209 | |
| 210 | to88 = mapx88cxx . . $ mapx88(2141b656ce2cc063).(to); |
| 211 | fr88 = mapx88cxx . . $ mapx88(2141b656ce2cc063).(from); |
| 212 | diff = (int)to88 - (int)fr88; |
| 213 | |
| 214 | if (diff == 17 || diff == 15) { |
| 215 | m |= attmskcxx . . $ attmsk.[wPcxx . . $ `gtb-att.c:73:9`!]; |
| 216 | } |
| 217 | if (diff == -17 || diff == -15) { |
| 218 | m |= attmskcxx . . $ attmsk.[bPcxx . . $ `gtb-att.c:81:9`!]; |
| 219 | } |
| 220 | |
| 221 | attmapcxx . . $ attmap. [to] [from] = (unsigned char) m; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | } |
| 226 | |
| 227 | bool_tcxx . . $ bool_t# |
| 228 | possible_attackcxx . . $ possible_attack(64d4c609941711dd).(unsigned int from, unsigned int to, unsigned int piece) |
| 229 | { |
| 230 | |
| 231 | assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`! (piece < 256); |
| 232 | assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`! (from < 64 && to < 64); |
| 233 | assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`! (reach_was_initialized()); |
| 234 | assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`! (attmsk [piece] != 0 || 0==fprintf(stderr, "PIECE=%d\n",piece) ); /* means piece has been considered */ |
| 235 | |
| 236 | return 0 != (attmapcxx . . $ attmap. [to] [from] & attmskcxx . . $ attmsk. [piece]); |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | | |
| 241 | | REACH ROUTINES |
| 242 | | |
| 243 | \*----------------------------------------------*/ |
| 244 | |
| 245 | |
| 246 | enum Keycxx . . $ Key# {REACH_INITIALIZED_KEYcxx . . $ REACH_INITIALIZED_KEY. = 0x1313}; |
| 247 | static int reach_initialized_keycxx . . $ reach_initialized_key. = 0; |
| 248 | |
| 249 | bool_tcxx . . $ bool_t# |
| 250 | reach_was_initializedcxx . . $ reach_was_initialized(b126dc7c1de90089). (void) |
| 251 | { |
| 252 | return reach_initialized_keycxx . . $ reach_initialized_key. == REACH_INITIALIZED_KEYcxx . . $ REACH_INITIALIZED_KEY.; |
| 253 | } |
| 254 | |
| 255 | void |
| 256 | reach_initcxx . . $ reach_init(49f6e7a06ebc5aa8). (void) |
| 257 | { |
| 258 | SQUAREcxx . . $ SQUARE# buflist[64+1], *list; |
| 259 | SQ_CONTENTcxx . . $ SQ_CONTENT# pc; |
| 260 | int stp_a [] = {15, -15 }; |
| 261 | int stp_b [] = {17, -17 }; |
| 262 | int STEP_A, STEP_B; |
| 263 | unsigned int side; |
| 264 | unsigned int index; |
| 265 | SQUAREcxx . . $ SQUARE# sq, us; |
| 266 | |
| 267 | int s; |
| 268 | |
| 269 | for (pc = KNIGHTcxx . . $ `gtb-att.c:64:9`!; pc < (KINGcxx . . $ `gtb-att.c:68:9`!+1); pc++) { |
| 270 | for (sq = 0; sq < 64; sq++) { |
| 271 | uint64_tcxx . . $ uint64_t# bb = U64cxx . . $ `sysport/sysport.h:80:10`!(0x0); |
| 272 | tolist_revcxx . . $ tolist_rev(7266cd2c7918b75e). (U64cxx . . $ `sysport/sysport.h:80:10`!(0x0), pc, sq, buflist); |
| 273 | for (list = buflist; *list != NOSQUAREcxx . . $ NOSQUARE.; list++) { |
| 274 | bb |= U64cxx . . $ `sysport/sysport.h:80:10`!(1) << *list; |
| 275 | } |
| 276 | Reachcxx . . $ Reach. [pc] [sq] = bb; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | for (side = 0; side < 2; side++) { |
| 281 | index = 1u ^ side; |
| 282 | STEP_A = stp_a[side]; |
| 283 | STEP_B = stp_b[side]; |
| 284 | for (sq = 0; sq < 64; sq++) { |
| 285 | |
| 286 | int sq88 = (int)map88cxx . . $ `gtb-att.c:132:9`!(sq); |
| 287 | uint64_tcxx . . $ uint64_t# bb = U64cxx . . $ `sysport/sysport.h:80:10`!(0x0); |
| 288 | |
| 289 | list = buflist; |
| 290 | |
| 291 | |
| 292 | s = sq88 + STEP_A; |
| 293 | if (0 == (s & 0x88)) { |
| 294 | us = (SQUAREcxx . . $ SQUARE#)unmap88cxx . . $ `gtb-att.c:133:9`!(s); |
| 295 | *list++ = us; |
| 296 | } |
| 297 | s = sq88 + STEP_B; |
| 298 | if (0 == (s & 0x88)) { |
| 299 | us = (SQUAREcxx . . $ SQUARE#)unmap88cxx . . $ `gtb-att.c:133:9`!(s); |
| 300 | *list++ = us; |
| 301 | } |
| 302 | *list = NOSQUAREcxx . . $ NOSQUARE.; |
| 303 | |
| 304 | for (list = buflist; *list != NOSQUAREcxx . . $ NOSQUARE.; list++) { |
| 305 | bb |= U64cxx . . $ `sysport/sysport.h:80:10`!(1) << *list; |
| 306 | } |
| 307 | Reachcxx . . $ Reach. [index] [sq] = bb; |
| 308 | } |
| 309 | } |
| 310 | reach_initialized_keycxx . . $ reach_initialized_key. = REACH_INITIALIZED_KEYcxx . . $ REACH_INITIALIZED_KEY.; |
| 311 | } |
| 312 | |
| 313 | /*--------------------------------------------------------------------------------*/ |
| 314 | |
| 315 | static const int bstepcxx . . $ bstep.[] = { 17, 15, -15, -17, 0}; |
| 316 | static const int rstepcxx . . $ rstep.[] = { 1, 16, -1, -16, 0}; |
| 317 | static const int nstepcxx . . $ nstep.[] = { 18, 33, 31, 14, -18, -33, -31, -14, 0}; |
| 318 | static const int kstepcxx . . $ kstep.[] = { 1, 17, 16, 15, -1, -17, -16, -15, 0}; |
| 319 | |
| 320 | static const |
| 321 | int *psteparrcxx . . $ psteparr.[] = {NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, /* NOPIECE & PAWN */ |
| 322 | nstepcxx . . $ nstep., bstepcxx . . $ bstep., rstepcxx . . $ rstep., kstepcxx . . $ kstep., kstepcxx . . $ kstep. /* same for Q & K*/ |
| 323 | }; |
| 324 | static const |
| 325 | int pslidercxx . . $ pslider.[] = {FALSEcxx . . $ `gtb-att.c:57:9`!, FALSEcxx . . $ `gtb-att.c:57:9`!, |
| 326 | FALSEcxx . . $ `gtb-att.c:57:9`!, TRUEcxx . . $ `gtb-att.c:53:9`!, TRUEcxx . . $ `gtb-att.c:53:9`!, TRUEcxx . . $ `gtb-att.c:53:9`!, FALSEcxx . . $ `gtb-att.c:57:9`! |
| 327 | }; |
| 328 | |
| 329 | void |
| 330 | tolist_revcxx . . $ tolist_rev(7266cd2c7918b75e). (uint64_tcxx . . $ uint64_t# occ, SQ_CONTENTcxx . . $ SQ_CONTENT# input_piece, SQUAREcxx . . $ SQUARE# sq, SQUAREcxx . . $ SQUARE# *list) |
| 331 | /* reversible moves from pieces. Output is a list of squares */ |
| 332 | { |
| 333 | int direction; |
| 334 | unsigned int pc; |
| 335 | int s; |
| 336 | int from; |
| 337 | int step; |
| 338 | const int *steparr; |
| 339 | bool_tcxx . . $ bool_t# slider; |
| 340 | SQUAREcxx . . $ SQUARE# us; |
| 341 | |
| 342 | assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`! (sq < 64); |
| 343 | |
| 344 | /* i.e. no pawn allowed as input */ |
| 345 | assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`! (input_piece == KNIGHT || input_piece == BISHOP || |
| 346 | input_piece == ROOK || input_piece == QUEEN || |
| 347 | input_piece == KING); |
| 348 | |
| 349 | from = (int)map88cxx . . $ `gtb-att.c:132:9`!(sq); |
| 350 | |
| 351 | pc = input_piece & (PAWNcxx . . $ `gtb-att.c:63:9`!|KNIGHTcxx . . $ `gtb-att.c:64:9`!|BISHOPcxx . . $ `gtb-att.c:65:9`!|ROOKcxx . . $ `gtb-att.c:66:9`!|QUEENcxx . . $ `gtb-att.c:67:9`!|KINGcxx . . $ `gtb-att.c:68:9`!); |
| 352 | |
| 353 | steparr = psteparrcxx . . $ psteparr. [pc]; |
| 354 | slider = pslidercxx . . $ pslider. [pc]; |
| 355 | |
| 356 | if (slider) { |
| 357 | |
| 358 | for (direction = 0; steparr[direction] != 0; direction++) { |
| 359 | step = steparr[direction]; |
| 360 | s = from + step; |
| 361 | while (0 == (s & 0x88)) { |
| 362 | us = (SQUAREcxx . . $ SQUARE#)unmap88cxx . . $ `gtb-att.c:133:9`!(s); |
| 363 | if (0 != (0x1u & (unsigned int)(occ >> us))) |
| 364 | break; |
| 365 | *list++ = us; |
| 366 | s += step; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | } else { |
| 371 | |
| 372 | for (direction = 0; steparr[direction] != 0; direction++) { |
| 373 | step = steparr[direction]; |
| 374 | s = from + step; |
| 375 | if (0 == (s & 0x88)) { |
| 376 | us = (SQUAREcxx . . $ SQUARE#)unmap88cxx . . $ `gtb-att.c:133:9`!(s); |
| 377 | if (0 == (0x1u & (unsigned int)(occ >> us))) { |
| 378 | *list++ = us; |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | *list = NOSQUAREcxx . . $ NOSQUARE.; |
| 385 | |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | |
| 390 |