Split singe file into set of src files
This commit is contained in:
145
lib/src/globals.dart
Normal file
145
lib/src/globals.dart
Normal file
@@ -0,0 +1,145 @@
|
||||
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// // Piece-Square tables. Tune these to change sunfish's behaviour
|
||||
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// TODO: add wizard
|
||||
final piece = {'P': 100, 'N': 280, 'B': 320, 'R': 479, 'Q': 929, 'K': 60000};
|
||||
|
||||
///TODO: add 2 raws and 2 colums to each set AND Wizard pst
|
||||
var pst = {
|
||||
'P': [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, //
|
||||
78, 83, 86, 73, 102, 82, 85, 90, //
|
||||
7, 29, 21, 44, 40, 31, 44, 7, //
|
||||
-17, 16, -2, 15, 14, 0, 15, -13, //
|
||||
-26, 3, 10, 9, 6, 1, 0, -23, //
|
||||
-22, 9, 5, -11, -10, -2, 3, -19, //
|
||||
-31, 8, -7, -37, -36, -14, 3, -31, //
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
], //
|
||||
'N': [
|
||||
-66, -53, -75, -75, -10, -55, -58, -70, //
|
||||
-3, -6, 100, -36, 4, 62, -4, -14, //
|
||||
10, 67, 1, 74, 73, 27, 62, -2, //
|
||||
24, 24, 45, 37, 33, 41, 25, 17, //
|
||||
-1, 5, 31, 21, 22, 35, 2, 0, //
|
||||
-18, 10, 13, 22, 18, 15, 11, -14, //
|
||||
-23, -15, 2, 0, 2, 0, -23, -20, //
|
||||
-74, -23, -26, -24, -19, -35, -22, -69
|
||||
], //
|
||||
'B': [
|
||||
-59, -78, -82, -76, -23, -107, -37, -50, //
|
||||
-11, 20, 35, -42, -39, 31, 2, -22, //
|
||||
-9, 39, -32, 41, 52, -10, 28, -14, //
|
||||
25, 17, 20, 34, 26, 25, 15, 10, //
|
||||
13, 10, 17, 23, 17, 16, 0, 7, //
|
||||
14, 25, 24, 15, 8, 25, 20, 15, //
|
||||
19, 20, 11, 6, 7, 6, 20, 16, //
|
||||
-7, 2, -15, -12, -14, -15, -10, -10
|
||||
], //
|
||||
'R': [
|
||||
35, 29, 33, 4, 37, 33, 56, 50, //
|
||||
55, 29, 56, 67, 55, 62, 34, 60, //
|
||||
19, 35, 28, 33, 45, 27, 25, 15, //
|
||||
0, 5, 16, 13, 18, -4, -9, -6, //
|
||||
-28, -35, -16, -21, -13, -29, -46, -30, //
|
||||
-42, -28, -42, -25, -25, -35, -26, -46, //
|
||||
-53, -38, -31, -26, -29, -43, -44, -53, //
|
||||
-30, -24, -18, 5, -2, -18, -31, -32
|
||||
], //
|
||||
'Q': [
|
||||
6, 1, -8, -104, 69, 24, 88, 26, //
|
||||
14, 32, 60, -10, 20, 76, 57, 24, //
|
||||
-2, 43, 32, 60, 72, 63, 43, 2, //
|
||||
1, -16, 22, 17, 25, 20, -13, -6, //
|
||||
-14, -15, -2, -5, -1, -10, -20, -22, //
|
||||
-30, -6, -13, -11, -16, -11, -16, -27, //
|
||||
-36, -18, 0, -19, -15, -15, -21, -38, //
|
||||
-39, -30, -31, -13, -31, -36, -34, -42
|
||||
], //
|
||||
'K': [
|
||||
4, 54, 47, -99, -99, 60, 83, -62, //
|
||||
-32, 10, 55, 56, 56, 55, 10, 3, //
|
||||
-62, 12, -57, 44, -67, 28, 37, -31, //
|
||||
-55, 50, 11, -4, -19, 13, 0, -49, //
|
||||
-55, -43, -52, -28, -51, -47, -8, -50, //
|
||||
-47, -42, -43, -79, -64, -32, -29, -32, //
|
||||
-4, 3, -14, -50, -57, -18, 13, 4, //
|
||||
17, 30, -3, -14, 6, -1, 40, 18
|
||||
], //
|
||||
};
|
||||
|
||||
// recalculating Piece-Square raw into desk surrounded by 0-s
|
||||
List<int> padrow(List<int> row, String k) {
|
||||
var rowBody = <int>[for (int x in row) x + piece[k]!];
|
||||
return [
|
||||
0,
|
||||
...rowBody,
|
||||
0,
|
||||
];
|
||||
}
|
||||
|
||||
void setPst() {
|
||||
pst.forEach((key, item) {
|
||||
final innerItem = [...List.filled(20, 0)];
|
||||
for (var i = 0; i < 8; i++) {
|
||||
innerItem.addAll(padrow(item.getRange(i * 8, i * 8 + 8).toList(), key));
|
||||
}
|
||||
innerItem.addAll(List.filled(20, 0));
|
||||
pst[key] = innerItem;
|
||||
});
|
||||
}
|
||||
|
||||
int getSeconds() {
|
||||
return DateTime.now().millisecondsSinceEpoch ~/ 1000.toInt();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Global constants
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Our board is represented as a 120 character string. The padding allows for
|
||||
// fast detection of moves that don't stay within the board.
|
||||
|
||||
//TODO: Tune globals for 10x10 field
|
||||
final A1 = 91, H1 = 98, A8 = 21, H8 = 28;
|
||||
final initial = (' \n' // 0 - 9
|
||||
' \n' // 10 - 19
|
||||
' rnbqkbnr\n' // 20 - 29
|
||||
' pppppppp\n' // 30 - 39
|
||||
' ........\n' // 40 - 49
|
||||
' ........\n' // 50 - 59
|
||||
' ........\n' // 60 - 69
|
||||
' ........\n' // 70 - 79
|
||||
' PPPPPPPP\n' // 80 - 89
|
||||
' RNBQKBNR\n' // 90 - 99
|
||||
' \n' // 100 -109
|
||||
' \n' // 110 -119
|
||||
);
|
||||
|
||||
// Lists of possible moves for each piece type.
|
||||
int N = -10, E = 1, S = 10, W = -1;
|
||||
//TODO: add directions for Wizard
|
||||
final Map<String?, List<int>> directions = {
|
||||
'P': [N, N + N, N + W, N + E],
|
||||
'N': [N + N + E, E + N + E, E + S + E, S + S + E, S + S + W, W + S + W, W + N + W, N + N + W],
|
||||
'B': [N + E, S + E, S + W, N + W],
|
||||
'R': [N, E, S, W],
|
||||
'Q': [N, E, S, W, N + E, S + E, S + W, N + W],
|
||||
'K': [N, E, S, W, N + E, S + E, S + W, N + W],
|
||||
'.': []
|
||||
};
|
||||
|
||||
// Mate value must be greater than 8*queen + 2*(rook+knight+bishop)
|
||||
// King value is set to twice this value such that if the opponent is
|
||||
// 8 queens up, but we got the king, we still exceed MATE_VALUE.
|
||||
// When a MATE is detected, we'll set the score to MATE_UPPER - plies to get there
|
||||
// E.g. Mate in 3 will be MATE_UPPER - 6
|
||||
// TOD: replace mate with King capture event
|
||||
final MATE_LOWER = piece['K']! - 10 * piece['Q']!;
|
||||
final MATE_UPPER = piece['K']! + 10 * piece['Q']!;
|
||||
|
||||
// The table size is the maximum number of elements in the transposition table.
|
||||
final TABLE_SIZE = 1e7;
|
||||
|
||||
// Constants for tuning search
|
||||
final QS_LIMIT = 219, EVAL_ROUGHNESS = 13, DRAW_TEST = true;
|
||||
Reference in New Issue
Block a user