-
Notifications
You must be signed in to change notification settings - Fork 1
/
move_util.go
63 lines (52 loc) · 1.53 KB
/
move_util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package godraughts
import (
Color "github.com/dangnguyendota/godraughts/color"
"github.com/dangnguyendota/godraughts/magic"
)
const (
endShift int = 50
pieceShift int = 56
colorShift int = 57
captureFlagShift int = 58
promotionFlagShift int = 59
legalMoveFlagShift int = 60
Mask1Bit int64 = 0x1
Mask6Bit int64 = 0x3F
)
func getRemoveMap(move int64) int64 {
return move & magic.LegalMask
}
func getEndIndex(move int64) int {
return int(move >> endShift & Mask6Bit)
}
func getPiece(move int64) int {
return int(move >> pieceShift & Mask1Bit)
}
func getColor(move int64) int {
return int(move >> colorShift & Mask1Bit)
}
func isCapture(move int64) bool {
return (move >> captureFlagShift & Mask1Bit) == 1
}
func isPromotion(move int64) bool {
return (move >> promotionFlagShift & Mask1Bit) == 1
}
func isLegalMove(move int64) bool {
return (move >> legalMoveFlagShift & Mask1Bit) == 1
}
func createMove(removeMap int64, endPos, piece, color, capture int) int64 {
promotion := 0
if color == Color.White {
if (magic.MASK[endPos] & 0x1f) != 0 {
promotion = 1
}
} else if color == Color.Black {
if (magic.MASK[endPos] & 0x3e00000000000) != 0 {
promotion = 1
}
}
return removeMap | int64(endPos) << endShift | int64(piece) << pieceShift | int64(color) << colorShift | int64(capture) << captureFlagShift | int64(promotion) << promotionFlagShift | magic.MASK[legalMoveFlagShift]
}
func removeLegal(move int64) int64 {
return move ^ magic.MASK[legalMoveFlagShift]
}