mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-10 08:02:40 +01:00
Moved CuckooChessEngine project to trunk/
This commit is contained in:
85
CuckooChessEngine/test/chess/BookTest.java
Normal file
85
CuckooChessEngine/test/chess/BookTest.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
CuckooChess - A java chess program.
|
||||
Copyright (C) 2011 Peter Österlund, peterosterlund2@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package chess;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author petero
|
||||
*/
|
||||
public class BookTest {
|
||||
|
||||
public BookTest() {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getBookMove method, of class Book.
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getAllBookMoves method, of class Book.
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllBookMoves() throws ChessParseError {
|
||||
System.out.println("getAllBookMoves");
|
||||
Position pos = TextIO.readFEN(TextIO.startPosFEN);
|
||||
Book book = new Book(true);
|
||||
String moveListString = book.getAllBookMoves(pos);
|
||||
String[] strMoves = moveListString.split("\\([0-9]*\\) ");
|
||||
assertTrue(strMoves.length > 1);
|
||||
for (String strMove : strMoves) {
|
||||
Move m = TextIO.stringToMove(pos, strMove);
|
||||
checkValid(pos, m);
|
||||
}
|
||||
}
|
||||
|
||||
/** Check that move is a legal move in position pos. */
|
||||
private void checkValid(Position pos, Move move) {
|
||||
assertTrue(move != null);
|
||||
MoveGen.MoveList moveList = new MoveGen().pseudoLegalMoves(pos);
|
||||
MoveGen.removeIllegal(pos, moveList);
|
||||
boolean contains = false;
|
||||
for (int mi = 0; mi < moveList.size; mi++)
|
||||
if (moveList.m[mi].equals(move)) {
|
||||
contains = true;
|
||||
break;
|
||||
}
|
||||
assertTrue(contains);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user