Exemplo n.º 1
0
void conway_test()
{
	force_write(1,2,is_world_calc);
	force_write(2,2,is_world_calc);
	force_write(3,2,is_world_calc);
	display_world();

	//write_cell(3, 3, 2);
	//display_world();
	printf("%i \n",check_cell(1, 2, is_world_calc));
	printf("%i \n",check_cell(2, 2, is_world_calc));
	printf("%i \n",check_cell(3, 2, is_world_calc));
	printf("%i \n",check_cell(2, 1, is_world_calc));
	on_tick();
	printf("%i \n",check_cell(1, 2, is_world_calc));
	printf("%i \n",check_cell(2, 2, is_world_calc));
	printf("%i \n",check_cell(3, 2, is_world_calc));
	printf("%i \n",check_cell(2, 1, is_world_calc));
	on_tick();
	printf("%i \n",check_cell(1, 2, is_world_calc));
	printf("%i \n",check_cell(2, 2, is_world_calc));
	printf("%i \n",check_cell(3, 2, is_world_calc));
	printf("%i \n",check_cell(2, 1, is_world_calc));
	on_tick();
}
Exemplo n.º 2
0
inline void fastWorld()
{	
void display_world();

int i,j;

	world_R=3;
	world_C=4;

	BETA=0.9;
	ALPHA=1;
	transition_function[0]=0.8;
	transition_function[1]=0.1;
	transition_function[2]=0.1;


				FOR_ALL_ROWS
				FOR_ALL_COLUMNS
				reward[i][j]=-0.04;

			reward[1][1]=UNREACHABLE;
			utility[1][1]=UNREACHABLE;
			
			reward[0][3]=1+TERMINAL;
			utility[0][3]=1;	

			reward[1][3]=-1+TERMINAL;
			utility[1][3]=-1;
		

display_world();
}
Exemplo n.º 3
0
int run_main_loop (struct world *world)
{
	int animation_speed;   /* In milliseconds. */
	static int round_intervals[6] = { 0, 1, 10, 100, 1000, 10000 };
	static int step_intervals[6] = { 1, 0, 0, 0, 0, 0 };

	enum events event; 	

	rounds = 1;  
	steps = 0;  

	do_animation = 0;
	do_one_step = 0;
	
	animation_speed = 500;

	while ((event = v_poll_event (animation_speed)) != EVENT_QUIT) {
		switch (event) {
		case EVENT_NONE: break;
		case EVENT_REDISPLAY: display_world (world); break;

		case EVENT_ANIMATE_FASTEST: animation_speed = 0; break;
		case EVENT_ANIMATE_FASTER: animation_speed -= 100; break;
		case EVENT_ANIMATE_SLOWER: animation_speed += 100; break;
		case EVENT_START_ANIMATION: do_animation=1; break;
		case EVENT_STOP_ANIMATION: do_animation=0; break;
		case EVENT_TOGGLE_ANIMATION: do_animation=!do_animation; break;

		case EVENT_UPDATE: break;   /* just causes status line to be updated. */
		case EVENT_SHOW_ANT_STATE: show_state_in_editor (world); 
		default: break;
		}

		if (event >= EVENT_STEP_FORWARD && event <= EVENT_10000_ROUNDS_BACKWARD) {
					
			rounds = round_intervals [(event - EVENT_STEP_FORWARD) / 2];
			steps = step_intervals [(event - EVENT_STEP_FORWARD) / 2];
			if ((event - EVENT_STEP_FORWARD) % 2) {
				rounds = -rounds;
				steps = -steps;
			}
		    	printf("changing to rounds=%d, steps=%d\n", rounds, steps);
			do_one_step = 1;
		}

		update_status (world);
		if (do_animation || do_one_step) {
			if (steps) {
				n_steps (world, steps);
			} else {
				n_rounds (world, rounds);
			}
		}
		do_one_step = 0;
	}

	return 0;
}
Exemplo n.º 4
0
int main(int argc, char **argv) {
	int result;

	/* reset internal variables */
	reset_cgi_vars();

	/* Initialize shared configuration variables */                             
	init_shared_cfg_vars(1);

	/* read the CGI configuration file */
	result = read_cgi_config_file(get_cgi_config_location());
	if(result == ERROR) {
		document_header();
		return ERROR;
		}

	/* defaults from CGI config file */
	layout_method = default_statuswrl_layout_method;

	/* get the arguments passed in the URL */
	process_cgivars();

	document_header();

	/* read the main configuration file */
	result = read_main_config_file(main_config_file);
	if(result == ERROR)
		return ERROR;

	/* read all object configuration data */
	result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
	if(result == ERROR)
		return ERROR;

	/* read all status data */
	result = read_all_status_data(status_file, READ_ALL_STATUS_DATA);
	if(result == ERROR) {
		free_memory();
		return ERROR;
		}

	/* get authentication information */
	get_authentication_information(&current_authdata);

	/* display the 3-D VRML world... */
	display_world();

	/* free all allocated memory */
	free_memory();

	return OK;
	}
Exemplo n.º 5
0
void on_tick()
{
	// Function to be called once per tick.
	// Every tick we should go through the world and run check_cell on each cell in
	// world_write to determine the new value of world_calc's cells
	// Then, we set world_write's values equal to world_calc's new value and display them
	for (j=0; j<number_of_rows; j++)
	{
		for (k=0; k<32; k++){
			write_cell( j, k, check_cell( j, k, is_world_calc) );
		}
	}
	display_world();
	is_world_calc = !(is_world_calc);
}
Exemplo n.º 6
0
int main (int argc, char ** argv)
{
	struct world *world;
	FILE *f;
	int c, ret;
	int head_steps, tail_steps, skip_steps, next_step;
	int ants_count, resolution;
	int step;
	int performance_test;
	int window_width;
	int window_height;
	int hex_size;

	dump_format = 0;
	step = 0;
	head_steps = 0; 
	tail_steps = 0; 
	skip_steps = 1;
	performance_test = 0;

	window_width = 800;
	window_height = 614;
	hex_size = 3;

/* These are used for dump format, since it is difficult to figure them out. */
	resolution = 10;
	ants_count = 32;

	world = NULL;

	while ((c=getopt (argc, argv, "wdh:t:s:a:p:W:H:c:")) != EOF) {
		switch (c) {
		case 'd': dump_format = 1; break;
		case 't': 
			if (!optarg) usage_and_exit (argv[0]);
			tail_steps = atoi (optarg); break;
		case 's': 
			if (!optarg) usage_and_exit (argv[0]);
			skip_steps = atoi (optarg); break;
                case 'r':
                        if (!optarg) usage_and_exit (argv[0]);
                        resolution = atoi (optarg); break;
                case 'a':
                        if (!optarg) usage_and_exit (argv[0]);
                        ants_count = atoi (optarg); break;
		case 'h': 
			if (!optarg) usage_and_exit (argv[0]);
			head_steps = atoi (optarg); break;
		case 'w': warnings = 1; break;
		case 'p': 
			if (!optarg) usage_and_exit (argv[0]);
			performance_test = atoi (optarg); 
			break;
		case 'W': 
			if (!optarg) usage_and_exit (argv[0]);
			window_width = atoi (optarg); break;
		case 'H': 
			if (!optarg) usage_and_exit (argv[0]);
			window_height = atoi (optarg); break;
		case 'c': 
			if (!optarg) usage_and_exit (argv[0]);
			hex_size = atoi (optarg); break;
		
		case '?': 
		default: usage_and_exit (argv[0]);
		}
	}

	if (skip_steps < 1 || tail_steps < head_steps) {
		fprintf (stderr, "Illegal step setting.\n");
		exit (-1);
	}

	if (dump_format) {
		next_step = head_steps;
		f = open_next_file_from_argv (argv);

		v_set_geometry (window_width, window_height, hex_size);
		v_initialize ();
		while (!feof (f)) {
			if (read_world_as_icfp_dump (&world, f, resolution, resolution, ants_count) == 0) {
				if (step <= head_steps ||
                                    step >= tail_steps ||
                                    step == next_step) {
					printf ("Step %d ...\n", step);
					display_world (world);
		    	    	    	v_refit_view ();
					if ((ret = v_poll_event (0))) {
					    if (ret == -1) {
						break;
					    }
					}

					next_step = skip_steps+step;
				}
			}
			step++;
		}
		fclose (f);
	} else {
		f = open_next_file_from_argv (argv);
		if (read_world (&world, f) != 0) {
			fprintf (stderr, "Error in reading world map.\n");
			exit (-1);
		}
		fclose (f);

		f = open_next_file_from_argv (argv);
		if (parse_world_trace (world, f) != 0) {
			fprintf (stderr, "Error in reading world trace.\n");
			exit (-1);
		}
		fclose (f);

		v_set_geometry (window_width, window_height, hex_size);
		v_initialize ();
		display_world (world);
		// v_refit_view ();
	}

	if (performance_test) {
		return run_performance_test (world, performance_test);
	} else {
		return run_main_loop (world);
	}
}
Exemplo n.º 7
0
inline void inputWorld()
{	
void display_world();

int i=-1,j=-1;
int temp,temp2;
float reward_of;

	printf("Please enter the characteristics of the world\nROWS=");
	scanf("%d",&world_R);

	printf("COLUMNS=");
	scanf("%d",&world_C);

	printf("BETA=");
	scanf("%f",&BETA);

	printf("Please enter the transition function probabilities in descending order...since correct action is at index 0\n");

		for(i=0;i<MODEL_TRANSITIONS;i++)
		{
		printf("Enter value:");
		scanf("%f",&transition_function[i]);
		}

	printf("WHICH TYPE OF REWARD DO YOU WANT TO CHOOSE\n1.FIXED FOR ALL STATES\n2.DIFFERENT FOR ALL THE STATES\nENTER YOUR OPTION: ");
	scanf("%d",&temp);

		switch(temp)
		{
		case 1: printf("Enter the reward:");
			scanf("%f",&fixed_reward);

				FOR_ALL_ROWS
				FOR_ALL_COLUMNS
				reward[i][j]=fixed_reward;
		break;

		case 2: FOR_ALL_ROWS
			{
				FOR_ALL_COLUMNS
				{
				printf("Enter the reward for state [%d,%d]:",i,j);
				scanf("%f",&reward[i][j]);
				}
			}
		break;
		}

	printf("Enter the pits of the world....Press -1 to stop ");	

		INFINITE
		{
			printf("\nPIT_ROW #=");
			scanf("%d",&temp);
			
				if(temp<0)
				break;
			
			printf("PIT_COLUMN #=");
			scanf("%d",&temp2);

			reward[temp][temp2]=UNREACHABLE;
			utility[temp][temp2]=UNREACHABLE;
		}


	printf("Enter the terminal states and their rewards....Press -1 to stop");

		INFINITE
		{
			printf("\nTERMINAL_ROW #=");
			scanf("%d",&temp);
				
				if(temp<0)
				break;
			
			printf("TERMINAL_COLUMN #=");
			scanf("%d",&temp2);

			printf("TERMINAL_REWARD=");
			scanf("%f",&reward_of);	
			
			reward[temp][temp2]=reward_of+TERMINAL;
			utility[temp][temp2]=reward_of;	
		}

display_world();
}