Skip to content
This repository was archived by the owner on Aug 2, 2019. It is now read-only.

Commit bcfd380

Browse files
committed
Cleanup
Do never ever use "tabs" :-)
1 parent 7fea632 commit bcfd380

File tree

1 file changed

+74
-59
lines changed

1 file changed

+74
-59
lines changed

src/eval.cpp

Lines changed: 74 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,21 @@ static const int MinLine[8] = { // minor
187187
+35, +25, +15, +5, +5, +15, +25, +35, // TODO: tune me!
188188
};
189189

190+
static const inc_t KnightVector[8] = {
191+
-33, -31, -18, -14, 33, 31, 18, 14
192+
};
193+
194+
static const inc_t BishopVector[4] = {
195+
-17, -15, 15, 17
196+
};
197+
198+
static const inc_t RookVector[4] = {
199+
-1, -16, 16, 1
200+
};
201+
static const inc_t QueenVector[8] = {
202+
-17, -15, 15, 17, -1, -16, 16, 1
203+
};
204+
190205
// variables
191206

192207
static int MobUnit[ColourNb][PieceNb];
@@ -873,6 +888,7 @@ static void eval_piece(const board_t * board, const material_info_t * mat_info,
873888
int op[ColourNb], eg[ColourNb];
874889
int me, opp;
875890
const sq_t * ptr;
891+
int i;
876892
int from, to;
877893
int piece;
878894
int mob;
@@ -882,12 +898,7 @@ static void eval_piece(const board_t * board, const material_info_t * mat_info,
882898
int king;
883899
int delta;
884900
int att;
885-
int vector; // for mobility loops
886-
887-
static const int knight_vector[8] = {-33, -31, -18, -14, 33, 31, 18, 14};
888-
static const int bishop_vector[4] = {-17, -15, 15, 17};
889-
static const int rook_vector[4] = { -1, -16, 16, 1};
890-
static const int queen_vector[8] = {-17, -15, 15, 17, -1, -16, 16, 1};
901+
inc_t inc;
891902

892903
ASSERT(board!=NULL);
893904
ASSERT(mat_info!=NULL);
@@ -927,15 +938,17 @@ static void eval_piece(const board_t * board, const material_info_t * mat_info,
927938

928939
// mobility
929940

930-
for (int i = 0; i < 8; i++) {
931-
to = from + knight_vector[i];
932-
if ((capture = unit[board->square[to]]) > MobDefense) {
933-
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob++;
934-
if (UseMobAttack && capture > MobAttack) {
935-
if (NO_DEFENDER(to,pawn_safe)) att += capture;
936-
}
937-
}
938-
}
941+
for (i = 0; i < 8; i++) {
942+
943+
to = from + KnightVector[i];
944+
945+
if ((capture = unit[board->square[to]]) > MobDefense) {
946+
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob++;
947+
if (UseMobAttack && capture > MobAttack) {
948+
if (NO_DEFENDER(to,pawn_safe)) att += capture;
949+
}
950+
}
951+
}
939952

940953
if (UseMobLinear) {
941954
op[me] += (mob - KnightUnit) * KnightMobOpening;
@@ -956,26 +969,27 @@ static void eval_piece(const board_t * board, const material_info_t * mat_info,
956969

957970
// mobility
958971

959-
for (int i = 0; i < 4; i++) {
960-
vector = bishop_vector[i];
972+
for (i = 0; i < 4; i++) {
961973

962-
for (to = from+vector; capture=board->square[to], THROUGH(capture); to += vector) {
963-
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob += MobMove;
964-
}
974+
inc = BishopVector[i];
965975

966-
if ((piece = unit[capture]) > MobDefense) { // MobAttack
967-
mob += MobAttack;
968-
if (UseMobAttack && NO_DEFENDER(to,pawn_safe)) att += piece;
976+
for (to = from+inc; capture=board->square[to], THROUGH(capture); to += inc) {
977+
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob += MobMove;
978+
}
969979

970-
} else if (UseMobXRay && (capture & BishopFlag) != 0) { // MobXRay
971-
do {
972-
ASSERT(COLOUR_IS(capture,me));
973-
for (to += vector; capture=board->square[to], THROUGH(capture); to += vector) {
974-
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob += MobMove;
975-
}
976-
} while ((capture & BishopFlag) != 0 && PIECE_COLOUR(capture) == me);
977-
}
978-
}
980+
if ((piece = unit[capture]) > MobDefense) { // MobAttack
981+
mob += MobAttack;
982+
if (UseMobAttack && NO_DEFENDER(to,pawn_safe)) att += piece;
983+
984+
} else if (UseMobXRay && (capture & BishopFlag) != 0) { // MobXRay
985+
do {
986+
ASSERT(COLOUR_IS(capture,me));
987+
for (to += inc; capture=board->square[to], THROUGH(capture); to += inc) {
988+
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob += MobMove;
989+
}
990+
} while ((capture & BishopFlag) != 0 && PIECE_COLOUR(capture) == me);
991+
}
992+
}
979993

980994
if (UseMobLinear) {
981995
op[me] += (mob - BishopUnit) * BishopMobOpening;
@@ -996,26 +1010,27 @@ static void eval_piece(const board_t * board, const material_info_t * mat_info,
9961010

9971011
// mobility
9981012

999-
for (int i = 0; i < 4; i++) {
1000-
vector = rook_vector[i];
1013+
for (i = 0; i < 4; i++) {
1014+
1015+
inc = RookVector[i];
10011016

1002-
for (to = from+vector; capture=board->square[to], THROUGH(capture); to += vector) {
1003-
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob += MobMove;
1004-
}
1017+
for (to = from+inc; capture=board->square[to], THROUGH(capture); to += inc) {
1018+
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob += MobMove;
1019+
}
10051020

1006-
if ((piece = unit[capture]) > MobDefense) { // MobAttack
1007-
mob += MobAttack;
1008-
if (UseMobAttack && NO_DEFENDER(to,pawn_safe)) att += piece;
1021+
if ((piece = unit[capture]) > MobDefense) { // MobAttack
1022+
mob += MobAttack;
1023+
if (UseMobAttack && NO_DEFENDER(to,pawn_safe)) att += piece;
10091024

1010-
} else if (UseMobXRay && (capture & RookFlag) != 0) { // MobXRay
1011-
do {
1012-
ASSERT(COLOUR_IS(capture,me));
1013-
for (to += vector; capture=board->square[to], THROUGH(capture); to += vector) {
1014-
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob += MobMove;
1015-
}
1016-
} while ((capture & RookFlag) != 0 && PIECE_COLOUR(capture) == me);
1017-
}
1018-
}
1025+
} else if (UseMobXRay && (capture & RookFlag) != 0) { // MobXRay
1026+
do {
1027+
ASSERT(COLOUR_IS(capture,me));
1028+
for (to += inc; capture=board->square[to], THROUGH(capture); to += inc) {
1029+
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob += MobMove;
1030+
}
1031+
} while ((capture & RookFlag) != 0 && PIECE_COLOUR(capture) == me);
1032+
}
1033+
}
10191034

10201035
if (UseMobLinear) {
10211036
op[me] += (mob - RookUnit) * RookMobOpening;
@@ -1080,19 +1095,19 @@ static void eval_piece(const board_t * board, const material_info_t * mat_info,
10801095

10811096
// mobility
10821097

1083-
for (int i = 0; i < 8; i++) {
1084-
vector = queen_vector[i];
1098+
for (int i = 0; i < 8; i++) {
10851099

1086-
for (to = from+vector; capture=board->square[to], THROUGH(capture); to += vector) {
1087-
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob += MobMove;
1088-
}
1100+
inc = QueenVector[i];
10891101

1090-
if ((piece = unit[capture]) > MobDefense) { // MobAttack
1091-
mob += MobAttack;
1092-
if (UseMobAttack && NO_DEFENDER(to,pawn_safe)) att += piece;
1093-
}
1094-
}
1102+
for (to = from+inc; capture=board->square[to], THROUGH(capture); to += inc) {
1103+
if (!UseMobPawnSafe || NO_ATTACKER(to,pawn_safe)) mob += MobMove;
1104+
}
10951105

1106+
if ((piece = unit[capture]) > MobDefense) { // MobAttack
1107+
mob += MobAttack;
1108+
if (UseMobAttack && NO_DEFENDER(to,pawn_safe)) att += piece;
1109+
}
1110+
}
10961111

10971112
if (UseMobLinear) {
10981113
op[me] += (mob - QueenUnit) * QueenMobOpening;

0 commit comments

Comments
 (0)