Skip to content

Commit bf9bb2c

Browse files
committed
internal minor changes
1 parent 1bdf35e commit bf9bb2c

File tree

6 files changed

+317
-20
lines changed

6 files changed

+317
-20
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
*.c
99
See_c/*.*
1010
temp.go
11-
See_c/SEE_Pradu.txt
11+
diverse/*.*

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"LICENSE": true,
1010
"uci_example.txt": true,
1111
"**/*.jpg": true,
12-
".gitignore": true,
1312
"See_c": true,
14-
"_config.yml": true
13+
"_config.yml": true,
14+
"diverese": true
1515
},
1616
"cSpell.words": [
1717
"Pval",

design.png

-57.8 KB
Binary file not shown.

diverese/See_c/SEE_Pradu.txt

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
//the board structure
2+
const
3+
P = 0;
4+
N = 1;
5+
B = 2;
6+
R = 3;
7+
Q = 4;
8+
K = 5;
9+
E = -1;
10+
WHITE = 0;
11+
BLACK = 1;
12+
Pval = 100;
13+
Qval = 900;
14+
Nval = 300;
15+
Bval = 330;
16+
Rval = 500;
17+
Kval = 99999;
18+
INF = 999999;
19+
typedef unsigned long U64;
20+
typedef bool bool;
21+
typedef struct _board //104 bytes
22+
{
23+
U64 AllPieces; //All the pieces on the board
24+
U64 PiecesSide[2]; //All the pieces belonging to each side
25+
U64 Pieces[12]; //Specific pieces on the board eg Pieces[R]
26+
U64 hashkey; //the hash key for the transposition table
27+
unsigned char PieceTypes[64]; //All the piece types according to squares
28+
unsigned char KingPos[2]; //King position for a side
29+
unsigned char EP; //The enpassant square
30+
unsigned char castling; //Castling privilages - format defined below
31+
unsigned char fifty; //Fifty move count
32+
unsigned char SF; //Search Flags (see Search Related section)
33+
bool side; //the side to play
34+
bool xside; //the side opposite to play
35+
} board;
36+
37+
#define LSB(X) ((X) & -(X))
38+
typedef unsigned int move;
39+
int pieceValue[12];
40+
//full static exchange evaluvation
41+
int SEE(const board *pos, const move m)
42+
{
43+
//The variables are set to the inital state where the move in question has been played
44+
int SEEscore = pieceValue[extractCapture(m)]; //The score to be returned
45+
int SEEmax, SEEmin; //Maximum and minimum SEE scores (alphbeta approach)
46+
int target = extractTo(m); //The square that we are doing a SEE on
47+
int currentPieceValue = pieceValue[extractPiece(m)]; //Value of the piece currently on the target square
48+
U64 used = toBit(extractFrom(m)); //Used attackers
49+
//Battery attacks will be calculated instead of regular attacks
50+
//Piece order isn't a problem (except when dealing with Queens)
51+
U64 occupancy = (pos->AllPieces ^ used) &
52+
~(pos->Pieces[B] | pos->Pieces[R] | ((pos->Pieces[P]) & (Pcaps(target, WHITE) | Pcaps(target, BLACK))));
53+
54+
U64 attackers; //attackers of each piece type from both sides
55+
U64 attackersSide; //attackers for each piece type for a particular side
56+
U64 attackersPiece; //attackers for a particular color and a particular type
57+
58+
//handle enpassant and promotion
59+
if (currentPieceValue == Pval)
60+
{
61+
if (extractEP(m))
62+
{
63+
used |= toBit(extractEP(m));
64+
occupancy ^= toBit(extractEP(m));
65+
SEEscore = Pval;
66+
}
67+
else if (extractPromotion(m) != E)
68+
{
69+
SEEscore += pieceValue[extractPromotion(m)] - Pval;
70+
currentPieceValue = Qval;
71+
}
72+
}
73+
74+
//these are the bounds, we will be doing an alphabeta-like search in SEE
75+
SEEmax = SEEscore; //upperbound
76+
SEEmin = -INF; //lowerbound
77+
78+
//Generate attackers
79+
attackers = attacksToOcc(*pos, target, occupancy) ^ used;
80+
81+
//Loop Through Opponent Captures
82+
while (attackersSide = attackers & pos->PiecesSide[pos->xside])
83+
{
84+
SEEscore -= currentPieceValue;
85+
if (SEEscore >= SEEmax)
86+
return SEEmax;
87+
if (SEEscore > SEEmin)
88+
SEEmin = SEEscore;
89+
90+
if (attackersPiece = attackersSide & pos->Pieces[P]) //Pawn
91+
{
92+
used |= LSB(attackersPiece);
93+
attackers ^= LSB(attackersPiece);
94+
currentPieceValue = Pval;
95+
}
96+
else if (attackersPiece = attackersSide & pos->Pieces[N]) //Knight
97+
{
98+
attackers ^= LSB(attackersPiece);
99+
currentPieceValue = Nval;
100+
}
101+
else if (attackersPiece = attackersSide & pos->Pieces[B]) //Bishop
102+
{
103+
attackers ^= LSB(attackersPiece);
104+
used |= LSB(attackersPiece);
105+
currentPieceValue = Bval;
106+
}
107+
else if (attackersPiece = attackersSide & pos->Pieces[R]) //Rook
108+
{
109+
attackers ^= LSB(attackersPiece);
110+
used |= LSB(attackersPiece);
111+
currentPieceValue = Rval;
112+
}
113+
else if (attackersPiece = attackersSide & pos->Pieces[Q]) //Queen
114+
{
115+
used |= LSB(attackersPiece);
116+
occupancy ^= LSB(attackersPiece);
117+
attackers = attacksBQRToOcc(*pos, target, occupancy) ^ used;
118+
currentPieceValue = Qval;
119+
}
120+
else //King
121+
{
122+
attackers ^= toBit(pos->KingPos[pos->xside]);
123+
currentPieceValue = Kval;
124+
}
125+
//Loop Through My Captures
126+
if (!(attackersSide = attackers & pos->PiecesSide[pos->side]))
127+
break;
128+
129+
SEEscore += currentPieceValue;
130+
if (SEEscore <= SEEmin)
131+
return SEEmin;
132+
if (SEEscore < SEEmax)
133+
SEEmax = SEEscore;
134+
135+
if (attackersPiece = attackersSide & pos->Pieces[P]) //Pawn
136+
{
137+
used |= LSB(attackersPiece);
138+
attackers ^= LSB(attackersPiece);
139+
currentPieceValue = Pval;
140+
}
141+
else if (attackersPiece = attackersSide & pos->Pieces[N]) //Knight
142+
{
143+
attackers ^= LSB(attackersPiece);
144+
currentPieceValue = Nval;
145+
}
146+
else if (attackersPiece = attackersSide & pos->Pieces[B]) //Bishop
147+
{
148+
attackers ^= LSB(attackersPiece);
149+
used |= LSB(attackersPiece);
150+
currentPieceValue = Bval;
151+
}
152+
else if (attackersPiece = attackersSide & pos->Pieces[R]) //Rook
153+
{
154+
attackers ^= LSB(attackersPiece);
155+
used |= LSB(attackersPiece);
156+
currentPieceValue = Rval;
157+
}
158+
else if (attackersPiece = attackersSide & pos->Pieces[Q]) //Queen
159+
{
160+
used |= LSB(attackersPiece);
161+
occupancy ^= LSB(attackersPiece);
162+
attackers |= attacksBQRToOcc(*pos, target, occupancy) & ~used;
163+
currentPieceValue = Qval;
164+
}
165+
else //King
166+
{
167+
attackers ^= toBit(pos->KingPos[pos->side]);
168+
currentPieceValue = Kval;
169+
}
170+
}
171+
if (SEEscore < SEEmin)
172+
return SEEmin;
173+
if (SEEscore > SEEmax)
174+
return SEEmax;
175+
return SEEscore;
176+
}

diverese/See_c/SEE_Tord.txt

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
P = 0;
2+
PAWN = 0;
3+
N = 1;
4+
B = 2;
5+
R = 3;
6+
Q = 4;
7+
K = 5;
8+
KING = 5;
9+
E = -1;
10+
WHITE = 0;
11+
BLACK = 1;
12+
Pval = 100;
13+
Qval = 900;
14+
Nval = 300;
15+
Bval = 330;
16+
Rval = 500;
17+
Kval = 99999;
18+
INF = 999999;
19+
EmptyBoardBB = 0x0;
20+
typedef unsigned long U64;
21+
typedef bool bool;
22+
typedef unsigned int Color;
23+
typedef unsigned int Piece;
24+
typedef unsigned int PieceType;
25+
typedef U64 Bitboard;
26+
27+
typedef unsigned int Square;
28+
int see(Square from, Square to)
29+
{
30+
// Go: Make unitTest first
31+
// Approximate material values, with pawn = 1:
32+
static const int seeValues[18] = {
33+
0, 1, 3, 3, 5, 10, 100, 0, 0, 1, 3, 3, 5, 10, 100, 0, 0, 0};
34+
Color us, them;
35+
Piece piece, capture;
36+
Bitboard attackers, occ;
37+
38+
// Initialize colors:
39+
us = this->color_of_piece_at(from); // Go: stm := b.stm
40+
them = opposite_color(us); // Go: opp := stm ^ 0x1
41+
42+
// Initialize pieces:
43+
piece = this->piece_at(from);
44+
capture = this->piece_at(to); // go: toVal := seeValues[capture]
45+
46+
// Find all attackers to the destination square, but with the moving piece
47+
// removed, but possibly an X-ray attacker added behind it:
48+
occ = this->occupied_squares();
49+
clear_bit(&occ, from);
50+
attackers =
51+
(rook_attacks_bb(to, occ) & this->rooks_and_queens()) |
52+
(bishop_attacks_bb(to, occ) & this->bishops_and_queens()) |
53+
(this->knight_attacks(to) & this->knights()) |
54+
(this->king_attacks(to) & this->kings()) |
55+
(this->white_pawn_attacks(to) & this->pawns_of_color(BLACK)) |
56+
(this->black_pawn_attacks(to) & this->pawns_of_color(WHITE));
57+
attackers &= occ;
58+
59+
// If the opponent has no attackers, we are finished:
60+
if ((attackers & this->pieces_of_color(them)) == EmptyBoardBB)
61+
return seeValues[capture]; // go: return toVal
62+
63+
// The destination square is defended, which makes things rather more
64+
// difficult to compute. We proceed by building up a "swap list" containing
65+
// the material gain or loss at each stop in a sequence of captures to the
66+
// destination square, where the sides alternately capture, and always
67+
// capture with the least valuable piece. After each capture, we look for
68+
// new X-ray attacks from behind the capturing piece.
69+
int lastCapturingPieceValue = seeValues[piece]; // Go: prevValue := seeValue[frPiece]
70+
int swapList[32], n = 1;
71+
Color c = them;
72+
PieceType pt;
73+
Bitboard b;
74+
75+
swapList[0] = seeValues[capture]; // Go: swapList[0] = toVal
76+
77+
do
78+
{
79+
// Locate the least valuable attacker for the side to move. The loop
80+
// below looks like it is potentially infinite, but it isn't. We know
81+
// that the side to move still has some attackers left.
82+
// go maybe getNext(.....):
83+
// Pawns
84+
// Knights
85+
// Bishops + Q
86+
// Rooks + Q
87+
// King
88+
for (pt = PAWN; !(attackers & this->pieces_of_color_and_type(c, pt)); pt++)
89+
assert(pt <= KING);
90+
91+
// Remove the attacker we just found from the 'attackers' bitboard,
92+
// and scan for new X-ray attacks behind the attacker:
93+
b = attackers & this->pieces_of_color_and_type(c, pt);
94+
occ ^= (b & -b);
95+
// Go: the following works even when pt is non sliding because ther will be no new bits
96+
attackers |=
97+
(rook_attacks_bb(to, occ) & this->rooks_and_queens()) |
98+
(bishop_attacks_bb(to, occ) & this->bishops_and_queens());
99+
attackers &= occ;
100+
101+
// Add the new entry to the swap list:
102+
swapList[n] = -swapList[n - 1] + lastCapturingPieceValue; // Go: + prevSee
103+
n++;
104+
105+
// Remember the value of the capturing piece, and change the side to move
106+
// before beginning the next iteration:
107+
lastCapturingPieceValue = seeValues[pt]; // Go: prevSee := seeValue[pt)]
108+
c = opposite_color(c); // Go: stm,opp = opp,stm (Lägg sist i loop. Använd stm istf c)
109+
110+
// Stop after a king capture:
111+
if (pt == KING && (attackers & this->pieces_of_color(c))) //Go: använd opp istf c
112+
{
113+
swapList[n++] = 100; // maxEval
114+
break;
115+
}
116+
// Go: stm,opp = opp,stm (se ovan)
117+
} while (attackers & this->pieces_of_color(c));
118+
119+
// Having built the swap list, we negamax through it to find the best
120+
// achievable score from the point of view of the side to move:
121+
while (--n)
122+
swapList[n - 1] = Min(-swapList[n], swapList[n - 1]);
123+
124+
return swapList[0];
125+
}

position.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,23 @@ func (b *boardStruct) move(fr, to, pr int) bool {
6868
case p12 == wK:
6969
b.castlings.off(shortW | longW)
7070
if abs(to-fr) == 2 {
71-
if fr == E1 {
72-
if to == G1 {
73-
b.setSq(wR, F1)
74-
b.setSq(empty, H1)
75-
} else {
76-
b.setSq(wR, D1)
77-
b.setSq(empty, A1)
78-
}
71+
if to == G1 {
72+
b.setSq(wR, F1)
73+
b.setSq(empty, H1)
74+
} else {
75+
b.setSq(wR, D1)
76+
b.setSq(empty, A1)
7977
}
8078
}
8179
case p12 == bK:
8280
b.castlings.off(shortB | longB)
8381
if abs(to-fr) == 2 {
84-
if fr == E8 {
85-
if to == G8 {
86-
b.setSq(bR, F8)
87-
b.setSq(empty, H8)
88-
} else {
89-
b.setSq(bR, D8)
90-
b.setSq(empty, A8)
91-
}
82+
if to == G8 {
83+
b.setSq(bR, F8)
84+
b.setSq(empty, H8)
85+
} else {
86+
b.setSq(bR, D8)
87+
b.setSq(empty, A8)
9288
}
9389
}
9490
case p12 == wR:
@@ -248,7 +244,7 @@ func (b *boardStruct) genFrMoves(p12 int, frBB bitBoard, ml *moveList) {
248244

249245
//////////////////////////////////// my own commands - NOT UCI /////////////////////////////////////
250246

251-
func (b *boardStruct) printAllMvs() {
247+
func (b *boardStruct) printAllMvs() {
252248

253249
fmt.Println("magic")
254250
// var ml moveList

0 commit comments

Comments
 (0)