Book { public final Move getBookMove(Position pos) { initBook(); List<BookEntry> bookMoves = bookMap.get(pos.zobristHash()); if (bookMoves == null) { return null; } MoveGen.MoveList legalMoves = new MoveGen().pseudoLegalMoves(pos); MoveGen.removeIllegal(pos, legalMoves); int sum = 0; for (int i = 0; i < bookMoves.size(); i++) { BookEntry be = bookMoves.get(i); boolean contains = false; for (int mi = 0; mi < legalMoves.size; mi++) if (legalMoves.m[mi].equals(be.move)) { contains = true; break; } if (!contains) { return null; } sum += getWeight(bookMoves.get(i).count); } if (sum <= 0) { return null; } int rnd = rndGen.nextInt(sum); sum = 0; for (int i = 0; i < bookMoves.size(); i++) { sum += getWeight(bookMoves.get(i).count); if (rnd < sum) { return bookMoves.get(i).move; } } throw new RuntimeException(); } Book(boolean verbose); final Move getBookMove(Position pos); final String getAllBookMoves(Position pos);  }
@Test public void testGetBookMove() throws ChessParseError { System.out.println("getBookMove"); Position pos = TextIO.readFEN(TextIO.startPosFEN); Book book = new Book(true); Move move = book.getBookMove(pos); checkValid(pos, move); }