Esempio n. 1
0
BOOL	WINAPI	DllMain (HANDLE hInst, 
						ULONG ul_reason_for_call,
						LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
			PyWin_DLLhModule = hInst;
			initall();
			break;
		case DLL_PROCESS_DETACH:
			break;
	}
	return TRUE;
}
Esempio n. 2
0
int main()
{
    struct mystack s;
    int a = 10;
    int b = 20;
    int c = 30;
    int *p;
    initall(&s);
    printf("&a:0x%x\n&b:0x%x\n&c:0x%x\n",&a,&b,&c);
    push(&s,&a);
    push(&s,&b);
    push(&s,&c);
    while(!isempty(&s))
    {
        p = pop(&s);
        printf("0x%x,%d\n",p,*p);
    }
    return 0;
}
Esempio n. 3
0
static int		begin(t_ai *all, char *file)
{
	int		fd;
	int		ans;

	fd = (file ? open(file, O_RDONLY) : 0);
	if (fd == -1)
		return (1);
	ans = initall(all, fd);
	if (ans == 0)
	{
		play(all);
		free(all->map);
		free(all->inverted);
	}
	if (file)
		close(fd);
	return (ans);
}
Esempio n. 4
0
unsigned getcircles(unsigned base_num, unsigned & circ_num, unsigned * circles)
{
	char num_check[MAX_NUMBER/8+1];
	unsigned a,b,c;
	if ((base_num%2==0)||(base_num<4)||(base_num>MAX_NUMBER)) return 0;
	circ_num = 0;
	initall(num_check,circles);
	do {
		for(a=0;bread(num_check,a)==1;a++) ;
		if (a>=base_num) break;
		b = a;c = 0;
		do {
			circles[circ_num*MAX_NUM_PER_CIRC+c] = a;
			bwrite(num_check,a,1);
			a = (a*2)%base_num; c++;
		} while (a != b);
		circ_num++;
	} while (circ_num); // This loop will stop only with the break statement;
	return 1;
}
Esempio n. 5
0
File: nmm.c Progetto: ryanakca/nmm
/*
 * The Big Cheese
 */
int
main(int argc, char *argv[])
{
  scrgame *sg;
  int c;
  char *bn = basename(argv[0]);
  if (!bn || errno) {
    /* basename can return a NULL pointer, causing a segfault on
       strncmp below */
    errx(errno, "Something went wrong in determining the %s",
	 "filename by which nmm was called.");
  }
  if (argc != 1) {
    errx(EINVAL, "%s doesn't take any arguments.", bn);
  }
  if ((sg = malloc(sizeof(*sg)))) {
    if ((sg->game = malloc(sizeof(*sg->game)))) {
      point *board;
      if ((board = calloc(ROWS * COLS, sizeof(*board)))) {
	int r;
	for (r = 0; r < ROWS; r++) {
	  for (c = 0; c < COLS; c++) {
	    sg->game->board[r][c] = board++;
	  }
	}
      } else {
	errx(errno, "Unable to allocate memory for the board");
      }
    } else {
      errx(errno, "Unable to allocate memory for the game");
    }
  } else {
    errx(errno, "Unable to allocate memory");
  }
  initscr();
  cbreak();
  keypad(stdscr, TRUE);
  clear();
  printw("Display instructions? (y/n) ");
  refresh();
  c = getch();
  c = tolower(c);
  if (c == 'y') {
    printinstrs(sg);
  }
  clear();
  noecho();
  refresh();
  if (strncmp("tmm", bn, 3) == 0) {
    c = TMM;
  } else if (strncmp("twmm", bn, 4) == 0) {
    c = TWMM;
  } else {
    c = NMM;
  }
  for (;;) {
    initall(sg, c);
    refresh();
    phaseone(sg);
    phasetwothree(sg);
    if (!gameend(sg)) {
      break;
    }
  }
  refresh();
  endwin();
  return 0;
}
Esempio n. 6
0
void initialize()
{
	initall();
}
Esempio n. 7
0
void main(void)
{
    OSCCON = 0b01100001;  //4 MHz
    OSCTUNE= 0;
    //INTCON = 0;
    //Count1micros = 0;
    Count4ms = 0;
    //Delay(2);
    initports();
    USARTinit();
//USARTWriteString("Serial init\n\rchecking for config enable...\n\r");
    while(SERIALDETECT == 1)
    {
        //USARTWriteString("\n\rEnter Config\n\r");USARTWriteString(strnw);
        //USARTWriteString("\n\rEnter ");
        getData();
    }
    ENB = 0;
    nSLEEP = 1;
    DECAY = 1;
    initall();
    int i;
    for( i = 0 ; i < 4 ; i++)
    {
        CurTotNoStep = 270; CurStepDir = ANTICLKVIZ; CurStepMode = MIC32STEP ;

        Make_Table( CurTotNoStep );
        while(!MotionComplete);
    }

    while(Crankflg == 0)
    {
        get_Actrpm();
        Calc_SetPoint();
        USARTWriteChar('N');USARTWriteString(strnw);
    }

    for( i = 0 ; i < 4 ; i++)
    {
        CurTotNoStep = 225; CurStepDir = CLKVIZ; //CurStepMode = MIC32STEP ;
        Make_Table( CurTotNoStep );
        while(!MotionComplete);
    }
        //MoveMotor();
    while(1)
    {
        if(MS100Flag)
        {
            MS100Flag = 0;
            Calc_Err(PIDCycleNo);
            
            if((PIDCycleNo >= 2) /*&& Crankflg*/ )
            {
                Calc_PID_op();
            }//USARTWriteString("100 ms done \n\r");
            /*else
            {
                USARTWriteChar('N');USARTWriteString(strnw);
                //USARTWriteString("no crank\n\r");
            }*/
        }
    }
}
Esempio n. 8
0
int BiDirAStar:: bidir_astar(edge_astar_t *edges, size_t edge_count, int maxNode, int start_vertex, int end_vertex,
				path_element_t **path, size_t *path_count, char **err_msg)
{
	max_node_id = maxNode;
	max_edge_id = -1;
	
	// Allocate memory for local storage like cost and parent holder
	initall(maxNode);

	// construct the graph from the edge list, i.e. populate node and edge data structures
	construct_graph(edges, edge_count, maxNode);
	
	m_lStartNodeId = start_vertex;
	m_lEndNodeId = end_vertex;

	// int nodeCount = m_vecNodeVector.size();
	
	MinHeap fque(maxNode + 2);
	MinHeap rque(maxNode + 2);
	//std::priority_queue<PDI, std::vector<PDI>, std::greater<PDI> > fque;
	//std::priority_queue<PDI, std::vector<PDI>, std::greater<PDI> > rque;
	
	m_vecPath.clear();

	// Initialize the forward search
	m_pFParent[start_vertex].par_Node = -1;
	m_pFParent[start_vertex].par_Edge = -1;
	m_pFCost[start_vertex] = 0.0;
	fque.push(std::make_pair(0.0, start_vertex));

	// Initialize the reverse search
	m_pRParent[end_vertex].par_Node = -1;
	m_pRParent[end_vertex].par_Edge = -1;
	m_pRCost[end_vertex] = 0.0;
	rque.push(std::make_pair(0.0, end_vertex));

	// int new_node;
	int cur_node;
	// int dir;
/*
	The main loop. The algorithm is as follows:
	1. IF the sum of the current minimum of both heap is greater than so far found path, we cannot get any better, so break the loop.
	2. IF the reverse heap minimum is lower than the forward heap minimum, explore from reverse direction.
	3. ELSE explore from the forward directtion.
*/

	while(!fque.empty() && !rque.empty())
	{
		PDI fTop = fque.top();
		PDI rTop = rque.top();
		if(m_pFCost[fTop.second] + m_pRCost[rTop.second] > m_MinCost) //We are done, there is no path with lower cost
			break;

		if(rTop.first < fTop.first) // Explore from reverse queue
		{
			if(rTop.first > m_MinCost)
				break;
			cur_node = rTop.second;
			int dir = -1;
			rque.pop();
			explore(cur_node, m_pRCost[rTop.second], dir, rque);
		}
		else                        // Explore from forward queue
		{
			if(fTop.first > m_MinCost)
				break;
			cur_node = fTop.second;
			int dir = 1;
			fque.pop();
			explore(cur_node, m_pFCost[fTop.second], dir, fque);
		}
	}

/*
	Path reconstruction part. m_MidNode is the joining point where two searches meet to make a shortest path. It is updated in explore.
	If it contains -1, then no path is found. Other wise we have a shortest path and that is reconstructed in the m_vecPath.
*/

	if(m_MidNode == -1)
	{
		*err_msg = (char *)"Path Not Found";
		deleteall();
		return -1;
	}
	else
	{
		// reconstruct path from forward search
		fconstruct_path(m_MidNode);
		// reconstruct path from backward search
		rconstruct_path(m_MidNode);

		// insert the last row in the path trace (having edge_id = -1 and cost = 0.0)
		path_element_t pelement;
		pelement.vertex_id = end_vertex;
		pelement.edge_id = -1;
		pelement.cost = 0.0;
		m_vecPath.push_back(pelement);

		// Transfer data path to path_element_t format and allocate memory and populate the pointer
		*path = (path_element_t *) malloc(sizeof(path_element_t) * (m_vecPath.size() + 1));
		*path_count = m_vecPath.size();

		for(size_t i = 0; i < *path_count; i++)
		{
			(*path)[i].vertex_id = m_vecPath[i].vertex_id;
			(*path)[i].edge_id = m_vecPath[i].edge_id;
			(*path)[i].cost = m_vecPath[i].cost;
		}
		
	}
	deleteall();
	return 0;
}
Esempio n. 9
0
int BiDirDijkstra:: bidir_dijkstra(edge_t *edges, unsigned int edge_count, int maxNode, int start_vertex, int end_vertex,
				path_element_t **path, int *path_count, char **err_msg)
{
	max_node_id = maxNode;
	max_edge_id = -1;
	init();
	construct_graph(edges, edge_count, maxNode);
	

	int nodeCount = m_vecNodeVector.size();
		
	std::priority_queue<PDI, std::vector<PDI>, std::greater<PDI> > fque;
	std::priority_queue<PDI, std::vector<PDI>, std::greater<PDI> > rque;
	
	m_vecPath.clear();

	int i;
	initall(maxNode);

	m_pFParent[start_vertex].par_Node = -1;
	m_pFParent[start_vertex].par_Edge = -1;
	m_pFCost[start_vertex] = 0.0;
	fque.push(std::make_pair(0.0, start_vertex));

	m_pRParent[end_vertex].par_Node = -1;
	m_pRParent[end_vertex].par_Edge = -1;
	m_pRCost[end_vertex] = 0.0;
	rque.push(std::make_pair(0.0, end_vertex));


	int new_node;
	int cur_node;
	int dir;

	while(!fque.empty() && !rque.empty())
	{
		PDI fTop = fque.top();
		PDI rTop = rque.top();
		if(fTop.first + rTop.first > m_MinCost) //We are done, there is no path with lower cost
			break;

		if(rTop.first < fTop.first) // Explore from reverse queue
		{
			cur_node = rTop.second;
			int dir = -1;
			rque.pop();
			explore(cur_node, rTop.first, dir, rque);
		}
		else                        // Explore from forward queue
		{
			cur_node = fTop.second;
			int dir = 1;
			fque.pop();
			explore(cur_node, fTop.first, dir, fque);
		}
	}

	if(m_MidNode == -1)
	{
		*err_msg = (char *)"Path Not Found";
		deleteall();
		return -1;
	}
	else
	{
		fconstruct_path(m_MidNode);
		rconstruct_path(m_MidNode);
		path_element_t pelement;
		pelement.vertex_id = end_vertex;
		pelement.edge_id = -1;
		pelement.cost = 0.0;
		m_vecPath.push_back(pelement);

		*path = (path_element_t *) malloc(sizeof(path_element_t) * (m_vecPath.size() + 1));
		*path_count = m_vecPath.size();

		for(i = 0; i < *path_count; i++)
		{
			(*path)[i].vertex_id = m_vecPath[i].vertex_id;
			(*path)[i].edge_id = m_vecPath[i].edge_id;
			(*path)[i].cost = m_vecPath[i].cost;
		}
		
	}
	deleteall();
	return 0;
}