示例#1
0
	bool checkCols(const Sudoku &s)
	{
		for(unsigned int c = 0; c < 9; ++c) {
			Row l;
			for(const auto &row : s)
				l.push_back(row[c]);
			if (!checkList(l, "in col"))
				return false;
		}
		return true;
	}
示例#2
0
	bool checkSquares(const Sudoku &s)
	{
		for(int sr=0; sr < 3; ++sr)
			for(int sc = 0; sc < 3; ++sc) {
				Row l;
				for(int r = 0; r < 3; ++r)
					for(int c = 0; c < 3; ++c)
						l.push_back(s[sr*3 + r][sc*3 + c]);
				if (!checkList(l, "in square"))
					return false;
			}
		return true;
	}
示例#3
0
文件: list.c 项目: dayu070/GProm
List *
appendToTailOfListInt(List *list, int value)
{
    ASSERT(isIntList(list));
    
    if (list == NIL)
        list = newList(T_IntList);
    else
        newListTail(list);
    
    list->tail->data.int_value = value;
    ASSERT(checkList(list));
    return list;
}
示例#4
0
文件: list.c 项目: dayu070/GProm
List *
appendToHeadOfList(List *list, void *value)
{
    ASSERT(isPtrList(list));

    if (list == NIL)
        list = newList(T_List);
    else
        newListHead(list);
    
    list->head->data.ptr_value = value;
    ASSERT(checkList(list));
    return list;
}
示例#5
0
文件: list.c 项目: dayu070/GProm
List *
appendToHeadOfListInt (List *list, int value)
{
    ASSERT(isIntList(list));

    if (list == NIL)
        list = newList(T_IntList);
    else
        newListHead(list);

    list->head->data.int_value = value;
    ASSERT(checkList(list));
    return list;
}
示例#6
0
文件: list.c 项目: dayu070/GProm
List *
appendToTailOfList(List *list, void *value)
{
    ASSERT(isPtrList(list));
	
    if (list == NIL || list->length == 0)
		list = newList(T_List);
	else
        newListTail(list);
    
    list->tail->data.ptr_value = value;

    ASSERT(checkList(list));
    return list;
}
示例#7
0
void my_free(void *block) {
	Node *curr = myHeapList;
	while (curr != NULL){
		if (curr->address == ((Node *) block)->address) {
			break;
		}
		curr = curr->next;
	}
	if (curr == NULL) {		//can't find the block address (outside of heap)
		printf("Illegal argument. Pointer outside of heap.\n");
	} else {
		curr->free = TRUE;
		capacityLeft += curr->size;
		checkList();
	}
}
示例#8
0
文件: ll1.c 项目: himz/C
int main() {
	int a;
	head = NULL;
	push( &head, 3);
	push( &head, 2);
	push( &head, 1);
	push( &head, 1);
	checkList();
	printf("Head Node: \n");
	printNode(head);
	printf("List: \n");
	printList(head);
	/* Count Test */
	printf("Count of 1 = %d\n", Count( head, 1 ));
	/* GetNth test */
	printf("Value at node 2 = %d \n", GetNth( head, 2));
	scanf("%d",&a);
}
示例#9
0
BOOL CALLBACK EnumDesktopProc(LPTSTR lpszDesktop, LPARAM lParam)
{
    TCHAR *szBuff;


    if (!checkList(lpszDesktop)) {
	szBuff = (TCHAR *) malloc(100);
	_stprintf(szBuff, _T("%s"), lpszDesktop);



	desktopList.push_front(szBuff);
    }

    OutputDebugString(L"Desktop  Enumrated");
    return 1;

}
示例#10
0
文件: list.c 项目: dayu070/GProm
List *
newList(NodeTag type)
{
    List *newList;
    ListCell *newListHead;

    newListHead = (ListCell *) NEW(ListCell);
    newListHead->next = NULL;

    newList = (List *) NEW(List);
    newList->type = type;
    newList->length = 1;
    newList->head = newListHead;
    newList->tail = newListHead;

    ASSERT(checkList(newList));

    return newList;
}
示例#11
0
void showPage (FILE* fd, int in_fd, char * host, char * IP, char* fecha, char* URL)
{
  int out_fd = connectToServer(host);
  char * tipo;

  //Chequeo de Paginas Prohibidas.
  if (checkList(URL) == 0)    
{  simpleRes(in_fd, URL);
  tipo = "forbidden";}
else if (checkBeginning(URL) == 0)   
{  complexRes(in_fd, URL, URL);
  tipo = "forbidden";}
else
{
    CatClient(in_fd, out_fd);
  tipo = CatServ(out_fd, in_fd);
  };

  //Imprime sobre el archivo de Trazas
  fprintf(fd, "%s %s %s %s\n", IP, URL, tipo, fecha);

}
示例#12
0
static PyObject *
newNormalizer(PyObject *modinfo, PyObject *args, PyObject *keywds)
{
    Normalizer *self=NULL;
    PyObject *table;
    char * encoding = "latin1";

    if (! (PyArg_ParseTupleAndKeywords(args,keywds,"O|s",Normalizer_args,&table,&encoding)))
        return NULL;

    if (! (self = PyObject_NEW(Normalizer, &NormalizerType)))
        return NULL;

   if (! checkList(table))
       return NULL;

    self->encoding = encoding;

    CopyTranslationTable(self,table);

    return (PyObject*) self;
}
示例#13
0
文件: cache.c 项目: HIPERFIT/mlkit
static void
checkList1(const cache *c)/*{{{*/
{
  checkList((cache *) c);
  return;
}/*}}}*/
示例#14
0
//----- Execution function -------//
void GamePlay::process()
{
	if (!grid||!window||!objectProgram||!shadowProgram||!skyboxProgram||!playergroup)
		return;
	
	
	bool running=true;
	sf::Clock c;


	cout<<"starting game play"<<endl;
	int identity;

	if (playergroup->isServer())
	{
		identity=playergroup->getNbPlayer();

		Message message;
		// sending StartParty
		message.type=Message::StartParty;
		for(int i=0;i<playergroup->getNbPlayer();++i)
		{
			message.identity=i;
			playergroup->sendMessage(message);
		}
		// waiting Okay
		vector<bool> checkList(playergroup->getNbPlayer());
		for(int i=0;i<playergroup->getNbPlayer();++i)
			checkList.push_back(false);
		bool okay=false;
		while(not okay)
		{
			okay=true;
			message=playergroup->checkMessage();
			if (message.type==Message::Okay)
			{
				checkList[message.identity]=true;
			}
			okay=true;
			for(int i=0;i<playergroup->getNbPlayer();++i)
			{
				okay &= checkList[i];
			}
			sf::sleep(sf::seconds(0.5));
		}
	}
	else
	{
		// waiting StartParty
		Message message;
		while(1)
		{
			message=playergroup->checkMessage();
			if (message.type==Message::StartParty)
			{
				identity=message.identity;
				break;
			}
		}

		// sending Okay
		message.type=Message::Okay;
		playergroup->sendMessage(message);
		
	}

	cout<<"I am " << identity<<endl;

	if (playergroup->isServer())
	{
		// creating every balls
		list<IntCoord> bowlReceptacle=grid->getStartPointList();
		for(int i=0;i<playergroup->getNbPlayer();++i)
		{
			// creating a new ball
			IntCoord position=bowlReceptacle.front();
			bowlReceptacle.pop_front();
			cout<<position.x<<" "<<position.y<<" "<<position.z<<endl;
			game_physic.add_sphere(position.x,position.y,position.z+0.5);
		}
		// the server's ball
		IntCoord position=bowlReceptacle.front();
		bowlReceptacle.pop_front();
		cout<<position.x<<" "<<position.y<<" "<<position.z<<endl;
		game_physic.add_sphere(position.x,position.y,position.z+0.5);
		loadMesh();

		// for each player sending every balls
		for(int i=0;i<playergroup->getNbPlayer();++i)
		{
			for(int j=0;j<=playergroup->getNbPlayer();++j)
			{
				Message message;
				message.identity=i;
				message.type=Message::BowlMatrix;
				
				btTransform tr=game_physic.get_sphere_transformation(i);
				btScalar m[16];
				tr.getOpenGLMatrix(m);
				for(int j=0;j<16;++j)
				{
					message.content.bowlMatrix.mat[j]=m[j];
				}
				message.content.bowlMatrix.player=i;
				playergroup->sendMessage(message);
			
			}
			// sending StartParty
			Message message;
			message.type=Message::StartParty;
			message.identity=i;
			playergroup->sendMessage(message);
		}
	}
	else
	{
		while(true)
		{
			Message message;
			message=playergroup->checkMessage();
			int player=0;
			if (message.type==Message::BowlMatrix)
			{
				game_physic.add_sphere(0,0,0);
				btTransform tr;
				tr.setFromOpenGLMatrix(message.content.bowlMatrix.mat);
				game_physic.set_sphere_transformation(player,tr);
				player++;
				cout<<"receiving new sphere"<<endl;
			}
			else if (message.type==Message::StartParty)
			{
				break;
			}
		}
	}

	// installing world mesh
	btBvhTriangleMeshShape* mesh;
	mesh=grid->get_mesh();
	game_physic.set_world_mesh(mesh);

	


	while(running)
	{
		//event management
		sf::Event event;
		while (window->pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
			{
				// the program is stopped
				running = false;
				state = exit_all;
			}
			else if (event.type == sf::Event::Resized)
			{
				// viewport adjusting when the window is redimensionned
				glViewport(0, 0, event.size.width, event.size.height);
			}
			else if (event.type == sf::Event::KeyPressed)
			{
				if (event.key.code == sf::Keyboard::Escape)
				{
					running=false;
					state = exit;
				}
				else if (event.key.code == sf::Keyboard::Space)
				{
					//if (game_editor_menu.isFocusOn())
						//game_editor_menu.give_focus();
					//else
						//game_editor_menu.take_focus();

				}
			}
			else if (event.type == sf::Event::MouseButtonPressed)
			{
				//if (game_editor_menu.isFocusOn())
				//{
					//if (event.mouseButton.button == sf::Mouse :: Left)
						//game_editor_menu.getMouseInfo(true,event.mouseButton.x,event.mouseButton.y);
				//}
				//else
				//{
					//if (event.mouseButton.button == sf::Mouse :: Left)
						//character.mouse_click(true);
					//else if (event.mouseButton.button == sf::Mouse :: Right)
						//character.mouse_click(false);
				//}
			}
			else if (event.type == sf::Event::MouseMoved)
			{
				//if (game_editor_menu.isFocusOn())
				//{
					//game_editor_menu.getMouseInfo(false,event.mouseMove.x,event.mouseMove.y);
				//}
			}
			//else if (event.type == sf::Event::MouseWheelMoved)
			//{
				//if (event.mouseWheel.delta>0.0)
				//{
					//game_editor_menu.increaseSelectedSlot();
				//}
				//else if (event.mouseWheel.delta<0.0)
				//{
					//game_editor_menu.decreaseSelectedSlot();
				//}
			//}
		}

		

		character.step();

		//sf::Vector2i position = sf::Mouse::getPosition(*window);
		//character.update_mouse_position(position.x-400.0,-(position.y-300.0));
		//position.x=400;
		//position.y=300;
		//sf::Mous:e::setPosition(position,*window);
		
		btTransform tr;
		tr=game_physic.get_sphere_transformation(identity);
		btScalar bmat[16];
		tr.getOpenGLMatrix(bmat);
		character.setBowlPosition(bmat[12],bmat[13],bmat[14]);
		scene.setCameraMatrix(character.get_view());
		

		
		int cx,cy,cz;
		character.getPosition(cx,cy,cz);
		scene.setCameraPosition(cx,cy,cz);

		// drawing phase
		for(int mode=BINDFORSHADOW;mode<=BINDFOROBJECT;++mode)
		{
			// drawing grid
			scene.bindFor(mode);
			if (mode==BINDFORSKYBOX)
			{
				scene.performSkyboxDrawing();
			}
			
			if (mode==BINDFOROBJECT or mode==BINDFORSHADOW)
			{
				if (mode==BINDFOROBJECT)
				{
					GLint location = glGetUniformLocation(objectProgram, "tex");
					glUniform1i(location,0);
					glActiveTexture(GL_TEXTURE0);
				}
				grid->draw(scene);
				grid->draw_special(Grid::DRAW_END_POINT,scene);
				
				// drawing sphere
				scene.pushModelViewMatrix();
				{
					glActiveTexture(GL_TEXTURE0);
					glBindTexture(GL_TEXTURE_2D,get_texture_id(texture_ball));
				}
				for(int i=0;i<game_physic.getNbSphere();++i)
				{
					btTransform tr=game_physic.get_sphere_transformation(i);
					btScalar m[16];
					tr.getOpenGLMatrix(m);
					glm::mat4 mat=glm::mat4(
							m[0],
							m[1],
							m[2],
							m[3],
							m[4],
							m[5],
							m[6],
							m[7],
							m[8],
							m[9],
							m[10],
							m[11],
							m[12],
							m[13],
							m[14],
							m[15]
					);
					scene.setModelViewMatrix(mat);
					scene.sendModelViewMatrix();
					// drawing the sphere
					GLUquadricObj *quadric=gluNewQuadric();
					gluQuadricNormals(quadric, GLU_SMOOTH);
					gluQuadricTexture(quadric, GL_TRUE);
					gluSphere(quadric, 1.0f,20,20);
					gluDeleteQuadric(quadric);
				}
				scene.popModelViewMatrix();
			}
		}
		window->display();

		// physic simulation
		if (playergroup->isServer())
		{
			// keyboard event
			float bowlAngle=character.getBowlAngle();
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
				game_physic.sphere_applyTorque(identity,0,1.2,0,bowlAngle);
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
				game_physic.sphere_applyTorque(identity,-1.2,0,0,bowlAngle);
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
				game_physic.sphere_applyTorque(identity,0,-1.2,0,bowlAngle);
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
				game_physic.sphere_applyTorque(identity,1.2,0,0,bowlAngle);
			
			// receiving others player event
			
			Message message;
			for(;;)
			{
				message=playergroup->checkMessage();
				if (message.type==Message::Nothing) break;
				else if (message.type==Message::Move)
				{
					cout<<"message move received"<<endl;
					float& moveAngle=message.content.moveAngle;
					game_physic.sphere_applyTorque(message.identity,0.0,1.2,0.0,moveAngle);
				}
			}

			// simulation
			game_physic.stepSimulation(1.0/30.0);
		}
		else
		{
			Message message;
			message.type=Message::Move;

			float bowlAngle=character.getBowlAngle();
			// keyboard event
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
			{
				message.content.moveAngle=bowlAngle;
				playergroup->sendMessage(message);
			}
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
			{
				message.content.moveAngle=bowlAngle+1.57;
				playergroup->sendMessage(message);
			}
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
			{
				message.content.moveAngle=bowlAngle+3.14;
				playergroup->sendMessage(message);
			}
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
			{
				message.content.moveAngle=bowlAngle-1.57;
				playergroup->sendMessage(message);
			}
		}

		////////////////////////////////////////
		// sharing bowl position information //
		//////////////////////////////////////
		if (playergroup->isServer())
		{
			// for each player sending every balls
			for(int i=0;i<playergroup->getNbPlayer();++i)
			{
				for(int j=0;j<=playergroup->getNbPlayer();++j)
				{
					Message message;
					message.identity=i;
					message.type=Message::BowlMatrix;

					btTransform tr=game_physic.get_sphere_transformation(j);
					btScalar m[16];
					tr.getOpenGLMatrix(m);
					for(int k=0;k<16;++k)
					{
						message.content.bowlMatrix.mat[k]=m[k];
					}
					message.content.bowlMatrix.player=j;
					playergroup->sendMessage(message);
					//cout<<"sending bowl "<<j<<" to player "<<i<<endl;

				}
			}
		}
		else
		{	
			Message message;
			message.type=Message::Nothing;
			for(;;)
			{
				//cout<<int(message.type)<<endl;
				message=playergroup->checkMessage();
				if (message.type==Message::Nothing) break;
				else if (message.type==Message::BowlMatrix)
				{
					btTransform tr;
					tr.setFromOpenGLMatrix(message.content.bowlMatrix.mat);
					int idPlayer=message.content.bowlMatrix.player;
					//cout<<"receiving bowl "<<idPlayer<<endl;
					game_physic.set_sphere_transformation(idPlayer,tr);
				}
			}
		}
		double time_elapsed=c.getElapsedTime().asSeconds();
		sf::sleep(sf::seconds(1.0/30.0-time_elapsed));
		c.restart();
	}
}
示例#15
0
int main(int argc, char **argv) {
	dlist *list;
	dlist *list2;
	dlist *list3;
	dlist *list4;
	int choice;
	int i = 0;
	int numData;
	Node *p;
	FILE *fin, *fout;
	int select = 0;
	int startFrom, numSplit; // where to split and the length of splitting list
	char fileName[15]; //file name for output data
	char textName1[20], textName2[20]; // file name for split lists

	char sections [MAX][40] = {"Import from phonebook.dat", "Display (traverse)", "Add new contact (insert before/after)",
	                           "Insert a position" , "Delete a position", "Delete current",
	                           "Delete first", "Search and Update", "Divide and Extract",
	                           "Reverse list", "Save to file", "Count max identical phone numbers", "Exit (free)"
	                          };


	do {
		choice = getMenu(sections, MAX);
		switch (choice) {
		case 1:

			// if ((fin = fopen(argv[1], "r")) == NULL)
			// {
			// 	printf("Can't open file %s\n", argv[1]);
			// 	exit(1);
			// }
			// if ((fout = fopen(argv[2], "wb")) == NULL)
			// {
			// 	printf("Can't open file %s\n", argv[2]);
			// 	exit(1);
			// }

			// numData = importDB(fin, fout);

			// fclose(fin);
			// fclose(fout);

			list = iniList(list);
			list2 = iniList(list2);
			list3 = iniList(list3);
			list4 = iniList(list4);
			if ((fin = fopen(argv[1], "rb")) == NULL)
			{
				printf("Can't open file %s\n", argv[1]);
				exit(1);
			}
			fseek(fin, 0, SEEK_END);
			numData = ftell(fin) / sizeof(element_type);
			rewind(fin);
			result = import(fin, numData);
			for (i = 0; i < result; ++i)
				insertEnd(contact[i], list);
			// printData();
			fclose(fin);
			break;
		case 2:
			traverse(list);
			break;
		case 3:
			printf("Enter 0 to insert before, 1 to insert after: ");
			scanf("%d", &select);
			while (getchar() != '\n');
			if (select == 0)
				insertBefore(list->root, typeHand(), list);
			else
				insertEnd(typeHand(), list);
			break;
		case 4: printf("Position to insert after (1 means root element): ");
			scanf("%d", &select);
			printf("Type in the data to insert\n");
			while (getchar() != '\n');
			if (select < numData)
				insertAfter(locateNode(select, list), typeHand(), list);
			else
				insertEnd(typeHand(), list);
			break;
		case 5: printf("Position to delete: (1 means root element)");
			scanf("%d", &select);
			delNode(locateNode(select, list), list);
			break;
		case 6: delNode(list->cur, list);
			break;
		case 7: delNode(list->root, list);
			break;
		case 8: searchName();
			while (1) {

				printf("Update for position number (type -1 to stop updating): ");
				scanf("%d", &select);
				while (getchar() != '\n');
				if (select == -1)
					break;

				insertAfter(locateNode(select, list), typeHand(), list);
				delNode(locateNode(select, list), list);
				printf("Update success\n");
			}
			break;
		case 9:
			printf("The length of the list is %d\n", listLength(list));
			printf("Type in where to start (range from 1 to end of the list): ");
			scanf("%d", &startFrom);
			printf("Length of spliting: ");
			scanf("%d", &numSplit);
			if (listLength(list) > startFrom + numSplit)
				splitList(startFrom, numSplit, list, list2, list3);
			else
				splitList(startFrom, listLength(list) - startFrom, list, list2, list3);
			while (getchar() != '\n');
			printf("Now type in 2 file name to save the new lists\n");
			printf("File 1: ");
			scanf("%s", textName1);
			printf("File 2: ");
			scanf("%s", textName2);
			checkList(list2, textName1); //result of splitList
			checkList(list3, textName2);
			break;
		case 10:
			reverseList(list);
			break;
		case 11:
			printf("Type in the file name\n");
			scanf("%s", fileName);
			if ((fout = fopen(fileName, "w + t")) == NULL)
			{
				printf("Can't open file %s\n", fileName);
				exit(1);
			}
			savetoFile(fout, list);
			break;
		case 12:
			list4 = countsameNum(list, list4);
			printf("After spliting, the new list with identical numbers: \n");
			p = list4->root;
			while ( p != NULL ) {
				printf("Node with phone number: %s, address %p\n", p->element.tel, p);
				p = p->next;
			}
			break;
		case MAX:
			freeList(list);
			freeList(list2);
			freeList(list3);
			freeList(list4);
			exit(1);
			break;
		default: printf("Invalid choice. It must be from 1 to %d\n", MAX); break;
		}
	} while (choice != MAX);
	return 0;
}
示例#16
0
static int wtCmd(ClientData clientData, Tcl_Interp * interp, int argc,
                  char ** argv) {
    enum mode mode = MODE_NONE;
    poptContext optCon;
    int arg;
    const char * optArg;
    const char * text;
    const char * nextArg;
    char * end;
    int height;
    int width;
    int noCancel = 0;
    int noItem = 0;
    int scrollText = 0;
    int rc = 0;
    int flags = 0;
    int defaultNo = 0;
    char * result;
    char ** selections, ** next;
    char * title = NULL;
    struct poptOption optionsTable[] = {
	    { "checklist", '\0', 0, 0, OPT_CHECKLIST },
	    { "defaultno", '\0', 0, &defaultNo, 0 },
	    { "inputbox", '\0', 0, 0, OPT_INPUTBOX },
	    { "menu", '\0', 0, 0, OPT_MENU },
	    { "msgbox", '\0', 0, 0, OPT_MSGBOX },
	    { "nocancel", '\0', 0, &noCancel, 0 },
	    { "noitem", '\0', 0, &noItem, 0 },
	    { "radiolist", '\0', 0, 0, OPT_RADIOLIST },
	    { "scrolltext", '\0', 0, &scrollText, 0 },
	    { "title", '\0', POPT_ARG_STRING, &title, 0 },
	    { "yesno", '\0', 0, 0, OPT_YESNO },
	    { 0, 0, 0, 0, 0 } 
    };
    
    optCon = poptGetContext("whiptcl", argc, argv, optionsTable, 0);

    while ((arg = poptGetNextOpt(optCon)) > 0) {
	optArg = poptGetOptArg(optCon);

	switch (arg) {
	  case OPT_MENU:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_MENU;
	    break;

	  case OPT_MSGBOX:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_MSGBOX;
	    break;

	  case OPT_RADIOLIST:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_RADIOLIST;
	    break;

	  case OPT_CHECKLIST:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_CHECKLIST;
	    break;

	  case OPT_YESNO:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_YESNO;
	    break;

	  case OPT_INPUTBOX:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_INPUTBOX;
	    break;
	}
    }
    
    if (arg < -1) {
	/* this could buffer oveflow, bug we're not setuid so I don't care */
	interp->result = malloc(200);
	interp->freeProc = TCL_DYNAMIC;
	sprintf(interp->result, "%s: %s\n", 
		poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
		poptStrerror(arg));

	return TCL_ERROR;
    }

    if (mode == MODE_NONE) {
	interp->result = "no dialog mode was specified";
	return TCL_ERROR;
    } else if (rc) {
	interp->result = "multiple modes were specified";
	return TCL_ERROR;
    }

    if (!(text = poptGetArg(optCon))) {
	interp->result = "missing text parameter";
	return TCL_ERROR;
    }

    if (!(nextArg = poptGetArg(optCon))) {
	interp->result = "height missing";
	return TCL_ERROR;
    }
    height = strtoul(nextArg, &end, 10);
    if (*end) {
	interp->result = "height is not a number";
	return TCL_ERROR;
    }

    if (!(nextArg = poptGetArg(optCon))) {
	interp->result = "width missing";
	return TCL_ERROR;
    }
    width = strtoul(nextArg, &end, 10);
    if (*end) {
	interp->result = "width is not a number";
	return TCL_ERROR;
    }

    width -= 2;
    height -= 2;
    newtOpenWindow((80 - width) / 2, (24 - height) / 2, width, height, title);

    if (noCancel) flags |= FLAG_NOCANCEL;
    if (noItem) flags |= FLAG_NOITEM;
    if (scrollText) flags |= FLAG_SCROLL_TEXT;
    if (defaultNo) flags |= FLAG_DEFAULT_NO;

    switch (mode) {
      case MODE_MSGBOX:
	rc = messageBox(text, height, width, MSGBOX_MSG, flags);
	break;

      case MODE_YESNO:
	rc = messageBox(text, height, width, MSGBOX_YESNO, flags);
	if (rc == DLG_OKAY)
	    interp->result = "yes";
	else 
	    interp->result = "no";
	if (rc == DLG_ERROR) rc = 0;
	break;

      case MODE_INPUTBOX:
	rc = inputBox(text, height, width, optCon, flags, &result);
	if (!rc) {
	    interp->result = strdup(result);
	    interp->freeProc = TCL_DYNAMIC;
	}
	break;

      case MODE_MENU:
	rc = listBox(text, height, width, optCon, flags, &result);
	if (!rc) {
	    interp->result = strdup(result);
	    interp->freeProc = TCL_DYNAMIC;
	}
	break;

      case MODE_RADIOLIST:
	rc = checkList(text, height, width, optCon, 1, flags, &selections);
	if (!rc) {
	    interp->result = strdup(selections[0]);
	    interp->freeProc = TCL_DYNAMIC;
	}
	break;

      case MODE_CHECKLIST:
	rc = checkList(text, height, width, optCon, 0, flags, &selections);

	if (!rc) {
	    for (next = selections; *next; next++) 
		Tcl_AppendElement(interp, *next);

	    free(selections);
	}
	break;

      case MODE_NONE:
	/* this can't happen */
    }

    newtPopWindow();

    if (rc == DLG_ERROR) {
	interp->result = "bad paramter for whiptcl dialog box";
	return TCL_ERROR;
    } 

    Tcl_SetVar(interp, "whiptcl_canceled", (rc == DLG_CANCEL) ? "1" : "0",
		0);

    return TCL_OK;
}

static char * setBacktext(ClientData data, Tcl_Interp * interp, 
			  char * name1, char * name2, int flags) {
    static char blankLine[81] = "                                        "
                         "                                        ";

    newtDrawRootText(0, 0, blankLine);
    newtDrawRootText(0, 0, Tcl_GetVar(interp, "whiptcl_backtext",
		                      TCL_GLOBAL_ONLY));

    return NULL;
}

static char * setHelptext(ClientData data, Tcl_Interp * interp, 
			  char * name1, char * name2, int flags) {
    char * text = Tcl_GetVar(interp, "whiptcl_helpline", TCL_GLOBAL_ONLY);

    if (!text)
	text = "";
    else if (!strlen(text))
	text = NULL;

    newtPopHelpLine();
    newtPushHelpLine(text);

    return NULL;
}
示例#17
0
/**
* CAIStatePathPlan::update
* @date Modified May 4, 2006
*/
void CAIStatePathPlan::update(CAIEntity* poAIEntity, CCharacter* poCharacter)
{
	CAIManager* pAIManager = CAIManager::getInstancePtr();

	// set up the goal
	m_poGoalNode = pAIManager->findBestGoal(poCharacter);

	// try to update the goals if they are dirty
	if (pAIManager->getUpdateGoalLinks())
		pAIManager->update();

	// clear out all the old info
	/////////////////////////////

	poAIEntity->m_loPath.clear();
	m_loOpenNodes.clear();
	m_loClosedNodes.clear();

	// create a node at the actor's position and set up the links
	m_poStartNode->setPosition(poCharacter->getBV().centerPt);
	pAIManager->unlinkNode(m_poStartNode);

	// test a direct link to the goal
	if (pAIManager->testDirectLink(m_poStartNode, m_poGoalNode))
	{
		poAIEntity->m_loPath.push_back(m_poGoalNode);

		// put the entity into the follow state
		EObjectType eType = poCharacter->getType();
		switch (eType)
		{
		case OBJ_ENEMY_ZOMBIECITIZEN:
			((CEnemy*)(poCharacter))->setAIState(CAIStatePathFollow::getInstancePtr());
			break;
		case OBJ_ENEMY_GASEOUSCLAY:
			((CEnemy*)(poCharacter))->setAIState(CAIStateGaseousFollow::getInstancePtr());
			break;
		case OBJ_ENEMY_ICECREAMMAN:
			{
				((CEnemy*)(poCharacter))->setAIState(CAIStateAcidicFollow::getInstancePtr());
				break;
			}
		case OBJ_ENEMY_QUARTERBACK:
			((CEnemy*)(poCharacter))->setAIState(CAIStateQBFollow::getInstancePtr());
			break;
		}
		return;
	}

	pAIManager->linkNode(m_poStartNode);

	// if we don't have any links we have gone through geometry and we are screwed
	// if the goal has no links he has gone through geometry and the entire game is screwed
	if (m_poStartNode->m_loLinks.empty() || m_poGoalNode->m_loLinks.empty())
	{
		// set ourselves for deletion and get out of here
		CObjectManager::getInstance().removeObject(poCharacter);
		return;
	}

	// pre-plan initializations
	CAINode* poCurrentNode = m_poStartNode;
	float fDistanceToGoal = 0.0f;
	// Links Iterator
	NODE_LIST_ITER oNodeIter;
	// Open and Closed list iterator
	NODE_LIST_ITER oListIter;

	// start the path planning
	//////////////////////////

	m_loOpenNodes.push_back(poCurrentNode);

	// continue as long as there are paths to explore
	while (!m_loOpenNodes.empty())
	{
		poCurrentNode = m_loOpenNodes.front();
		m_loOpenNodes.pop_front();
		m_loClosedNodes.push_back(poCurrentNode);

		// is this current node the goal
		if (poCurrentNode == m_poGoalNode)
		{
			// it is so fill up the solution path and get out
			/////////////////////////////////////////////////
			
			// don't add the start node for the same reason as the goal node
			while (poCurrentNode != m_poStartNode)
			{
				poAIEntity->m_loPath.push_back(poCurrentNode);
				poCurrentNode = poCurrentNode->m_poParent;
			}

			// get while the gettin' 's good
			break;
		}

		// add the children to the current list
		///////////////////////////////////////

		// Links Iterator
		oNodeIter = poCurrentNode->m_loLinks.begin();

		// go through every link this node has
		while (oNodeIter != poCurrentNode->m_loLinks.end())
		{
			// check the open list first because it is smaller
			oListIter = checkList(&m_loOpenNodes, (*oNodeIter));

			// is it not in the open list
			if (oListIter == m_loOpenNodes.end())
			{
				// check the closed list not
				oListIter = checkList(&m_loClosedNodes, (*oNodeIter));

				// is it not in the closed list
				if (oListIter == m_loClosedNodes.end())
				{
					// insert node into the open list
					/////////////////////////////////

					// set parent
					(*oNodeIter)->m_poParent = poCurrentNode;
					// set the distance
					(*oNodeIter)->m_fDistanceToGoal = computeDistanceSquared((*oNodeIter)->getPosition(), m_poGoalNode->getPosition());
					// prioritized insert
					insertOpenList(*oNodeIter);					
				}
			}

			oNodeIter++;
		}
	}

	// put the entity into the follow state
	EObjectType eType = poCharacter->getType();
	switch (eType)
	{
	case OBJ_ENEMY_ZOMBIECITIZEN:
		((CEnemy*)(poCharacter))->setAIState(CAIStatePathFollow::getInstancePtr());
		break;
	case OBJ_ENEMY_GASEOUSCLAY:
		((CEnemy*)(poCharacter))->setAIState(CAIStateGaseousFollow::getInstancePtr());
		break;
	case OBJ_ENEMY_ICECREAMMAN:
		((CEnemy*)(poCharacter))->setAIState(CAIStateAcidicFollow::getInstancePtr());
		break;
	case OBJ_ENEMY_QUARTERBACK:
		((CEnemy*)(poCharacter))->setAIState(CAIStateQBFollow::getInstancePtr());
		break;
	}
}
示例#18
0
	bool checkRows(const Sudoku &s)
	{
		return std::all_of(s.begin(), s.end(),
				[this](const Row &r){ return checkList(r, "in row"); });
	}