path *spreadExecSearchAlgorithm::GetPath(GraphAbstraction *_aMap, node *from, node *to, reservationProvider *_rp)
{
	setTargets(_aMap, from, to, _rp);
	path *p;
	while ((p = think()) == 0) {}
	return p;
}
Example #2
0
void Zombie::prepare(double cx, double cy, Radar *smells, Radar * sounds) {
	double smx, smy, sox, soy;
	bool smv, sov;
	smells->getValue(x, y, smx, smy, smv);
	sounds->getValue(x, y, sox, soy, sov);
	double v1x, v1y, v2x, v2y;
	v1x = v1y = v2x = v2y = 0;
	if (smv) {
		v1x = smx - x;
		v1y = smy - y;
	}
	if (sov) {
		v2x = sox - x;
		v2y = soy - y;
	}
	for (int i = 0; i < output.size(); ++i) {
		input[i] = output[i];
	}
	input[4] = x - cx;
	input[5] = y - cy;
	input[6] = v1x;
	input[7] = v1y;
	input[8] = v2x;
	input[9] = v2y;
	for (int i = 0; i < input.size(); ++i) {
		if (!std::isfinite(input[i])) log(VERBOSE_ERRORS, "BAD INPUT %d", i);
	}
	think();
}
Example #3
0
void* philoT(void *philoID){
	unsigned int myID = *((unsigned int *)philoID);
	//printf("%i\n", myID);
	int ready = 1;
	int totalEat = 0;
	//printf("%i\n", myID);
	while(totalEat < 20){
		//printf("Philo %d created and waiting for chopsticks\n", myID);
		//fflush(stdout);
		while(ready) {
			ready = acquire(myID);
			sleep(1);
		}
		//printf("Philo %d has chopsticks, running eat function\n", myID);
		//fflush(stdout);
		totalEat += eat(myID);
		printf(" ***** Philo %d has eaten for %d seconds *****\n", myID, totalEat);
		fflush(stdout);
		pthread_mutex_unlock(&chopstick[myID]);
		pthread_mutex_unlock(&chopstick[(myID + 1) % 5]);
		//printf("Philo %d is thinking\n", myID);
		//fflush(stdout);
		think(myID);	
		//printf("Philo %d is done thinking\n", myID);
		fflush(stdout);
	}
	printf("Philo %d has finished eating and has left the table.\n", myID);
	return 0;
}
Example #4
0
void PlayerPanel::think()
{
    UI::Base::think();

    auto game = Game::getInstance();

    for (auto it = _ui.begin(); it != _ui.end(); ++it)
    {
        (*it)->think();
    }

    // object in hand
    if (auto item = game->player()->currentHandSlot())
    {
        auto itemUi = item->inventoryDragUi();
        itemUi->think();
    }

    if (_scrollingLogTimer && (SDL_GetTicks() > _scrollingLogTimer + 150)
        && ((_scrollingLog < 0 && _messageLog->lineOffset() > 0)
            || (_scrollingLog > 0 && _messageLog->lineOffset() < _messageLog->numLines() - 6)))
    {
        _messageLog->setLineOffset(_messageLog->lineOffset() + _scrollingLog);
        _scrollingLogTimer = SDL_GetTicks();
    }
}
Example #5
0
void philosopher(int i)
{
    while(TRUE)
    {
        think();
    }
}
void	*start_meeting(void *p)
{
  unsigned int	rcs;
  unsigned int	lcs;
  t_sceptiques	*philosopher;

  philosopher = (t_sceptiques*)p;
  while (philosopher->rice)
    {
      pthread_mutex_lock(&g_m);
      lcs = g_chopsticks[philosopher->id];
      rcs = g_chopsticks[RCS(philosopher->id)];
      if (philosopher->status != EATING && lcs == 0 && rcs == 0)
	eat(philosopher);
      else if (philosopher->status != EATING &&
	       philosopher->status != THINKING &&
	       lcs == 0)
	think(philosopher);
      else
	rest(philosopher);
    }
  philosopher->status = LEFT;
  pthread_exit(NULL);
  return 0;
}
Example #7
0
void bench()
{
	int i;
	int t[3];
	double nps;

	/* setting the position to a non-initial position confuses the opening
	   book code. */
	close_book();

	for (i = 0; i < 64; ++i) {
		color[i] = bench_color[i];
		piece[i] = bench_piece[i];
	}
	side = LIGHT;
	xside = DARK;
	castle = 0;
	ep = -1;
	fifty = 0;
	ply = 0;
	hply = 0;
	set_hash();
	print_board();
	max_time = 1 << 25;
	max_depth = 5;
	for (i = 0; i < 3; ++i) {
		think(1);
		t[i] = get_ms() - start_time;
		printf("Time: %d ms\n", t[i]);
	}
	if (t[1] < t[0])
		t[0] = t[1];
	if (t[2] < t[0])
		t[0] = t[2];
	printf("\n");
	printf("Nodes: %d\n", nodes);
	printf("Best time: %d ms\n", t[0]);
	if (!ftime_ok) {
		printf("\n");
		printf("Your compiler's ftime() function is apparently only accurate\n");
		printf("to the second. Please change the get_ms() function in main.c\n");
		printf("to make it more accurate.\n");
		printf("\n");
		return;
	}
	if (t[0] == 0) {
		printf("(invalid)\n");
		return;
	}
	nps = (double)nodes / (double)t[0];
	nps *= 1000.0;

	/* Score: 1.000 = my Athlon XP 2000+ */
	printf("Nodes per second: %d (Score: %.3f)\n", (int)nps, (float)nps/243169.0);

	init_board();
	open_book();
	gen();
}
Example #8
0
void *dining (int n) {
	while(1) {
		think(n);
		printf("Philosopher #%d is hungry...\n", n);
		eat(n);
		printf("Philosopher #%d finished eating\n", n);
	}
}
Example #9
0
void Control::calculate()
{
    STACKTRACE;

    if (!exists())
        return;

    target_stuff();

    if (ship) {
        if (!ship->exists() || (ship->death_counter != -1)) {
            //message.print(5000, 12, "Ship died in frame %d", game->frame_number);
            select_ship( NULL, NULL);
        }
        else keys = think();
    }

    if (!ship) {
        keys = 0;
        if (temporary)
            state = 0;
    }

    if (channel != Game::channel_none) {
        //prediction stuff
        _prediction_keys[_prediction_keys_index] = keys;
        _prediction_keys_index = (_prediction_keys_index + 1) & (_prediction_keys_size-1);

        //network prep for dieing (set state to unbuffering)
        if (!ship && temporary && (already > 0)) already = -already;

        //network traffic
        int lf = game->lag_frames;
        if (0) ;
        else if (already < 0) {
            //unbuffering
            game->log->unbuffer(channel + Game::_channel_buffered, &keys, sizeof(KeyCode));
            keys = intel_ordering_short(keys);
            already += 1;
        }
        else if (already < lf) {
            //buffering
            keys = intel_ordering_short(keys);
            game->log->buffer(channel + Game::_channel_buffered, &keys, sizeof(KeyCode));
            keys = intel_ordering_short(keys);
            already += 1;
        }
        else if (already > lf) {
            //stupid error check
            tw_error("Control::calculate() - inconcievable!");
        }						 //stable, perform no action
        else {
            game->log_short(channel + Game::_channel_buffered, keys);
        }
    }

    return;
}
Example #10
0
void *philosopher(int *j){
  int i=*j;
  while(1){
    think(i);
    take_fork(i);
    eat(i);
    leave_fork(i);
  }
}
Example #11
0
//------------------------------------------------------------------------------
Position *repl_think(Position *self) {
    Move move = think();
    if (move) {
        char buffer[512];
        self = make_move(self, move);
        printf("%s\n", position_string(self, buffer));
    }
    return self;
}
Example #12
0
unsigned int CCreature::act()
{
    if(creatures_map[x + (y << 8)] != this)
    {
        delete this;
        return 0;
    }
    return think();
}
Example #13
0
void autoget(int *x, int *y)
{
	think();
	print_score();
	getmax();
	*x = maxpoint.row;
	*y = maxpoint.col;
	printf("Player 2 : %d %d\n", *x, *y);
}
Example #14
0
//--------------------------------------------------------------
//
// Name:        Evaluate()
// Class:       CloseInOnEnemyWhileFiringWeapon
//
// Description: Update for this behavior -- called every server frame
//
// Parameters:  Actor &self -- Actor executing this behavior
//
// Returns:     BehaviorReturnCode_t
//
//--------------------------------------------------------------
BehaviorReturnCode_t CloseInOnEnemyWhileFiringWeapon::Evaluate( Actor & )
{

	BehaviorReturnCode_t stateResult;

	think();

	switch ( _state )
		{
		//---------------------------------------------------------------------
		case CIWF_APPROACH_SETUP_APPROACH:
		//---------------------------------------------------------------------
			stateResult = evaluateStateSetupApproach();
			if ( stateResult == BEHAVIOR_FAILED )
				transitionToState( CIWF_FAILED );

			if ( stateResult == BEHAVIOR_SUCCESS )
				transitionToState( CIWF_APPROACH_FIRE );
		break;

		//---------------------------------------------------------------------
		case CIWF_APPROACH_FIRE:
		//---------------------------------------------------------------------
			stateResult = evaluateStateApproachFire();
			if ( stateResult == BEHAVIOR_FAILED )
				transitionToState( CIWF_FAILED );

			if ( stateResult == BEHAVIOR_SUCCESS )
				transitionToState( CIWF_APPROACH_FIRE_PAUSE );
		break;		

		//---------------------------------------------------------------------
		case CIWF_APPROACH_FIRE_PAUSE:
		//---------------------------------------------------------------------
			stateResult = evaluateStateApproachFirePause();
			if ( stateResult == BEHAVIOR_FAILED )
				transitionToState( CIWF_FAILED );

			if ( stateResult == BEHAVIOR_SUCCESS )
				transitionToState( CIWF_APPROACH_FIRE );
		break;	

		//---------------------------------------------------------------------
		case CIWF_SUCCESS:
		//---------------------------------------------------------------------
			return BEHAVIOR_SUCCESS;
		break;

		//---------------------------------------------------------------------
		case CIWF_FAILED:
		//---------------------------------------------------------------------
			return BEHAVIOR_FAILED;
		break;
		}
	
	return BEHAVIOR_EVALUATING;
}
Example #15
0
    void run()
    {
        std::atomic<unsigned int> p1, p2;
        bool canEat(false);

        while (!stopflag.load()) {
            think();
            p1 = leftfork->get_priority();
            p2 = rightfork->get_priority();
            // Get status
            shed_mutex.lock();
            canEat = shed->get_status(id);
            shed_mutex.unlock();

            if (!canEat && !stopflag.load()) {
                while (!stopflag) {
                    shed_mutex.lock();
                    if (shed->get_status(id)) {
                        shed_mutex.unlock();
                        break;
                    } else {
                        shed_mutex.unlock();
                        std::this_thread::yield();
                    }
                }
            }
            if (stopflag.load()) {
                break;
            }

            if (p1 < p2) {
                leftfork->take();
                if (debugflag) std::printf("[%2d] took left fork\n", id);
                rightfork->take();
                if (debugflag) std::printf("[%2d] took right fork\n", id);
                eat();
                rightfork->put();
                if (debugflag) std::printf("[%2d] put right fork\n", id);
                leftfork->put();
                if (debugflag) std::printf("[%2d] put left fork\n", id);
            } else {
                rightfork->take();
                if (debugflag) std::printf("[%2d] took right fork\n", id);
                leftfork->take();
                if (debugflag) std::printf("[%2d] took left fork\n", id);
                eat();
                leftfork->put();
                if (debugflag) std::printf("[%2d] put left fork\n", id);
                rightfork->put();
                if (debugflag) std::printf("[%2d] put right fork\n", id);
            }

            shed_mutex.lock();
            shed->finished(id);
            shed_mutex.unlock();
        }
    }
Example #16
0
	void Enemy::update( double _deltaTime)
	{
		if(m_currentThinkSleep > m_maxThinkSleep)
		{
			resetThinkSleep();
			think();
		}
		m_currentThinkSleep+=_deltaTime;
		GameObject::update(_deltaTime);
	}
Example #17
0
void CChange::OnSet() 
{
 CString dst ;
 CString val;
 name.GetWindowText(dst);
 value.GetWindowText(val);
 CString ass = dst + "=" + val;
 CString b = togdb_eval_as_string ((const char *)ass);
 think();
}
Example #18
0
BOOL CChange::OnInitDialog() 
{
 CDialog::OnInitDialog();
 
 // TODO: Add extra initialization here
 name.SetWindowText(sname);	
 think();
 return TRUE;			// return TRUE unless you set the focus to a control
 // EXCEPTION: OCX Property Pages should return FALSE
}
Example #19
0
void philosoper(int i) { // i: philospher number, from 0 to 4
	while (true) {
		think();  // philisopher is thinking
		take_fork(i); // take left fork
		take_for((i + 1) % N); // take right fork; % is modulo operator
		eat(); // yum-yum, spaghetti
		put_fork(i); // put left fork back on the table
		put_fork((i + 1) % N); // put right fork back on the table
	}
}
Example #20
0
void* main_loop(void* phil) {

	while(1) {
		hungry((int)phil);
		for(i = 0; i<99999999; i++);
		think((int)phil);
		for(i = 0; i<99999999; i++);

	}		
}
Example #21
0
//--------------------------------------------------------------
// Name:        Evaluate()
// Class:       GotoCurrentHelperNode
//
// Description: Evaluates the behavior
//
// Parameters:  Actor &self -- The actor executing this behavior
//
// Returns:     BehaviorReturnCode_t 
//--------------------------------------------------------------
BehaviorReturnCode_t GotoCurrentHelperNode::Evaluate( Actor & )
{
	BehaviorReturnCode_t stateResult;

	think();
	
	switch ( _state )
		{
		//---------------------------------------------------------------------
		case GOTO_HNODE_FIND_NODE:
		//---------------------------------------------------------------------
			stateResult = evaluateStateFindNode();

			if ( stateResult == BEHAVIOR_SUCCESS )
				transitionToState( GOTO_HNODE_MOVE_TO_NODE );
			if ( stateResult == BEHAVIOR_FAILED )
				transitionToState( GOTO_HNODE_FAILED );
		break;

		//---------------------------------------------------------------------
		case GOTO_HNODE_MOVE_TO_NODE:
		//---------------------------------------------------------------------
			stateResult = evaluateStateMoveToNode();

			if ( stateResult == BEHAVIOR_FAILED )
				transitionToState( GOTO_HNODE_FAILED );
			
			if ( stateResult == BEHAVIOR_SUCCESS )
				transitionToState( GOTO_HNODE_SUCCESS );
		break;


		//---------------------------------------------------------------------
		case GOTO_HNODE_SUCCESS:
		//---------------------------------------------------------------------
			return BEHAVIOR_SUCCESS;

		break;


		//---------------------------------------------------------------------
		case GOTO_HNODE_FAILED:
		//---------------------------------------------------------------------
			return BEHAVIOR_FAILED;

		break;


		}
	

	return BEHAVIOR_EVALUATING;   

}
Example #22
0
void* philosopher(void* i){
	int p = (int) i;
	while(1){
		think(p);
	    take_forks(p);
	 	eat(p);
		put_forks(p);

	}
	return 0;
}
Example #23
0
int p_five()
{
   int i=0;
   srandom(time(0));

restart:
  setutmpmode(FIVE);
  showtitle("天地五子棋", BOARDNAME);

  outs("┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐\n");
for(sum=0;sum<20;sum++)
  outs("├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤\n");
  outs("└┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┘\n");


   gotoxy(48,1); outs("=-=-=-=-=-=-=-=-=-=");
   gotoxy(48,2); outs("|   天地五子棋    |");
   gotoxy(48,3); outs("=-=-=-=-=-=-=-=-=-=");
   who(0); who(1);

   gotoxy(45,17); outs(" ↓↑→← >> 控制方向");
   gotoxy(45,18); outs("  空白鍵  >> 確定");
   gotoxy(45,19); outs("     2    >> 二號玩家換人");
   gotoxy(45,20); outs("     b    >> 悔棋");
   gotoxy(45,21); outs("     r    >> 重新開始");
   gotoxy(45,22); outs("     q    >> 離開");

   for(m=1;m<22;m++)
    for(n=1;n<22;n++)
      chess[m][n]=0;

   sum=fturn=0;
   m=n=mm=nn=11;
   for(;;)
   {
     if(role[fturn]==1)
     {
       int tmp=fplayer(fturn+1);
       if(tmp==1) goto restart;
       if(tmp==2) return;
     }
     else
     {
       int hk=think(fturn+1);
       if(hk)
       {
         i=show_win(hk);
         if(i=='q'||i=='n') return;
         goto restart;
       }
     }
     fturn=abs(fturn-1);
   }
}
Example #24
0
File: C.c Project: ishiikurisu/PC
int main(int argc, char const *argv[]) {
    int t, T, N, K, M, m;

    for (t = 1; t <= T; t++)
    {
        scanf("%d %d", &N, &K);
        (N <= K)? M = m = 0: think(N, K, &M, &m);
        printf("case #%d: %d %d\n", t, M, n)
    }

    return 0;
}
void philosopher(void){
	int32_t i;

	i = HF_CurrentTaskId() - 1;

	while (1){
		think();
		take_forks(i);
		eat();
		put_forks(i);
	}
}
Example #26
0
void bot(int lX,int lY)
{
    int nbAv = 0;
    int xL, yL, xS, yS;
    int res = 0;
    for(xL=0;xL<3;++xL)
        for(yL=0;yL<3;++yL)
            if(bigB[xL][yL]==0)
                for(xS=0;xS<3;++xS)
                    for(yS=0;yS<3;++yS)
                        if(mat4[xL][yL][xS][yS]==0)
                            ++nbAv;
    
    for (;level<=LEVELMAX&&res!=1000000&&res!=-1000000;++level) {
        res = think(1,lX,lY,0,1000000);
    }

    if (res==-1000000)
        for(--level;res==-1000000;--level)
            res = think(1,lX,lY,0,1000000);
}
Example #27
0
void philosopher (void *data)
{
	int i;

	i = (int) data;
	for (;;) {
		think (i);
		get_forks (i, &fork [i], &fork [(i+1) % N]);
		eat (i);
		put_forks (&fork [i], &fork [(i+1) % N]);
	}
}
Example #28
0
int main(void)
{
    int i;
    enum States state = NONE;

    for(i = 0; i != 10; i++) {
        state = think(state);
        printf("%d\n", state);
    }

    return 0;
}
Example #29
0
// prepares to play the disc
void ldp::pre_play()
{
//	Uint32 cpu_hz;	// used to calculate elapsed cycles

	// safety check, if they try to play without checking the search result ...
	// THIS SAFETY CHECK CAN BE REMOVED ONCE ALL LDP DRIVERS HAVE BEEN CONVERTED OVER TO NON-BLOCKING SEEKING
	if (m_status == LDP_SEARCHING)
	{
		printline("LDP : tried to play without checking to see if we were still seeking! that's bad!");
		
		// if this ever happens, it is a bug in Daphne, so log it
		m_bug_log.push_back("LDP.CPP, pre_play() : tried to play without checking to see if we're still seeking!");
		
		return;
	}

	// we only want to refresh the frame calculation stuff if the disc is
	// not already playing
	if (m_status != LDP_PLAYING)
	{
		m_uElapsedMsSincePlay = 0;	// by definition, this must be reset since we are playing
		m_uBlockedMsSincePlay = 0;	// " " "
		m_iSkipOffsetSincePlay = 0;	// by definition, this must be reset since we are playing
		m_uCurrentOffsetFrame = 0;	// " " "
		m_uMsFrameBoundary = 1000000 / g_game->get_disc_fpks();	// how many ms must elapse before the first frame ends, 2nd frame begins

		// VLDP needs its timer reset with the rest of these timers before its play command is called.
		// Otherwise, it will think it's way behind and will try to catch up a bunch of frames.
		think();

		// if the disc may need to take a long time to spin up, then pause the cpu timers while the disc spins up
		if (m_status == LDP_STOPPED)
		{
			cpu_pause();
			m_play_time = play();
			cpu_unpause();
		}
		else
		{
			m_play_time = play();
		}

		m_bWaitingForVblankToPlay = true;	// don't start counting frames until the next vsync
		m_status = LDP_PLAYING;
	}
	else
	{
		printline("LDP : disc is already playing, play command ignored");
	}

	printline("Play");	// moved to the end of the function so as to not cause lag before play command could be issued
}
Example #30
0
int AI::thinkWrapper(const Field &self, const Field &enemy)
{
	Time.reset();
	stop = false;
	calls_count = 0;
	int timeLimit = 999999;

	if (enemy.flag(RENSA))// 敵が連鎖中
	{
		// 連鎖が起こりきるまでの時間と思えばよい
		timeLimit = (enemy.chainMax() - enemy.chain()) * (CHAINTIME + FALLTIME);
	}

	LightField s(self);
	LightField e(enemy);

	// 世代を進める
	TT.newSearch();

	hash_hit = 0;

	int depth;
	Move best_move;

	// 思考開始
	for (Depth d = ONE_PLY; d <= depth_max_; ++d)
	{
		think(s, e, d, timeLimit);
		best_move = stop ? best_move : best_[d];
		MyOutputDebugString("depth = %d, stop = %d\n", d, stop);

		if (stop)
			break;
	}

	// ベストな手はbest_[0]にはいっている
	// それを操作に変換
	if (easy_ == 0)
	{
		operate_.generate(best_move, self);
	}
	else if (easy_ == 1)
	{
		operate_.easyGenerate(best_move, self);
	}
	else if (easy_ == 2)
	{
		operate_.veryEasyGenerate(best_move, self);
	}
	
	return 0;
}