Esempio n. 1
0
void PerftTest(int depth, S_BOARD *pos) {
	S_MOVELIST list[1];
	int move;
	int MoveNum = 0;
	int start = GetTimeMs();
	long cumnodes, oldnodes;

	ASSERT(CheckBoard(pos));

	PrintBoard(pos);
	printf("\nStarting Test To Depth:%d\n", depth);
	leafNodes = 0;
	
	GenerateAllMoves(pos, list);

	for(MoveNum = 0; MoveNum < list->count; ++MoveNum) {
		move = list->moves[MoveNum].move;
		if(!MakeMove(pos, move))
			continue;

		cumnodes = leafNodes;
		Perft(depth - 1, pos);
		TakeMove(pos);
		oldnodes = leafNodes - cumnodes;
		printf("move %d : %s : %ld\n", MoveNum + 1, PrMove(move), oldnodes);
	}

	printf("\nTest Complete : %ld nodes visited in %dms\n", leafNodes, GetTimeMs() - start);
}
Esempio n. 2
0
uint64_t Perft(Board* board, int depth)
{
	uint64_t total = 0;

	// find all the moves
	Move moveList[100];
	int moveCount = Moves_GetAllMoves(board, moveList);
 
	for (int i = 0; i < moveCount; i++) {
		Move* move = &moveList[i];
		_Bool valid = Board_Make(board, move->From, move->To);
		
		if(!valid)
			continue;

		if(move->Promotion > 0)
			Board_Promote(board, move->To, move->Promotion);

		uint64_t cnt = (depth == 1) ? 1 : Perft(board, depth - 1);
		total += cnt;
		Board_Unmake(board);

		// log data in the top node
		if(Results.StartDepth == depth)
		{
			Results.Entries[Results.EntryCount].Count = cnt;
			Results.Entries[Results.EntryCount].From = move->From;
			Results.Entries[Results.EntryCount].To = move->To;
			Results.EntryCount++;
		}
	}

	return total;
}
Esempio n. 3
0
File: uci.c Progetto: raimarHD/lcec
int perft(char *input, ENGINE_STATE *stat)
{
  int depth = 0;
  sscanf(input, "perft %i", &depth);
  stat->control->init_time = clock();
  unsigned int nodes = Perft(stat->board, depth);
  float ms = (clock() - stat->control->init_time)/CPMS;
  printf("Depth: %i Moves: %i knps: %u\n", depth, nodes, (unsigned int)(nodes/ms));
  return 1;
}
Esempio n. 4
0
PerftResults* Perft_Search(Board* board, int depth)
{
	delete Results.Entries;
	
	Results.Entries = new PerftEntry[200];
	Results.StartDepth = depth;
	Results.EntryCount = 0;
	Results.Total = 0;

	Results.Total = Perft(board, depth);
	return &Results;
}
Esempio n. 5
0
void perftSuiteTest() {
	char const* const filename = "perftsuite.epd";
	FILE* file = fopen(filename, "r");

	if(file == NULL) {
		printf("didnt find file: %s", filename);
		return;
	}

	char line[256];
	char *fen;
	char *depthVal;

	U64 nodes;
	U64 perftResult;
	int depth;
	const char delim[2] = ";";

	S_BOARD board[1];

	while (fgets(line, sizeof(line), file)) {
	 	fen = strtok(line, delim);
	 	parseFEN(fen, board);

	 	printf("\n\nTesting position: \n");
	 	printBoard(board);


	 	depthVal = strtok(NULL, delim);

	 	depth = 1;
	 	nodes = ZERO64;

 		while(depthVal != NULL) {
 			printf("depth %d", depth);
	 		nodes = atoi(depthVal+3);
	 		perftResult = Perft(depth, board);

	 		if(nodes != perftResult) {
	 			printf("\nERROR: expected %"PRIu64"\nresult %"PRIu64"\ndepth %d\n", nodes, perftResult, depth);
	 		}
	 		else {
	 			printf(" ok\n");
	 		}


	 		depthVal = strtok(NULL, delim);
	 		depth++;
	 	}
    }
}
Esempio n. 6
0
File: main.cpp Progetto: niklasf/k2
//--------------------------------
void PerftCommand(std::string in)
{
    if(busy)
        return;
    Timer timer;
    double tick1, tick2, deltaTick;
    timer.start();
    tick1 = timer.getElapsedTimeInMicroSec();

    nodes = 0;
    max_search_depth = atoi(in.c_str());
    Perft(max_search_depth);
    max_search_depth = max_ply;
    tick2 = timer.getElapsedTimeInMicroSec();
    deltaTick = tick2 - tick1;

    std::cout << std::endl << "nodes = " << nodes << std::endl
        << "dt = " << deltaTick / 1000000. << std::endl
        << "Mnps = " << nodes / (deltaTick + 1) << std::endl << std::endl;
}
Esempio n. 7
0
U64 Perft(int depth, S_BOARD *pos) {
	ASSERT(checkBoard(pos));
 
 	S_MOVELIST list[1];
    GenerateAllMoves(pos, list);

    if(depth == 0) {
    	return 1;
    }

    U64 nodes = ZERO64;
    int i;
    for (i = 0; i < list->count; i++) {
    	if (MakeMove(pos, list->moves[i].move)) {
      	  nodes += Perft(depth - 1, pos);
      	  TakeMove(pos);
    	}
    }
    
    return nodes;
}
Esempio n. 8
0
int Perft(POS *p, int ply, int depth) {

  int move = 0;
  int fl_mv_type;
  MOVES m[1];
  UNDO u[1];
  int mv_cnt = 0;

  InitMoves(p, m, 0, 0, ply);

  while (move = NextMove(m, &fl_mv_type)) {

  p->DoMove(move, u);

  if (Illegal(p)) { p->UndoMove(move, u); continue; }

  if (depth == 1) mv_cnt++;
    else          mv_cnt += Perft(p, ply + 1, depth - 1);
    p->UndoMove(move, u);
  }

  return mv_cnt;
}
Esempio n. 9
0
void Perft(int depth, S_BOARD *pos) {
	S_MOVELIST list[1];
	int MoveNum = 0;

	ASSERT(CheckBoard(pos));

	if(depth == 0) {
		leafNodes++;
		return;
	}

	GenerateAllMoves(pos, list);

	for(MoveNum = 0; MoveNum < list->count; ++MoveNum) {
		if(!MakeMove(pos, list->moves[MoveNum].move)) {
			continue;
		}

		Perft(depth - 1, pos);
		TakeMove(pos);
	}

	return;
}
Esempio n. 10
0
void UciLoop(void) {

  char command[4096], token[180], *ptr;
  POS p[1];

  setbuf(stdin, NULL);
  setbuf(stdout, NULL);
  SetPosition(p, START_POS);
  AllocTrans(16);
  for (;;) {
    ReadLine(command, sizeof(command));
    ptr = ParseToken(command, token);

    // checks if Rodent should play with an opening book
    // UseBook remains for backward compatibly
    if ((strstr(command, "setoption name OwnBook value")) || (strstr(command, "setoption name UseBook value")))
      use_book = (strstr(command, "value true") != 0);
    if (strstr(command, "setoption name UCI_LimitStrength value"))
      Param.fl_weakening = (strstr(command, "value true") != 0);

    if (strcmp(token, "uci") == 0) {
      printf("id name %s\n", PROG_NAME);
      printf("id author Pawel Koziol (based on Sungorus 1.4 by Pablo Vazquez)\n");
      printf("option name Hash type spin default 16 min 1 max 4096\n");
      printf("option name Clear Hash type button\n");
      if (panel_style > 0) {
        printf("option name PawnValue type spin default %d min 0 max 1200\n", Param.pc_value[P]);
        printf("option name KnightValue type spin default %d min 0 max 1200\n", Param.pc_value[N]);
        printf("option name BishopValue type spin default %d min 0 max 1200\n", Param.pc_value[B]);
        printf("option name RookValue type spin default %d min 0 max 1200\n", Param.pc_value[R]);
        printf("option name QueenValue type spin default %d min 0 max 1200\n", Param.pc_value[Q]);
        
		printf("option name KeepPawn type spin default %d min -200 max 200\n", Param.keep_pc[P]);
        printf("option name KeepKnight type spin default %d min -200 max 200\n", Param.keep_pc[N]);
        printf("option name KeepBishop type spin default %d min -200 max 200\n", Param.keep_pc[B]);
        printf("option name KeepRook type spin default %d min -200 max 200\n", Param.keep_pc[R]);
        printf("option name KeepQueen type spin default %d min -200 max 200\n", Param.keep_pc[Q]);

        printf("option name BishopPair type spin default %d min -100 max 100\n", Param.bish_pair);
        if (panel_style == 2)
			printf("option name KnightPair type spin default %d min -100 max 100\n", Param.knight_pair);
           printf("option name ExchangeImbalance type spin default %d min -100 max 100\n", Param.exchange_imbalance);
        printf("option name KnightLikesClosed type spin default %d min 0 max 10\n", Param.np_bonus);
        if (panel_style == 2)
           printf("option name RookLikesOpen type spin default %d min 0 max 10\n", Param.rp_malus);

        printf("option name Material type spin default %d min 0 max 500\n", Param.mat_perc);
        printf("option name OwnAttack type spin default %d min 0 max 500\n", dyn_weights[DF_OWN_ATT]);
        printf("option name OppAttack type spin default %d min 0 max 500\n", dyn_weights[DF_OPP_ATT]);
        printf("option name OwnMobility type spin default %d min 0 max 500\n", dyn_weights[DF_OWN_MOB]);
        printf("option name OppMobility type spin default %d min 0 max 500\n", dyn_weights[DF_OPP_MOB]);

        printf("option name KingTropism type spin default %d min -50 max 500\n", weights[F_TROPISM]);
        printf("option name PiecePlacement type spin default %d min 0 max 500\n", Param.pst_perc);
        printf("option name PiecePressure type spin default %d min 0 max 500\n", weights[F_PRESSURE]);
        printf("option name PassedPawns type spin default %d min 0 max 500\n", weights[F_PASSERS]);
        printf("option name PawnStructure type spin default %d min 0 max 500\n", weights[F_PAWNS]);

		printf("option name Outposts type spin default %d min 0 max 500\n", weights[F_OUTPOST]);
        printf("option name Lines type spin default %d min 0 max 500\n", weights[F_LINES]);
        if (panel_style == 2) {
          printf("option name PawnShield type spin default %d min 0 max 500\n", Param.shield_perc);
          printf("option name PawnStorm type spin default %d min 0 max 500\n", Param.storm_perc);
        }
        printf("option name PstStyle type spin default %d min 0 max 2\n", Param.pst_style);
		printf("option name MobilityStyle type spin default %d min 0 max 1\n", Param.mob_style);

        if (panel_style == 2) {
          printf("option name DoubledPawnMg type spin default %d min -100 max 0\n", Param.doubled_malus_mg);
          printf("option name DoubledPawnEg type spin default %d min -100 max 0\n", Param.doubled_malus_eg);
          printf("option name IsolatedPawnMg type spin default %d min -100 max 0\n", Param.isolated_malus_mg);
          printf("option name IsolatedPawnEg type spin default %d min -100 max 0\n", Param.isolated_malus_eg);
          printf("option name IsolatedOnOpenMg type spin default %d min -100 max 0\n", Param.isolated_open_malus);
          printf("option name BackwardPawnMg type spin default %d min -100 max 0\n", Param.backward_malus_base);
          printf("option name BackwardPawnEg type spin default %d min -100 max 0\n", Param.backward_malus_eg);
          printf("option name BackwardOnOpenMg type spin default %d min -100 max 0\n", Param.backward_open_malus);
        }

        // Strength settings - we use either Elo slider with an approximate formula
        // or separate options for nodes per second reduction and eval blur

        if (fl_elo_slider == 0) {
          printf("option name NpsLimit type spin default %d min 0 max 5000000\n", Timer.nps_limit);
          printf("option name EvalBlur type spin default %d min 0 max 5000000\n", Param.eval_blur);
        } else {
          printf("option name UCI_LimitStrength type check default false\n");
          printf("option name UCI_Elo type spin default %d min 800 max 2800\n", Param.elo);
        }

        printf("option name Contempt type spin default %d min -250 max 250\n", Param.draw_score);
        printf("option name SlowMover type spin default %d min 10 max 500\n", time_percentage);
        printf("option name Selectivity type spin default %d min 0 max 200\n", hist_perc);
        printf("option name OwnBook type check default true\n");
        printf("option name GuideBookFile type string default guide.bin\n");
        printf("option name MainBookFile type string default rodent.bin\n");
        printf("option name BookFilter type spin default %d min 0 max 5000000\n", Param.book_filter);
     }

     if (panel_style == 0) {
        printf("option name PersonalityFile type string default rodent.txt\n");
        printf("option name OwnBook type check default true\n");
        if (fl_separate_books) {
          printf("option name GuideBookFile type string default guide.bin\n");
          printf("option name MainBookFile type string default rodent.bin\n");
        }
     }

      printf("uciok\n");
    } else if (strcmp(token, "isready") == 0) {
      printf("readyok\n");
    } else if (strcmp(token, "setoption") == 0) {
      ParseSetoption(ptr);
    } else if (strcmp(token, "position") == 0) {
      ParsePosition(p, ptr);
    } else if (strcmp(token, "perft") == 0) {
      ptr = ParseToken(ptr, token);
    int depth = atoi(token);
    if (depth == 0) depth = 5;
    Timer.SetStartTime();
    nodes = Perft(p, 0, depth);
#if defined _WIN32 || defined _WIN64 
    printf (" perft %d : %I64d nodes in %d miliseconds\n", depth, nodes, Timer.GetElapsedTime() );
#else
    printf(" perft %d : %lld nodes in %d miliseconds\n", depth, nodes, Timer.GetElapsedTime());
#endif
    } else if (strcmp(token, "print") == 0) {
      PrintBoard(p);
    } else if (strcmp(token, "eval") == 0) {
      SetAsymmetricEval(p->side);
      Eval.Print(p);
    } else if (strcmp(token, "step") == 0) {
      ParseMoves(p, ptr);
    } else if (strcmp(token, "go") == 0) {
      ParseGo(p, ptr);
    } else if (strcmp(token, "bench") == 0) {
      ptr = ParseToken(ptr, token);
      Bench(atoi(token));
    } else if (strcmp(token, "quit") == 0) {
      return;
    }
  }
}