Compare commits
No commits in common. "00f371b913638dc2420ef2b7358be067e4807795" and "0469760f305d355d7703dd204bd60b1552b318a4" have entirely different histories.
00f371b913
...
0469760f30
|
|
@ -98,15 +98,10 @@ class BestMoveSearcher {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getPositionBasePriority(Position position, int value, Iterable<(String, Position)> legalMoves, int depth) {
|
static int getPositionBasePriority(Position position, int value, Iterable<(String, Position)> legalMoves, int depth) =>
|
||||||
if (legalMoves.isEmpty) {
|
legalMoves.isEmpty
|
||||||
return Numbers.maxInteger;
|
? Numbers.maxInteger
|
||||||
}
|
: 0;
|
||||||
if (legalMoves.length < 10) {
|
|
||||||
return (-2520 / legalMoves.length).toInt() >> 2;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String?> search(Position position, int? moveTime) async {
|
Future<String?> search(Position position, int? moveTime) async {
|
||||||
_isRunning = true;
|
_isRunning = true;
|
||||||
|
|
@ -119,7 +114,7 @@ class BestMoveSearcher {
|
||||||
while (!_isStopped && positionTree.priority < Numbers.maxInteger) {
|
while (!_isStopped && positionTree.priority < Numbers.maxInteger) {
|
||||||
positionTree.computeStep();
|
positionTree.computeStep();
|
||||||
time = DateTime.now().millisecondsSinceEpoch - startTime;
|
time = DateTime.now().millisecondsSinceEpoch - startTime;
|
||||||
if (null != moveTime && time >= moveTime - 1000) {
|
if (null != moveTime && time >= moveTime) {
|
||||||
_isStopped = true;
|
_isStopped = true;
|
||||||
}
|
}
|
||||||
if (positionTree.childrenByValue.isNotEmpty || bestValue != positionTree.value) {
|
if (positionTree.childrenByValue.isNotEmpty || bestValue != positionTree.value) {
|
||||||
|
|
|
||||||
|
|
@ -363,11 +363,4 @@ class Position {
|
||||||
move.length > 4 ? move.substring(4).toLowerCase() : null,
|
move.length > 4 ? move.substring(4).toLowerCase() : null,
|
||||||
);
|
);
|
||||||
|
|
||||||
static bool isTake(Position position, String move) {
|
|
||||||
final (int from, int to, String? promotingPiece) = moveStringToIndices(move);
|
|
||||||
return
|
|
||||||
(position.board[to] != Piece.emptySquare) ||
|
|
||||||
(position.enPassantTargetSquare == to && (position.board[from] == Piece.whitePawn || position.board[from] == Piece.blackPawn));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -63,30 +63,27 @@ class PositionTreeNode {
|
||||||
_computeChildren();
|
_computeChildren();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final PositionTreeNode computedChild = children.first;
|
final PositionTreeNode firstChild = children.first;
|
||||||
final int initialFirstChildNodeCount = computedChild.nodeCount;
|
final int initialFirstChildNodeCount = firstChild.nodeCount;
|
||||||
computedChild.computeStep();
|
firstChild.computeStep();
|
||||||
children.updateElement(computedChild.move);
|
children.updateElement(firstChild.move);
|
||||||
childrenByValue.updateElement(computedChild.move);
|
childrenByValue.updateElement(firstChild.move);
|
||||||
nodeCount += computedChild.nodeCount - initialFirstChildNodeCount;
|
nodeCount += firstChild.nodeCount - initialFirstChildNodeCount;
|
||||||
if (computedChild.depth + 1 > depth) {
|
if (firstChild.depth + 1 > depth) {
|
||||||
depth = computedChild.depth + 1;
|
depth = firstChild.depth + 1;
|
||||||
}
|
}
|
||||||
priority = (children.first.priority == Numbers.maxInteger) ? children.first.priority : children.first.priority + 100;
|
priority = (children.first.priority == Numbers.maxInteger) ? children.first.priority : children.first.priority + 1;
|
||||||
value = childrenByValue.first.value;
|
value = childrenByValue.first.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _computeChildren() {
|
void _computeChildren() {
|
||||||
for (final (String, Position) move in legalMoves) {
|
for (final (String, Position) move in legalMoves) {
|
||||||
final PositionTreeNode positionTreeNode = PositionTreeNode.fromPosition(move.$2, move.$1);
|
final PositionTreeNode positionTreeNode = PositionTreeNode.fromPosition(move.$2, move.$1);
|
||||||
if (Position.isTake(position, move.$1)) {
|
|
||||||
positionTreeNode.priority -= 200;
|
|
||||||
}
|
|
||||||
children.add(positionTreeNode);
|
children.add(positionTreeNode);
|
||||||
childrenByValue.add(positionTreeNode);
|
childrenByValue.add(positionTreeNode);
|
||||||
}
|
}
|
||||||
nodeCount = legalMoves.length;
|
nodeCount = legalMoves.length;
|
||||||
priority = (children.first.priority == Numbers.maxInteger) ? children.first.priority : children.first.priority + 100;
|
priority = (children.first.priority == Numbers.maxInteger) ? children.first.priority : children.first.priority + 1;
|
||||||
depth = 1;
|
depth = 1;
|
||||||
value = childrenByValue.first.value;
|
value = childrenByValue.first.value;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,7 @@ class _LegalMovesBlack {
|
||||||
// up
|
// up
|
||||||
bool hasEncounteredPiece = false;
|
bool hasEncounteredPiece = false;
|
||||||
int j = i-8;
|
int j = i-8;
|
||||||
while (!hasEncounteredPiece && j >= 0) {
|
while (!hasEncounteredPiece && j > 0) {
|
||||||
if (Piece.emptySquare == position.board[j]) {
|
if (Piece.emptySquare == position.board[j]) {
|
||||||
yield ("${Position.squareIndexToString(i)}${Position.squareIndexToString(j)}", Position.from(position)..playMoveIndices(i, j));
|
yield ("${Position.squareIndexToString(i)}${Position.squareIndexToString(j)}", Position.from(position)..playMoveIndices(i, j));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,7 @@ class _LegalMovesWhite {
|
||||||
// up
|
// up
|
||||||
bool hasEncounteredPiece = false;
|
bool hasEncounteredPiece = false;
|
||||||
int j = i-8;
|
int j = i-8;
|
||||||
while (!hasEncounteredPiece && j >= 0) {
|
while (!hasEncounteredPiece && j > 0) {
|
||||||
if (Piece.emptySquare == position.board[j]) {
|
if (Piece.emptySquare == position.board[j]) {
|
||||||
yield ("${Position.squareIndexToString(i)}${Position.squareIndexToString(j)}", Position.from(position)..playMoveIndices(i, j));
|
yield ("${Position.squareIndexToString(i)}${Position.squareIndexToString(j)}", Position.from(position)..playMoveIndices(i, j));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -110,26 +110,26 @@ class Omnichess {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() async {
|
void loop() async {
|
||||||
// final DateTime now = DateTime.now();
|
final DateTime now = DateTime.now();
|
||||||
// final String logName = "${now.year}"
|
final String logName = "${now.year}"
|
||||||
// "${now.month.toString().padLeft(2, "0")}"
|
"${now.month.toString().padLeft(2, "0")}"
|
||||||
// "${now.day.toString().padLeft(2, "0")}"
|
"${now.day.toString().padLeft(2, "0")}"
|
||||||
// "-"
|
"-"
|
||||||
// "${now.hour.toString().padLeft(2, "0")}"
|
"${now.hour.toString().padLeft(2, "0")}"
|
||||||
// "${now.minute.toString().padLeft(2, "0")}"
|
"${now.minute.toString().padLeft(2, "0")}"
|
||||||
// "${now.second.toString().padLeft(2, "0")}"
|
"${now.second.toString().padLeft(2, "0")}"
|
||||||
// "${now.millisecond.toString().padLeft(3, "0")}"
|
"${now.millisecond.toString().padLeft(3, "0")}"
|
||||||
// ".log";
|
".log";
|
||||||
// final File log = File("logs/$logName");
|
final File log = File("logs/$logName");
|
||||||
// if (!log.existsSync()) {
|
if (!log.existsSync()) {
|
||||||
// log.createSync();
|
log.createSync();
|
||||||
// }
|
}
|
||||||
late StreamSubscription<String> inputSubscription;
|
late StreamSubscription<String> inputSubscription;
|
||||||
inputSubscription = stdin
|
inputSubscription = stdin
|
||||||
.transform(utf8.decoder)
|
.transform(utf8.decoder)
|
||||||
.transform(LineSplitter())
|
.transform(LineSplitter())
|
||||||
.listen((String line) async {
|
.listen((String line) async {
|
||||||
// log.writeAsStringSync("$line\n", mode: FileMode.append);
|
log.writeAsStringSync("$line\n", mode: FileMode.append);
|
||||||
final String input = line.trim();
|
final String input = line.trim();
|
||||||
final bool keepGoing = await elaborate(input);
|
final bool keepGoing = await elaborate(input);
|
||||||
if (!keepGoing) {
|
if (!keepGoing) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue