Exemple #1
0
static void checkTest() {
	printf("starting checkTest\n");
	char fen[]="rnbq1bnr/ppppkppp/4p3/8/8/BP6/P1PPPPPP/RN1QKBNR b KQkq - 1 1";
	parseFen(fen);

	bool isBlackInCheck = isInCheckAux( gs.bitboard[BK], WHITE);
	assert(isBlackInCheck);

	char p[] = "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1";
	parseFen(p);

	isBlackInCheck = isInCheckAux( gs.bitboard[BK], WHITE);
	assert(!isBlackInCheck);

	bool isWhiteInCheck = isInCheckAux( gs.bitboard[WK],  BLACK);
	assert(!isWhiteInCheck);


	// String s55 = "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R4K1R b kq - 1 1";
	// gs = new GameState(s55);
	//isWhiteInCheck = gs.isInCheck( gs.bitboard[GameState.WK],GameState.BLACK);
	//assertEquals(false, isWhiteInCheck);


	// isWhiteInCheck = gs.isInCheck(GameState.WHITE);
	// assertEquals(false, isWhiteInCheck);
	printf("Finished checkTest\n");
}
Exemple #2
0
void bookTest() {
		printf("book test\n");
		char fen[] = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
		parseFen(fen);
		U64 hash = gs.hash;

		printf("first hash = %llu\n", hash);
		char fen2[70];


		toFEN(fen2);
		printf("fen=%s \n",fen2);
		parseFen(fen2);
		U64 hash2 = gs.hash;

		printf("second hash = %llu\n", hash2);
		assert(hash==hash2);
	    printBookMoves();
		char moveStr[5]="1234";

		getBookMove(hash, moveStr);
		printf("The book move is : %s\n", moveStr);
		assert(
				(strcmp(moveStr,"e2e4")== 0 ) ||
				(strcmp(moveStr,"d2d4")== 0 ) ||
				(strcmp(moveStr,"c2c4")== 0 ) ||
				(strcmp(moveStr,"g1f3")== 0 ) ||
				(strcmp(moveStr,"g2g3")== 0 ));
}
Exemple #3
0
static void runOnePosition(char fen[])  {
	parseFen(fen);
	search_debug=true;
	char moveStr[6];

	calcBestMove( moveStr);
	printf("new move = %s\n", moveStr);
}
Exemple #4
0
void run_search( char *fen, char *answer) {
	assert(gs.initialized);
	//printf("parseFen\n");
	parseFen(fen);
	//printf("execute\n");
	execute(answer);
	//printf("Finished execute\n");
}
Exemple #5
0
void testAux(char fen[], int num) {
	parseFen(fen);
	int numMoves;
	MOVE movelist[MAX_MOVES];
	getLegalMoveList( movelist, &numMoves);
	printf("number of moves = %d\n", numMoves);
	assert(num==numMoves);

}
Exemple #6
0
static  char * check_test() {
	assert(gs.initialized);
	printf("Running check_test\n");
	char fen[] = "rnbqk1nr/pppp1Bpp/8/2b1p3/4P3/8/PPPP1PPP/RNBQK1NR w KQkq - 0 1";
	//black king is in check from white bishop
	parseFen(fen);

	assert( isInCheck(BLACK));
	assert( !isInCheck(WHITE));
	return 0;
}
Exemple #7
0
void check_evasion_aux(char *fen, int i) {
	//printf("fen= %s\n", fen);

	//printf("check evasion moves\n");
	parseFen(fen);
	int cntMoves;
	MOVE movelist[MAX_MOVES];
	getLegalCheckEvasions( movelist, &cntMoves);
	/*for (int i=0; i < cntMoves; i++) {
		printMove(movelist[i]);
	}*/
	//printf("legal moves\n");
	parseFen(fen);
	int cntMoves2;
	MOVE movelist2[MAX_MOVES];
	getLegalMoveList( movelist2, &cntMoves2);
	/*for (int i=0; i < cntMoves2; i++) {
			printMove(movelist2[i]);
	}*/
	//printf("i= %d number of legal check evasion moves: %d   number of legal moves %d\n", i, cntMoves, cntMoves2);

	assert(cntMoves==cntMoves2);
}
Exemple #8
0
static char *eval_test() {
	assert(gs.initialized);
	printf("Running eval_test\n");
	char fen[] = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
	parseFen(fen);
	assert(gs.material[0]==gs.material[1]);
	assert(gs.material[0]==4165);
	printf(" material white %d material black %d\n", gs.material[0],gs.material[1]);
	printf(" positional white %d positional black %d\n", gs.positional[0],gs.positional[1]);

	int eval = getEvaluation(gs);
	printf("evaluation= %d\n", eval);
	assert( eval==0);
	return 0;
}
Exemple #9
0
void hash_test() {
	printf("hash_test()\n");
	char startPos[] ="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
	parseFen(startPos);
	U64 hash = gs.hash;

	hash_test_aux("g1f3", WN, 0, simple);
	hash_test_aux("g8f6", BN, 0, simple);
	hash_test_aux("f3g1", WN, 0, simple);
	hash_test_aux("f6g8", BN, 0, simple);

	U64 hash2 = gs.hash;

	printf("hash %lld hash2 %lld\n", hash, hash2);
	assert(hash==hash2);

	printf("end hash_test()\n");
}
Exemple #10
0
static char*  isLegal_test() {
	assert(gs.initialized);
	printf("Running isLegal_test\n");
	char fen[] = "rn1qkbnr/ppp2pp1/3p4/4p2p/4P2P/3P3b/PPP2PP1/RNBQKBNR w KQkq - 0 1";
	parseFen(fen);
	int numMoves;
	MOVE moves[MAX_MOVES];
	generateNonCaptures(gs.color, moves, &numMoves, gs.bitboard);

	for (int i=0; i < numMoves; i++)
	{
		MOVE move = moves[i];
		//printf("Testing move ");
		//printMove(move);
		if (!isMoveLegal(move)) {
			printf("Not legal ");
			printMove(move);
			isMoveLegal(move);
		}
		assert( isMoveLegal(move));
	}
	return 0;
}
Exemple #11
0
void consoleLoop(board& b, searchInfo* search) {

	printf("Welcome to PENIQLIOTUV In Console Mode!\n");
	printf("Type help for commands\n\n");

	search->gameMode = CONSOLEMODE;
	search->postThinking = true;
	setbuf(stdin, NULL);
  setbuf(stdout, NULL);

	int depth = MAXDEPTH, moveTime = 3000;
	int engineSide = BOTH;
	int move = NOMOVE;
	char inBuf[80], command[80];

	engineSide = BLACK;
	parseFen(START_FEN, b);

	while(true) {
		fflush(stdout);
		if(b.side == engineSide && checkResult(b) == false) {
			search->startTime = getTime();
			search->depth = depth;

			if(moveTime != 0) {
				search->timeSet = true;
				search->stopTime = search->startTime + moveTime;
			}
			searchPosition(b, search);
		}
		std::cout << std::endl << "PENIQLIOTUV > ";

		memset(&inBuf[0], 0, sizeof(inBuf));
		fflush(stdout);
		if (!fgets(inBuf, 80, stdin))
		continue;

		sscanf(inBuf, "%s", command);

		if(!strcmp(command, "help")) {
			printf("Commands:\n");
			printf("quit - quit game\n");
			printf("force - computer will not think\n");
			printf("print - show board\n");
			printf("post - show thinking\n");
			printf("nopost - do not show thinking\n");
			printf("new - start new game\n");
			printf("go - set computer thinking\n");
			printf("depth x - set depth to x\n");
			printf("time x - set thinking time to x seconds (depth still applies if set)\n");
			printf("view - show current depth and movetime settings\n");
			printf("** note ** - to reset time and depth, set to 0\n");
			printf("enter moves using b7b8q notation\n\n\n");
			continue;
		}

		if(!strcmp(command, "quit")) {
			search->quit = true;
			break;
		}

		if(!strcmp(command, "post")) {
			search->postThinking = true;
			continue;
		}

		if(!strcmp(command, "print")) {
			printBoard(b);
			continue;
		}

		if(!strcmp(command, "nopost")) {
			search->postThinking = false;
			continue;
		}

		if(!strcmp(command, "force")) {
			engineSide = BOTH;
			continue;
		}

		if(!strcmp(command, "view")) {
			if(depth == MAXDEPTH) printf("depth not set ");
			else printf("depth %d",depth);

			if(moveTime != 0) printf(" movetime %ds\n",moveTime/1000);
			else printf(" movetime not set\n");

			continue;
		}

		if(!strcmp(command, "depth")) {
			sscanf(inBuf, "depth %d", &depth);
		  if(depth==0) {
				depth = MAXDEPTH;
			}
			continue;
		}

		if(!strcmp(command, "time")) {
			sscanf(inBuf, "time %d", &moveTime);
			moveTime *= 1000;
			continue;
		}

		if(!strcmp(command, "new")) {
			engineSide = BLACK;
			parseFen(START_FEN, b);
			continue;
		}

		if(!strcmp(command, "go")) {
			engineSide = b.side;
			continue;
		}

		move = parseMove(inBuf, b);
		if(move == NOMOVE) {
			printf("Command unknown:%s\n",inBuf);
			continue;
		}
		makeMove(b, move);
		b.ply=0;
    }
}
Exemple #12
0
void do_eval() {
	char fen[]="2rr3k/pp3pp1/1nNqbN1p/3p4/2pP3P/2P3Q1/PPB5/R4RK1 b - - 0 1";
	parseFen(fen);
	getEvaluation();
}