All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netsensia.rivalchess.bitboards.BitboardConstants.kt Maven / Gradle / Ivy

There is a newer version: 36.0.0
Show newest version
package com.netsensia.rivalchess.bitboards

const val RANK_8 = -0x100000000000000L
const val RANK_7 = 0x00FF000000000000L
const val RANK_6 = 0x0000FF0000000000L
const val RANK_5 = 0x000000FF00000000L
const val RANK_4 = 0x00000000FF000000L
const val RANK_3 = 0x0000000000FF0000L
const val RANK_2 = 0x000000000000FF00L
const val RANK_1 = 0x00000000000000FFL

const val FILE_A = 1L shl 7 or (1L shl 15) or (1L shl 23) or (1L shl 31) or (1L shl 39) or (1L shl 47) or (1L shl 55) or (1L shl 63)
const val FILE_B = 1L shl 6 or (1L shl 14) or (1L shl 22) or (1L shl 30) or (1L shl 38) or (1L shl 46) or (1L shl 54) or (1L shl 62)
const val FILE_C = 1L shl 5 or (1L shl 13) or (1L shl 21) or (1L shl 29) or (1L shl 37) or (1L shl 45) or (1L shl 53) or (1L shl 61)
const val FILE_D = 1L shl 4 or (1L shl 12) or (1L shl 20) or (1L shl 28) or (1L shl 36) or (1L shl 44) or (1L shl 52) or (1L shl 60)
const val FILE_E = 1L shl 3 or (1L shl 11) or (1L shl 19) or (1L shl 27) or (1L shl 35) or (1L shl 43) or (1L shl 51) or (1L shl 59)
const val FILE_F = 1L shl 2 or (1L shl 10) or (1L shl 18) or (1L shl 26) or (1L shl 34) or (1L shl 42) or (1L shl 50) or (1L shl 58)
const val FILE_G = 1L shl 1 or (1L shl 9) or (1L shl 17) or (1L shl 25) or (1L shl 33) or (1L shl 41) or (1L shl 49) or (1L shl 57)
const val FILE_H = 1L or (1L shl 8) or (1L shl 16) or (1L shl 24) or (1L shl 32) or (1L shl 40) or (1L shl 48) or (1L shl 56)

const val MIDDLE_FILES_8_BIT: Long = 0xE7
const val NONMID_FILES_8_BIT: Long = 0x18

const val F1G1 = 1L shl 1 or (1L shl 2)
const val G1H1 = 1L or (1L shl 1)
const val A1B1 = 1L shl 7 or (1L shl 6)
const val B1C1 = 1L shl 6 or (1L shl 5)
const val F8G8 = 1L shl 58 or (1L shl 57)
const val G8H8 = 1L shl 57 or (1L shl 56)
const val A8B8 = 1L shl 63 or (1L shl 62)
const val B8C8 = 1L shl 62 or (1L shl 61)

val FILES = longArrayOf(FILE_H, FILE_G, FILE_F, FILE_E, FILE_D, FILE_C, FILE_B, FILE_A)

const val LIGHT_SQUARES = -0x55aa55aa55aa55abL
const val DARK_SQUARES = 0x55AA55AA55AA55AAL

const val A1A2B1B2 = 1L shl 7 or (1L shl 6) or (1L shl 15) or (1L shl 14)
const val A8A7B8B7 = 1L shl 63 or (1L shl 62) or (1L shl 55) or (1L shl 54)
const val H8H7G8G7 = 1L shl 57 or (1L shl 56) or (1L shl 49) or (1L shl 48)
const val H1H2G1G2 = 1L or (1L shl 1) or (1L shl 8) or (1L shl 9)
const val A2A7H2H7 = 1L shl 15 or (1L shl 55) or (1L shl 8) or (1L shl 48)

const val LOW32 = 0x00000000FFFFFFFFL

const val WHITEKINGSIDECASTLESQUARES = 1L shl 1 or (1L shl 2)
const val WHITEQUEENSIDECASTLESQUARES = 1L shl 4 or (1L shl 5) or (1L shl 6)
const val BLACKKINGSIDECASTLESQUARES = 1L shl 57 or (1L shl 58)
const val BLACKQUEENSIDECASTLESQUARES = 1L shl 62 or (1L shl 61) or (1L shl 60)

const val WHITEKINGSIDECASTLEMOVEMASK = 1L shl 1 or (1L shl 3)
const val WHITEQUEENSIDECASTLEMOVEMASK = 1L shl 3 or (1L shl 5)
const val BLACKKINGSIDECASTLEMOVEMASK = 1L shl 57 or (1L shl 59)
const val BLACKQUEENSIDECASTLEMOVEMASK = 1L shl 59 or (1L shl 61)

const val WHITEKINGSIDECASTLEROOKMOVE = 1L or (1L shl 2)
const val WHITEQUEENSIDECASTLEROOKMOVE = 1L shl 4 or (1L shl 7)
const val BLACKKINGSIDECASTLEROOKMOVE = 1L shl 56 or (1L shl 58)
const val BLACKQUEENSIDECASTLEROOKMOVE = 1L shl 60 or (1L shl 63)

const val WHITEKINGSIDEROOKMASK = 1L
const val WHITEQUEENSIDEROOKMASK = 1L shl 7
const val BLACKKINGSIDEROOKMASK = 1L shl 56
const val BLACKQUEENSIDEROOKMASK = 1L shl 63

val distanceToH1OrA8 = intArrayOf(
        0, 1, 2, 3, 4, 5, 6, 7,
        1, 2, 3, 4, 5, 6, 7, 6,
        2, 3, 4, 5, 6, 7, 6, 5,
        3, 4, 5, 6, 7, 6, 5, 4,
        4, 5, 6, 7, 6, 5, 4, 3,
        5, 6, 7, 6, 5, 4, 3, 2,
        6, 7, 6, 5, 4, 3, 2, 1,
        7, 6, 5, 4, 3, 2, 1, 0)

val knightMoves = longArrayOf(
        0x20400L,
        0x50800L, 0xa1100L, 0x142200L, 0x284400L, 0x508800L, 0xa01000L, 0x402000L, 0x2040004L,
        0x5080008L, 0xa110011L, 0x14220022L, 0x28440044L, 0x50880088L, 0xa0100010L, 0x40200020L, 0x204000402L,
        0x508000805L, 0xa1100110aL, 0x1422002214L, 0x2844004428L, 0x5088008850L, 0xa0100010a0L, 0x4020002040L, 0x20400040200L,
        0x50800080500L, 0xa1100110a00L, 0x142200221400L, 0x284400442800L, 0x508800885000L, 0xa0100010a000L, 0x402000204000L, 0x2040004020000L,
        0x5080008050000L, 0xa1100110a0000L, 0x14220022140000L, 0x28440044280000L, 0x50880088500000L, 0xa0100010a00000L, 0x40200020400000L, 0x204000402000000L,
        0x508000805000000L, 0xa1100110a000000L, 0x1422002214000000L, 0x2844004428000000L, 0x5088008850000000L, -0x5fefffef60000000L, 0x4020002040000000L, 0x400040200000000L,
        0x800080500000000L, 0x1100110a00000000L, 0x2200221400000000L, 0x4400442800000000L, -0x77ff77b000000000L, 0x100010a000000000L, 0x2000204000000000L, 0x4020000000000L,
        0x8050000000000L, 0x110a0000000000L, 0x22140000000000L, 0x44280000000000L, 0x88500000000000L, 0x10a00000000000L, 0x20400000000000L)

val kingMoves = longArrayOf(
        0x302L,
        0x705L, 0xe0aL, 0x1c14L, 0x3828L, 0x7050L, 0xe0a0L, 0xc040L, 0x30203L,
        0x70507L, 0xe0a0eL, 0x1c141cL, 0x382838L, 0x705070L, 0xe0a0e0L, 0xc040c0L, 0x3020300L,
        0x7050700L, 0xe0a0e00L, 0x1c141c00L, 0x38283800L, 0x70507000L, 0xe0a0e000L, 0xc040c000L, 0x302030000L,
        0x705070000L, 0xe0a0e0000L, 0x1c141c0000L, 0x3828380000L, 0x7050700000L, 0xe0a0e00000L, 0xc040c00000L, 0x30203000000L,
        0x70507000000L, 0xe0a0e000000L, 0x1c141c000000L, 0x382838000000L, 0x705070000000L, 0xe0a0e0000000L, 0xc040c0000000L, 0x3020300000000L,
        0x7050700000000L, 0xe0a0e00000000L, 0x1c141c00000000L, 0x38283800000000L, 0x70507000000000L, 0xe0a0e000000000L, 0xc040c000000000L, 0x302030000000000L,
        0x705070000000000L, 0xe0a0e0000000000L, 0x1c141c0000000000L, 0x3828380000000000L, 0x7050700000000000L, -0x1f5f200000000000L, -0x3fbf400000000000L, 0x203000000000000L,
        0x507000000000000L, 0xa0e000000000000L, 0x141c000000000000L, 0x2838000000000000L, 0x5070000000000000L, -0x5f20000000000000L, 0x40c0000000000000L)

val whiteKingDangerZone = longArrayOf(
        197378L,460549L,921098L,1842196L,3684392L,7368784L,14737568L,12632128L,
        50529027L,117901063L,235802126L,471604252L,943208504L,1886417008L,3772834016L,3233857728L,
        12935430912L,30182672128L,60365344256L,120730688512L,241461377024L,482922754048L,965845508096L,827867578368L,
        3311470313472L,7726764064768L,15453528129536L,30907056259072L,61814112518144L,123628225036288L,247256450072576L,211934100062208L,
        847736400248832L,1978051600580608L,3956103201161216L,7912206402322432L,15824412804644864L,31648825609289728L,63297651218579456L,54255129615925248L,
        217020518463700992L,506381209748635648L,1012762419497271296L,2025524838994542592L,4051049677989085184L,8102099355978170368L,-2242545361753210880L,-4557430892032688128L,
        217020505578799104L,506381179683864576L,1012762359367729152L,2025524718735458304L,4051049437470916608L,8102098874941833216L,-2242546323825885184L,-4557431716666408960L,
        217017207043915776L,506373483102470144L,1012746966204940288L,2025493932409880576L,4050987864819761152L,8101975729639522304L,-2242792614430507008L,-4557642822898941952L
)

val blackKingDangerZone = longArrayOf(
        771L,1799L,3598L,7196L,14392L,28784L,57568L,49344L,
        197379L,460551L,921102L,1842204L,3684408L,7368816L,14737632L,12632256L,
        50529027L,117901063L,235802126L,471604252L,943208504L,1886417008L,3772834016L,3233857728L,
        12935430912L,30182672128L,60365344256L,120730688512L,241461377024L,482922754048L,965845508096L,827867578368L,
        3311470313472L,7726764064768L,15453528129536L,30907056259072L,61814112518144L,123628225036288L,247256450072576L,211934100062208L,
        847736400248832L,1978051600580608L,3956103201161216L,7912206402322432L,15824412804644864L,31648825609289728L,63297651218579456L,54255129615925248L,
        217020518463700992L,506381209748635648L,1012762419497271296L,2025524838994542592L,4051049677989085184L,8102099355978170368L,-2242545361753210880L,-4557430892032688128L,
        144962911540871168L,362265991608008704L,724531983216017408L,1449063966432034816L,2898127932864069632L,5796255865728139264L,-6854232342253273088L,4665940320188366848L
)

val whitePawnMovesForward = longArrayOf(
        0x100L, 0x200L, 0x400L, 0x800L, 0x1000L, 0x2000L, 0x4000L, 0x8000L,
        0x10000L, 0x20000L, 0x40000L, 0x80000L, 0x100000L, 0x200000L, 0x400000L, 0x800000L,
        0x1000000L, 0x2000000L, 0x4000000L, 0x8000000L, 0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L,
        0x100000000L, 0x200000000L, 0x400000000L, 0x800000000L, 0x1000000000L, 0x2000000000L, 0x4000000000L, 0x8000000000L,
        0x10000000000L, 0x20000000000L, 0x40000000000L, 0x80000000000L, 0x100000000000L, 0x200000000000L, 0x400000000000L, 0x800000000000L,
        0x1000000000000L, 0x2000000000000L, 0x4000000000000L, 0x8000000000000L, 0x10000000000000L, 0x20000000000000L, 0x40000000000000L, 0x80000000000000L,
        0x100000000000000L, 0x200000000000000L, 0x400000000000000L, 0x800000000000000L, 0x1000000000000000L, 0x2000000000000000L, 0x4000000000000000L, (1L shl 63),
        0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L)

val whitePawnMovesCapture = longArrayOf(
        0x200L, 0x500L, 0xa00L, 0x1400L, 0x2800L, 0x5000L, 0xa000L, 0x4000L,
        0x20000L, 0x50000L, 0xa0000L, 0x140000L, 0x280000L, 0x500000L, 0xa00000L, 0x400000L,
        0x2000000L, 0x5000000L, 0xa000000L, 0x14000000L, 0x28000000L, 0x50000000L, 0xa0000000L, 0x40000000L,
        0x200000000L, 0x500000000L, 0xa00000000L, 0x1400000000L, 0x2800000000L, 0x5000000000L, 0xa000000000L, 0x4000000000L,
        0x20000000000L, 0x50000000000L, 0xa0000000000L, 0x140000000000L, 0x280000000000L, 0x500000000000L, 0xa00000000000L, 0x400000000000L,
        0x2000000000000L, 0x5000000000000L, 0xa000000000000L, 0x14000000000000L, 0x28000000000000L, 0x50000000000000L, 0xa0000000000000L, 0x40000000000000L,
        0x200000000000000L, 0x500000000000000L, 0xa00000000000000L, 0x1400000000000000L, 0x2800000000000000L, 0x5000000000000000L, -0x6000000000000000L, 0x4000000000000000L,
        0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L)

val blackPawnMovesForward = longArrayOf(
        0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L,
        0x1L, 0x2L, 0x4L, 0x8L, 0x10L, 0x20L, 0x40L, 0x80L,
        0x100L, 0x200L, 0x400L, 0x800L, 0x1000L, 0x2000L, 0x4000L, 0x8000L,
        0x10000L, 0x20000L, 0x40000L, 0x80000L, 0x100000L, 0x200000L, 0x400000L, 0x800000L,
        0x1000000L, 0x2000000L, 0x4000000L, 0x8000000L, 0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L,
        0x100000000L, 0x200000000L, 0x400000000L, 0x800000000L, 0x1000000000L, 0x2000000000L, 0x4000000000L, 0x8000000000L,
        0x10000000000L, 0x20000000000L, 0x40000000000L, 0x80000000000L, 0x100000000000L, 0x200000000000L, 0x400000000000L, 0x800000000000L,
        0x1000000000000L, 0x2000000000000L, 0x4000000000000L, 0x8000000000000L, 0x10000000000000L, 0x20000000000000L, 0x40000000000000L, 0x80000000000000L)

val blackPawnMovesCapture = longArrayOf(
        0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L,
        0x2L, 0x5L, 0xaL, 0x14L, 0x28L, 0x50L, 0xa0L, 0x40L,
        0x200L, 0x500L, 0xa00L, 0x1400L, 0x2800L, 0x5000L, 0xa000L, 0x4000L,
        0x20000L, 0x50000L, 0xa0000L, 0x140000L, 0x280000L, 0x500000L, 0xa00000L, 0x400000L,
        0x2000000L, 0x5000000L, 0xa000000L, 0x14000000L, 0x28000000L, 0x50000000L, 0xa0000000L, 0x40000000L,
        0x200000000L, 0x500000000L, 0xa00000000L, 0x1400000000L, 0x2800000000L, 0x5000000000L, 0xa000000000L, 0x4000000000L,
        0x20000000000L, 0x50000000000L, 0xa0000000000L, 0x140000000000L, 0x280000000000L, 0x500000000000L, 0xa00000000000L, 0x400000000000L,
        0x2000000000000L, 0x5000000000000L, 0xa000000000000L, 0x14000000000000L, 0x28000000000000L, 0x50000000000000L, 0xa0000000000000L, 0x40000000000000L)

val whitePassedPawnMask = longArrayOf(
        0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
        0x0003030303030000L, 0x0007070707070000L, 0x000E0E0E0E0E0000L, 0x001C1C1C1C1C0000L, 0x0038383838380000L, 0x0070707070700000L, 0x00E0E0E0E0E00000L, 0x00C0C0C0C0C00000L,
        0x0003030303000000L, 0x0007070707000000L, 0x000E0E0E0E000000L, 0x001C1C1C1C000000L, 0x0038383838000000L, 0x0070707070000000L, 0x00E0E0E0E0000000L, 0x00C0C0C0C0000000L,
        0x0003030300000000L, 0x0007070700000000L, 0x000E0E0E00000000L, 0x001C1C1C00000000L, 0x0038383800000000L, 0x0070707000000000L, 0x00E0E0E000000000L, 0x00C0C0C000000000L,
        0x0003030000000000L, 0x0007070000000000L, 0x000E0E0000000000L, 0x001C1C0000000000L, 0x0038380000000000L, 0x0070700000000000L, 0x00E0E00000000000L, 0x00C0C00000000000L,
        0x0003000000000000L, 0x0007000000000000L, 0x000E000000000000L, 0x001C000000000000L, 0x0038000000000000L, 0x0070000000000000L, 0x00E0000000000000L, 0x00C0000000000000L,
        0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
        0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)

val blackPassedPawnMask = longArrayOf(
        0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
        0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
        0x0000000000000300L, 0x0000000000000700L, 0x0000000000000E00L, 0x0000000000001C00L, 0x0000000000003800L, 0x0000000000007000L, 0x000000000000E000L, 0x000000000000C000L,
        0x0000000000030300L, 0x0000000000070700L, 0x00000000000E0E00L, 0x00000000001C1C00L, 0x0000000000383800L, 0x0000000000707000L, 0x0000000000E0E000L, 0x0000000000C0C000L,
        0x0000000003030300L, 0x0000000007070700L, 0x000000000E0E0E00L, 0x000000001C1C1C00L, 0x0000000038383800L, 0x0000000070707000L, 0x00000000E0E0E000L, 0x00000000C0C0C000L,
        0x0000000303030300L, 0x0000000707070700L, 0x0000000E0E0E0E00L, 0x0000001C1C1C1C00L, 0x0000003838383800L, 0x0000007070707000L, 0x000000E0E0E0E000L, 0x000000C0C0C0C000L,
        0x0000030303030300L, 0x0000070707070700L, 0x00000E0E0E0E0E00L, 0x00001C1C1C1C1C00L, 0x0000383838383800L, 0x0000707070707000L, 0x0000E0E0E0E0E000L, 0x0000C0C0C0C0C000L,
        0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)

val whiteKingShieldMask = longArrayOf(
        1L shl 9 or (1L shl 8),
        1L shl 10 or (1L shl 9) or (1L shl 8),
        1L shl 11 or (1L shl 10) or (1L shl 9),
        1L shl 12 or (1L shl 11) or (1L shl 10),
        1L shl 13 or (1L shl 12) or (1L shl 11),
        1L shl 14 or (1L shl 13) or (1L shl 12),
        1L shl 15 or (1L shl 14) or (1L shl 13),
        1L shl 15 or (1L shl 14))

val bitFlippedHorizontalAxis = intArrayOf(
        56, 57, 58, 59, 60, 61, 62, 63, 48, 49, 50, 51, 52, 53, 54, 55, 40, 41, 42, 43, 44, 45, 46, 47, 32, 33, 34, 35, 36, 37, 38, 39, 24, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7
)





© 2015 - 2025 Weber Informatics LLC | Privacy Policy