コード例 #1
0
ファイル: 22-B.c プロジェクト: unasuke/AtCoder
int main( void ){
    int i;
    int j;
    int cursor = 0;
    int num;
    int taste_long = 0;
    int longest = 0;
    char buf[2048];
    char tmp[10];

    fscanf( stdin , "%d\n" , &num );
    //fscanf( stdin , "%s" , buf );
    fgets( buf , 2048 , stdin );
    //printf( "%s\n" , buf );

    int *taste = (int*)malloc( sizeof(int) * num );
    char *hash = (char*)malloc( sizeof(char) * num );

    for( i = 0; i < num * 2 - 1; ){
        clear_array( tmp , 10 );
        for( j = 0; j < 10; j++ ){
            if( buf[i] == '\0' || buf[i] == ' ' ){
                i++;
                break;
            }
            else{
                tmp[j] = buf[i];
                i++;
            }
        }
        taste[cursor] = atoi(tmp);
        cursor++;
    }

    //printf( "%d,%d\n",taste[0],taste[1] );

    for( i = 0; i < num; i++ ){
        clear_array( hash , num );
        taste_long = 0;
        for( j = i; j < num; j++ ){
            if( hash[ taste[j] ] == 0 ){
                hash[ taste[j] ] = 1;
                taste_long++;
            }
            else{
                break;
            }
        }
        if( longest <= taste_long ){
            longest = taste_long;
        }
    }

    printf( "%d\n" , longest );

    free( taste );
    free( hash );

    return 0;
}
コード例 #2
0
ファイル: pgsql.c プロジェクト: gvlx/gawkextlib
static awk_value_t *
do_pg_fieldsbyname(int nargs, awk_value_t *result)
{
  PGresult *res;
  awk_value_t array;
  int nf;
  int col;

  if (do_lint && (nargs > 2))
    lintwarn(ext_id, _("pg_fieldsbyname: called with too many arguments"));

  if (!(res = find_handle(results, 0))) {
    set_ERRNO(_("pg_fieldsbyname called with unknown result handle"));
    RET_NUM(-1);
  }

  if (!get_argument(1, AWK_ARRAY, &array)) {
    set_ERRNO(_("pg_fieldsbyname 2nd argument must be an array"));
    RET_NUM(-1);
  }
  clear_array(array.array_cookie);

  nf = PQnfields(res);
  for (col = 0; col < nf; col++) {
    char *fname;
    awk_value_t idx, val;

    fname = PQfname(res, col);
    set_array_element(array.array_cookie,
		      make_string_malloc(fname, strlen(fname), &idx),
		      make_number(col, &val));
  }
  RET_NUM(nf);
}
コード例 #3
0
ファイル: main.c プロジェクト: Nrpickle/EECS162
int main(int argc, char **argv)
{
   initialize();
   initialize_TIMER0();
   clear_array();
   PORTC = 0;
   USART_send_string("Currently outputing color: \n");
   while(1){
      for(unsigned int i = 0; i < 8; ++i){
	 PORTE = i;
	 switch (state){
	    case RED:
	       //PORTE = 1;
	       update_row(224,0,0);
		checkState();
	       break;
	    case GREEN:
	       update_row(0,7,0);
	       checkState();
	       break;
	    case YELLOW:
	       led_off();
	       update_row(yellowRow,0,0);
	       update_row(yellowRow,0,0);
	       update_row(yellowRow,yellowRow,0);
	       update_row(yellowRow,0,0);
	       update_row(yellowRow,0,0);
	       led_off();
	       checkState();
	       break;
	 }
      }
   }
}	
コード例 #4
0
ファイル: pgsql.c プロジェクト: gvlx/gawkextlib
static awk_value_t *
do_pg_getrowbyname(int nargs, awk_value_t *result)
{
  PGresult *res;
  awk_value_t array;
  awk_value_t rowarg;
  int row;
  int nf;
  int found;
  int col;

  if (do_lint && (nargs > 3))
    lintwarn(ext_id, _("pg_getrowbyname: called with too many arguments"));

  if (!(res = find_handle(results, 0))) {
    set_ERRNO(_("pg_getrowbyname called with unknown result handle"));
    RET_NUM(-1);
  }

  if (!get_argument(1, AWK_NUMBER, &rowarg)) {
    set_ERRNO(_("pg_getrowbyname: 2nd argument must be a row number"));
    RET_NUM(-1);
  }
  row = rowarg.num_value;

  if ((row < 0) || (row >= PQntuples(res))) {
    set_ERRNO(_("pg_getrowbyname: 2nd argument row_number is out of range"));
    RET_NUM(-1);
  }

  if (!get_argument(2, AWK_ARRAY, &array)) {
    set_ERRNO(_("pg_getrowbyname 3rd argument must be an array"));
    RET_NUM(-1);
  }
  clear_array(array.array_cookie);

  found = 0;
  nf = PQnfields(res);
  for (col = 0; col < nf; col++) {
    if (!PQgetisnull(res, row, col)) {
      char *fname;
      char *val;
      awk_value_t idx, value;

      fname = PQfname(res, col);
      val = PQgetvalue(res, row, col);
      set_array_element(array.array_cookie,
      			make_string_malloc(fname, strlen(fname), &idx),
			make_string_malloc(val, strlen(val), &value));
      found++;
    }
  }
  RET_NUM(found);
}
コード例 #5
0
t_hash calc_material_hash(struct t_board *board)
{
    int material[16];
    clear_array(material);
    for (t_chess_color color = WHITE; color <= BLACK; color++) {
        for (int piece = KNIGHT; piece <= PAWN; piece++) {
            material[PIECEINDEX(color, piece)] = popcount(board->pieces[color][piece]);
        }
    }
    return get_material_hash(material);
}
コード例 #6
0
ファイル: mole_candy.c プロジェクト: Zhanyin/taomee
int process_ok(void* owner, void* data)
{
	sprite_t * p = owner;
	if (p == NULL) {
		return -1;
	}
	clear_array(p->id);
	int i = sizeof(protocol_t), pos = 0;
	for (pos = 0; pos < 4; pos ++) {
		PKG_UINT32(msg, pos_array[pos], i);
	}
	init_proto_head(msg, PROTO_CANDY_POSITION_EX, i);
	send_to_map3(56, msg, i);
	return do_db_add_candy(p, p->r4_type);
}
コード例 #7
0
ファイル: wunder.c プロジェクト: KevinStephens/osu-asmt-kms
int main(int argc, char **argv)
{
	initialize();
	clear_array();

	PORTE = 0;
	
	ADC_enable();
	ADC_set_channel(ADC_MUX_ADC5);
	ADC_set_prescaler(ADC_PRESCALER_128);
	ADC_start();
	

	while(1){
		set_array_red(read_ADC(ADC_MUX_ADC5));
	}
}	
コード例 #8
0
static void
copy_array(nasl_array *a1, const nasl_array *a2)
{
  int		i;
  named_nasl_var	*v1, *v2, *v;


  if (a1 == a2)
    {
#if NASL_DEBUG > 1
      nasl_perror(NULL, "copy_array: a1 == a2!\n");
#endif
      return;
    }
 
  clear_array(a1);

  if ( a2->num_elt != NULL )
    {
      a1->max_idx = a2->max_idx;
      a1->num_elt = emalloc(sizeof(anon_nasl_var*) * a2->max_idx);
      for (i = 0; i < a2->max_idx; i ++)
	a1->num_elt[i] = dup_anon_var(a2->num_elt[i]);
    }
  if (a2->hash_elt != NULL)
    {
      a1->hash_elt = emalloc(VAR_NAME_HASH * sizeof(named_nasl_var*));
      for (i = 0; i < VAR_NAME_HASH; i ++)
	{
	  v1= NULL;
	  for (v2 = a2->hash_elt[i]; v2 != NULL; v2 = v2->next_var)
	    {
	      v = dup_named_var(v2);
	      v->next_var = v1;
	      a1->hash_elt[i] = v;
	      v1 = v;
	    }
	}
    }
}
コード例 #9
0
ファイル: testext.c プロジェクト: uarka/gawk
static awk_value_t *
test_array_size(int nargs, awk_value_t *result)
{
	awk_value_t value;
	size_t count = 0;

	assert(result != NULL);
	make_number(0.0, result);

	if (nargs != 1) {
		printf("test_array_size: nargs not right (%d should be 1)\n", nargs);
		goto out;
	}

	/* get element count and print it; should match length(array) from awk script */
	if (! get_argument(0, AWK_ARRAY, & value)) {
		printf("test_array_size: get_argument failed\n");
		goto out;
	}

	if (! get_element_count(value.array_cookie, & count)) {
		printf("test_array_size: get_element_count failed\n");
		goto out;
	}

	printf("test_array_size: incoming size is %lu\n", (unsigned long) count);

	/* clear array - length(array) should then go to zero in script */
	if (! clear_array(value.array_cookie)) {
		printf("test_array_size: clear_array failed\n");
		goto out;
	}

	make_number(1.0, result);

out:
	return result;
}
コード例 #10
0
void
clear_anon_var(anon_nasl_var* v)
{

  if (v == NULL)
    return;

  switch (v->var_type)
    {
    case VAR2_INT:
      v->v.v_int = 0;
      break;
    case VAR2_STRING:
    case VAR2_DATA:
      efree(&v->v.v_str.s_val);
      v->v.v_str.s_siz = 0;
      break;
    case VAR2_ARRAY:
      clear_array(&v->v.v_arr);
      break;
    }
  v->var_type = VAR2_UNDEF;
  return;
}
コード例 #11
0
ファイル: rwarray0.c プロジェクト: Distrotech/gawk
static awk_value_t *
do_reada(int nargs, awk_value_t *result)
{
	awk_value_t filename, array;
	int fd = -1;
	uint32_t major;
	uint32_t minor;
	char magic_buf[30];

	assert(result != NULL);
	make_number(0.0, result);

	if (do_lint && nargs > 2)
		lintwarn(ext_id, _("reada: called with too many arguments"));

	if (nargs < 2)
		goto out;

	/* directory is first arg, array to read is second */
	if (! get_argument(0, AWK_STRING, & filename)) {
		fprintf(stderr, _("do_reada: argument 0 is not a string\n"));
		errno = EINVAL;
		goto done1;
	}

	if (! get_argument(1, AWK_ARRAY, & array)) {
		fprintf(stderr, _("do_reada: argument 1 is not an array\n"));
		errno = EINVAL;
		goto done1;
	}

	fd = open(filename.str_value.str, O_RDONLY);
	if (fd < 0)
		goto done1;

	memset(magic_buf, '\0', sizeof(magic_buf));
	if (read(fd, magic_buf, strlen(MAGIC)) != strlen(MAGIC)) {
		errno = EBADF;
		goto done1;
	}

	if (strcmp(magic_buf, MAGIC) != 0) {
		errno = EBADF;
		goto done1;
	}

	if (read(fd, & major, sizeof(major)) != sizeof(major)) {
		errno = EBADF;
		goto done1;
	}
	major = ntohl(major);

	if (major != MAJOR) {
		errno = EBADF;
		goto done1;
	}

	if (read(fd, & minor, sizeof(minor)) != sizeof(minor)) {
		/* read() sets errno */
		goto done1;
	}

	minor = ntohl(minor);
	if (minor != MINOR) {
		errno = EBADF;
		goto done1;
	}

	if (! clear_array(array.array_cookie)) {
		errno = ENOMEM;
		fprintf(stderr, _("do_reada: clear_array failed\n"));
		goto done1;
	}

	if (read_array(fd, array.array_cookie)) {
		make_number(1.0, result);
		goto done0;
	}

done1:
	update_ERRNO_int(errno);
done0:
	close(fd);
out:
	return result;
}
コード例 #12
0
ファイル: mole_candy.c プロジェクト: Zhanyin/taomee
int query_item_cnt_callback(sprite_t *p, uint32_t id, char *buf, int len)
{
	CHECK_BODY_LEN_GE(len, 4);
	switch (p->waitcmd) {
		case PROTO_CANDY_MAKE:
		{
			uint32_t count;
			int j = 0, flag = 0;
			UNPKG_H_UINT32(buf, count, j);
			CHECK_BODY_LEN(len, count * 8 + 4);
			if (candyitem[p->r4_type].in_cnt != count) {
				flag = 1;
			} else {
				int it;
				for (it = 0; it < count; it++) {
					uint32_t itmid, itmcn, itmid_sav, itmcn_sav;
					UNPKG_H_UINT32(buf, itmid, j);
					UNPKG_H_UINT32(buf, itmcn, j);
					itmid_sav = candyitem[p->r4_type].in_item[it].itm->id;
					itmcn_sav = candyitem[p->r4_type].in_item[it].count * p->r4_cnt;
					if (itmid_sav != itmid || itmcn_sav > itmcn) {
						flag = 1;
						break;
					}
				}
			}
			if (flag) {
				uint32_t pos;
				clear_array(p->id);
				int i = sizeof(protocol_t);
				for (pos = 0; pos < 4; pos ++) {
					PKG_UINT32(msg, pos_array[pos], i);
				}
				init_proto_head(msg, PROTO_CANDY_POSITION_EX, i);
				send_to_map3(56, msg, i);
				return send_to_self_error(p, p->waitcmd, -ERR_candy_wrong_id, 1);
			}
			return do_pkg_candy_and_exch(p, p->r4_type);
		}
		case PROTO_GET_ITEMS_COUNT:
		case PROTO_GET_ITEMS_COUNT_NEW:
			return respond_items_count(p, buf, len);
		case PROTO_SEND_ONE_OF_TWO:
			return do_send_gift_oneoftwo(p, buf, len);
		case PROTO_SEND_GIFT_TWO:
			return do_send_gift_twooffour(p, buf, len);
		case PROTO_EXCHANGE_RAND_ITEM:
			return do_send_one_of_enum_items(p, buf, len);
		case PROTO_TANTALIZE_CAT:
			return tantalize_cat_get_something_callbak(p, buf, len);
			/*case PROTO_EXCHANGE_WITH_REPURATION:*/
			/*return check_if_have_garge_callback(p, buf, len);*/
		case PROTO_CREATE_BULDING:
		{
			int i = 0;
			uint32_t count;
			UNPKG_H_UINT32(buf, count, i);
			if(count) {
				UNPKG_H_UINT32(buf, count, i);
				UNPKG_H_UINT32(buf, count, i);
			}
			if(count == 0) {
				return send_to_self_error(p,p->waitcmd,ERR_not_have_certify, 1);
			}
			return send_request_to_db(SVR_PROTO_CREATE_BUILDING, p, 24, p->session + 4, p->id);
		}
		case PROTO_FIX_CARD_GAME_BUG:
			return get_lance_callback(p, p->id, buf, len);
		case PROTO_GET_SIG_CARD_FROM_NPC:
			return check_red_clothe_callback(p, p->id, buf, len);
		default:
			ERROR_RETURN(("Invalid cmd"), -1);

	}
	return 0;

}
コード例 #13
0
ファイル: wunder.c プロジェクト: KamalChaya/KamalC_code
int main(int argc, char **argv)
{
	initialize();
	clear_array();
	
	//Message to display on serial console. 
	//USART_SendString("\tHello world.\r\n"); 
	
	
	char str [33];
	
	while(1){
		PORTC = PINA;
		//Creating the "X":
		int i, j, k;
		
		//printf("\tHello \r\n");
		

		
			
		//IF no button pressed, light up as green
		if (PORTC != 0b00000001) {
			//clear_array();
			for (i = 7; i >= 0; i--) {
				PORTE = i;
				led_green(7-i, 7-i);
				led_green(7-i, i);
				_delay_ms(0.1);
				
				#ifdef DEBUG
					USART_SendString("\t\r\nX: ");
					USART_Transmit(itoa(7-i, str, 10));
					USART_SendString("\t\r\nY(top): ");
					USART_Transmit(itoa(7-i, str, 10));
					USART_SendString("\t\r\nY(bottom): ");
					USART_Transmit(itoa(i, str, 10));
				#endif
				
				set_array_green(0);
				
			}
		}
		
		//IF button 1 is pressed, light up as red
		if (PORTC & 0b00000010) {
			clear_array();
			for (i = 7; i >= 0; i--) {
				PORTE = i;
				led_red(7-i, 7-i);
				led_red(7-i, i);
				_delay_ms(0.1);
				
				#ifdef DEBUG
					USART_SendString("\t\r\nX: ");
					USART_Transmit(itoa(7-i, str, 10));
					USART_SendString("\t\r\nY(top): ");
					USART_Transmit(itoa(7-i, str, 10));
					USART_SendString("\t\r\nY(bottom): ");
					USART_Transmit(itoa(i, str, 10));
				#endif
				
				set_array_red(0);
				
			}
		}
		
		//IF button 5 is pressed, light up as blue.
		if (PORTC & 0b00100000) {
			clear_array();
			for (i = 7; i >= 0; i--) {
				PORTE = i;
				led_blue(7-i, 7-i);
				led_blue(7-i, i);
				_delay_ms(0.1);
				
				#ifdef DEBUG
					USART_SendString("\t\r\nX: ");
					USART_Transmit(itoa(7-i, str, 10));
					USART_SendString("\t\r\nY(top): ");
					USART_Transmit(itoa(7-i, str, 10));
					USART_SendString("\t\r\nY(bottom): ");
					USART_Transmit(itoa(i, str, 10));
				#endif
				
				set_array_blue(0);
			}
		}	
	}
}	
コード例 #14
0
ファイル: filefuncs.c プロジェクト: gvlx/gawk
static awk_value_t *
do_fts(int nargs, awk_value_t *result)
{
	awk_value_t pathlist, flagval, dest;
	awk_flat_array_t *path_array = NULL;
	char **pathvector = NULL;
	FTS *heirarchy;
	int flags;
	size_t i, count;
	int ret = -1;
	static const int mask = (
		  FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOCHDIR | FTS_PHYSICAL
		| FTS_SEEDOT | FTS_XDEV);

	assert(result != NULL);
	fts_errors = 0;		/* ensure a fresh start */

	if (do_lint && nargs != 3)
		lintwarn(ext_id, _("fts: called with incorrect number of arguments, expecting 3"));

	if (! get_argument(0, AWK_ARRAY, & pathlist)) {
		warning(ext_id, _("fts: bad first parameter"));
		update_ERRNO_int(EINVAL);
		goto out;
	}

	if (! get_argument(1, AWK_NUMBER, & flagval)) {
		warning(ext_id, _("fts: bad second parameter"));
		update_ERRNO_int(EINVAL);
		goto out;
	}

	if (! get_argument(2, AWK_ARRAY, & dest)) {
		warning(ext_id, _("fts: bad third parameter"));
		update_ERRNO_int(EINVAL);
		goto out;
	}

	/* flatten pathlist */
	if (! flatten_array(pathlist.array_cookie, & path_array)) {
		warning(ext_id, _("fts: could not flatten array\n"));
		goto out;
	}

	/* check the flags first, before the array flattening */

	/* get flags */
	flags = flagval.num_value;

	/* enforce physical or logical but not both, and not no_stat */
	if ((flags & (FTS_PHYSICAL|FTS_LOGICAL)) == 0
	    || (flags & (FTS_PHYSICAL|FTS_LOGICAL)) == (FTS_PHYSICAL|FTS_LOGICAL)) {
		update_ERRNO_int(EINVAL);
		goto out;
	}
	if ((flags & FTS_NOSTAT) != 0) {
		flags &= ~FTS_NOSTAT;
		if (do_lint)
			lintwarn(ext_id, _("fts: ignoring sneaky FTS_NOSTAT flag. nyah, nyah, nyah."));
	}
	flags &= mask;	/* turn off anything else */

	/* make pathvector */
	count = path_array->count + 1;
	emalloc(pathvector, char **, count * sizeof(char *), "do_fts");
	memset(pathvector, 0, count * sizeof(char *));

	/* fill it in */
	count--;	/* ignore final NULL at end of vector */
	for (i = 0; i < count; i++)
		pathvector[i] = path_array->elements[i].value.str_value.str;


	/* clear dest array */
	if (! clear_array(dest.array_cookie)) {
		warning(ext_id, _("fts: clear_array failed\n"));
		goto out;
	}

	/* let's do it! */
	if ((heirarchy = fts_open(pathvector, flags, NULL)) != NULL) {
		process(heirarchy, dest.array_cookie, (flags & FTS_SEEDOT) != 0);
		fts_close(heirarchy);

		if (fts_errors == 0)
			ret = 0;
	} else
		update_ERRNO_int(errno);

out:
	if (pathvector != NULL)
		free(pathvector);
	if (path_array != NULL)
		(void) release_flattened_array(pathlist.array_cookie, path_array);

	return make_number(ret, result);
}
コード例 #15
0
ファイル: filefuncs.c プロジェクト: gvlx/gawk
static int
fill_stat_array(const char *name, awk_array_t array, struct stat *sbuf)
{
	char *pmode;	/* printable mode */
	const char *type = "unknown";
	awk_value_t tmp;
	static struct ftype_map {
		unsigned int mask;
		const char *type;
	} ftype_map[] = {
		{ S_IFREG, "file" },
		{ S_IFBLK, "blockdev" },
		{ S_IFCHR, "chardev" },
		{ S_IFDIR, "directory" },
#ifdef S_IFSOCK
		{ S_IFSOCK, "socket" },
#endif
#ifdef S_IFIFO
		{ S_IFIFO, "fifo" },
#endif
#ifdef S_IFLNK
		{ S_IFLNK, "symlink" },
#endif
#ifdef S_IFDOOR	/* Solaris weirdness */
		{ S_IFDOOR, "door" },
#endif /* S_IFDOOR */
	};
	int j, k;

	/* empty out the array */
	clear_array(array);

	/* fill in the array */
	array_set(array, "name", make_const_string(name, strlen(name), & tmp));
	array_set_numeric(array, "dev", sbuf->st_dev);
	array_set_numeric(array, "ino", sbuf->st_ino);
	array_set_numeric(array, "mode", sbuf->st_mode);
	array_set_numeric(array, "nlink", sbuf->st_nlink);
	array_set_numeric(array, "uid", sbuf->st_uid);
	array_set_numeric(array, "gid", sbuf->st_gid);
	array_set_numeric(array, "size", sbuf->st_size);
	array_set_numeric(array, "blocks", sbuf->st_blocks);
	array_set_numeric(array, "atime", sbuf->st_atime);
	array_set_numeric(array, "mtime", sbuf->st_mtime);
	array_set_numeric(array, "ctime", sbuf->st_ctime);

	/* for block and character devices, add rdev, major and minor numbers */
	if (S_ISBLK(sbuf->st_mode) || S_ISCHR(sbuf->st_mode)) {
		array_set_numeric(array, "rdev", sbuf->st_rdev);
		array_set_numeric(array, "major", major(sbuf->st_rdev));
		array_set_numeric(array, "minor", minor(sbuf->st_rdev));
	}

#ifdef HAVE_ST_BLKSIZE
	array_set_numeric(array, "blksize", sbuf->st_blksize);
#endif /* HAVE_ST_BLKSIZE */

	pmode = format_mode(sbuf->st_mode);
	array_set(array, "pmode", make_const_string(pmode, strlen(pmode), & tmp));

	/* for symbolic links, add a linkval field */
	if (S_ISLNK(sbuf->st_mode)) {
		char *buf;
		ssize_t linksize;

		if ((buf = read_symlink(name, sbuf->st_size,
					& linksize)) != NULL)
			array_set(array, "linkval", make_malloced_string(buf, linksize, & tmp));
		else
			warning(ext_id, "stat: unable to read symbolic link `%s'", name);
	}

	/* add a type field */
	type = "unknown";	/* shouldn't happen */
	for (j = 0, k = sizeof(ftype_map)/sizeof(ftype_map[0]); j < k; j++) {
		if ((sbuf->st_mode & S_IFMT) == ftype_map[j].mask) {
			type = ftype_map[j].type;
			break;
		}
	}

	array_set(array, "type", make_const_string(type, strlen(type), &tmp));

	return 0;
}
コード例 #16
0
BOOL fill_material_hash()
{
    //-- Reset all the material hash records
    for (int i = material_hash_mask; i >= 0; i--) {
        material_hash[i].key = 0;
        material_hash[i].eval_endgame = NULL;
    }

    //-- Local variables
    t_hash key;
    t_hash index;
    int material[16];

    //-- K vs. k
    clear_array(material);
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0 || material_hash[index].eval_endgame != NULL)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- Q + K vs. k
    clear_array(material);
    material[WHITEQUEEN] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_QKvk;

    //-- K vs. q + k
    clear_array(material);
    material[BLACKQUEEN] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_Kvqk;

    //-- R + K vs. k
    clear_array(material);
    material[WHITEROOK] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_RKvk;

    //-- K vs. r + k
    clear_array(material);
    material[BLACKROOK] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_Kvrk;

    //-- B + B + K vs. k
    clear_array(material);
    material[WHITEBISHOP] = 2;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_BBKvk;

    //-- K vs. b + b + k
    clear_array(material);
    material[BLACKBISHOP] = 2;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_Kvbbk;

    //-- B + N + K vs. k
    clear_array(material);
    material[WHITEBISHOP] = 1;
    material[WHITEKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_BNKvk;

    //-- K vs. b + n + k
    clear_array(material);
    material[BLACKBISHOP] = 1;
    material[BLACKKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_Kvbnk;

    //-- K + N vs. k
    clear_array(material);
    material[WHITEKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K vs. k + n
    clear_array(material);
    material[BLACKKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K + N + N vs. k
    clear_array(material);
    material[WHITEKNIGHT] = 2;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K vs. k + n + n
    clear_array(material);
    material[BLACKKNIGHT] = 2;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K + B vs. k
    clear_array(material);
    material[WHITEBISHOP] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K vs. k + b
    clear_array(material);
    material[BLACKBISHOP] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K + B vs. k + n
    clear_array(material);
    material[WHITEBISHOP] = 1;
    material[BLACKKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K + N vs. k + b
    clear_array(material);
    material[WHITEKNIGHT] = 1;
    material[BLACKBISHOP] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K + R + N vs. k
    clear_array(material);
    material[WHITEKNIGHT] = 1;
    material[WHITEROOK] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KRNvk;

    //-- K vs. k + r + n
    clear_array(material);
    material[BLACKKNIGHT] = 1;
    material[BLACKROOK] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_Kvkrn;

    //-- K + R + B vs. k
    clear_array(material);
    material[WHITEBISHOP] = 1;
    material[WHITEROOK] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KRBvk;

    //-- K vs. k + r + b
    clear_array(material);
    material[BLACKBISHOP] = 1;
    material[BLACKROOK] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_Kvkrb;

    //-- K + N vs. k  + p
    clear_array(material);
    material[WHITEKNIGHT] = 1;
    material[BLACKPAWN] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KNvkp;

    //-- K + P vs. k + n
    clear_array(material);
    material[WHITEPAWN] = 1;
    material[BLACKKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KPvkn;

    //-- K + B vs. k  + p
    clear_array(material);
    material[WHITEBISHOP] = 1;
    material[BLACKPAWN] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KBvkp;

    //-- K + P vs. k + b
    clear_array(material);
    material[WHITEPAWN] = 1;
    material[BLACKBISHOP] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KPvkb;

    //-- K + B vs. k  + r
    clear_array(material);
    material[WHITEBISHOP] = 1;
    material[BLACKROOK] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KBvkr;

    //-- K + R vs. k + b
    clear_array(material);
    material[WHITEROOK] = 1;
    material[BLACKBISHOP] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KRvkb;

    //-- K + N vs. k  + r
    clear_array(material);
    material[WHITEKNIGHT] = 1;
    material[BLACKROOK] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KNvkr;

    //-- K + R vs. k + n
    clear_array(material);
    material[WHITEROOK] = 1;
    material[BLACKKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KRvkn;

    //-- K + N + N vs. k + n
    clear_array(material);
    material[WHITEKNIGHT] = 2;
    material[BLACKKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K + N vs. k + n + n
    clear_array(material);
    material[WHITEKNIGHT] = 1;
    material[BLACKKNIGHT] = 2;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K + N + N vs. k + n + n
    clear_array(material);
    material[WHITEKNIGHT] = 2;
    material[BLACKKNIGHT] = 2;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K + N + N vs. k + b
    clear_array(material);
    material[WHITEKNIGHT] = 2;
    material[BLACKBISHOP] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K + B vs. k + n + n
    clear_array(material);
    material[WHITEBISHOP] = 1;
    material[BLACKKNIGHT] = 2;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_insufficient_material;

    //-- K + R + B vs. k + r
    clear_array(material);
    material[WHITEBISHOP] = 1;
    material[WHITEROOK] = 1;
    material[BLACKROOK] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KRBvkr;

    //-- K + R + N vs. k + r
    clear_array(material);
    material[WHITEKNIGHT] = 1;
    material[WHITEROOK] = 1;
    material[BLACKROOK] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KRNvkr;

    //-- K + R vs. k + r + b
    clear_array(material);
    material[WHITEROOK] = 1;
    material[BLACKROOK] = 1;
    material[BLACKBISHOP] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KRvkrb;

    //-- K + R vs. k + r + n
    clear_array(material);
    material[WHITEROOK] = 1;
    material[BLACKROOK] = 1;
    material[BLACKKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KRvkrn;

	//-- K + P vs. k
	clear_array(material);
	material[WHITEPAWN] = 1;
	key = get_material_hash(material);
	index = key & material_hash_mask;
	assert(material_hash[index].key != key);
	if (material_hash[index].key != 0)
		return FALSE;
	material_hash[index].key = key;
	material_hash[index].eval_endgame = &known_endgame_KPvk;

	//-- K vs. k + p
	clear_array(material);
	material[BLACKPAWN] = 1;
	key = get_material_hash(material);
	index = key & material_hash_mask;
	assert(material_hash[index].key != key);
	if (material_hash[index].key != 0)
		return FALSE;
	material_hash[index].key = key;
	material_hash[index].eval_endgame = &known_endgame_Kvkp;

	//-- K + Q vs. k + q + b
    clear_array(material);
    material[WHITEQUEEN] = 1;
    material[BLACKQUEEN] = 1;
    material[BLACKBISHOP] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KQvkqb;

    //-- K + Q vs. k + q + n
    clear_array(material);
    material[WHITEQUEEN] = 1;
    material[BLACKQUEEN] = 1;
    material[BLACKKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KQvkqn;

    //-- K + Q + B vs. k + q
    clear_array(material);
    material[WHITEQUEEN] = 1;
    material[WHITEBISHOP] = 1;
    material[BLACKQUEEN] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KQBvkq;

    //-- K + Q + N vs. k + q
    clear_array(material);
    material[WHITEQUEEN] = 1;
    material[WHITEKNIGHT] = 1;
    material[BLACKQUEEN] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KQNvkq;

    //-- K + B + N vs. k + b
    clear_array(material);
    material[WHITEKNIGHT] = 1;
    material[WHITEBISHOP] = 1;
    material[BLACKBISHOP] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KBNvkb;

    //-- K + B + N vs. k + n
    clear_array(material);
    material[WHITEKNIGHT] = 1;
    material[WHITEBISHOP] = 1;
    material[BLACKKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KBNvkn;

    //-- K + B vs. k + b + n
    clear_array(material);
    material[WHITEBISHOP] = 1;
    material[BLACKBISHOP] = 1;
    material[BLACKKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KBvkbn;

    //-- K + N vs. k + b + n
    clear_array(material);
    material[WHITEKNIGHT] = 1;
    material[BLACKBISHOP] = 1;
    material[BLACKKNIGHT] = 1;
    key = get_material_hash(material);
    index = key & material_hash_mask;
    assert(material_hash[index].key != key);
    if (material_hash[index].key != 0)
        return FALSE;
    material_hash[index].key = key;
    material_hash[index].eval_endgame = &known_endgame_KNvkbn;

	//-- K + B + P vs. k
	clear_array(material);
	material[WHITEPAWN] = 1;
	material[WHITEBISHOP] = 1;
	key = get_material_hash(material);
	index = key & material_hash_mask;
	assert(material_hash[index].key != key);
	if (material_hash[index].key != 0)
		return FALSE;
	material_hash[index].key = key;
	material_hash[index].eval_endgame = &known_endgame_KBPvk;

	//-- K vs. k + b + p
	clear_array(material);
	material[BLACKPAWN] = 1;
	material[BLACKBISHOP] = 1;
	key = get_material_hash(material);
	index = key & material_hash_mask;
	assert(material_hash[index].key != key);
	if (material_hash[index].key != 0)
		return FALSE;
	material_hash[index].key = key;
	material_hash[index].eval_endgame = &known_endgame_Kvkbp;

	//-- K + B + P + P vs. k
	clear_array(material);
	material[WHITEPAWN] = 2;
	material[WHITEBISHOP] = 1;
	key = get_material_hash(material);
	index = key & material_hash_mask;
	assert(material_hash[index].key != key);
	if (material_hash[index].key != 0)
		return FALSE;
	material_hash[index].key = key;
	material_hash[index].eval_endgame = &known_endgame_KBPPvk;

	//-- K vs. k + b + p + p
	clear_array(material);
	material[BLACKPAWN] = 2;
	material[BLACKBISHOP] = 1;
	key = get_material_hash(material);
	index = key & material_hash_mask;
	assert(material_hash[index].key != key);
	if (material_hash[index].key != 0)
		return FALSE;
	material_hash[index].key = key;
	material_hash[index].eval_endgame = &known_endgame_Kvkbpp;

	//-- K + P + P vs. k
	clear_array(material);
	material[WHITEPAWN] = 2;
	key = get_material_hash(material);
	index = key & material_hash_mask;
	assert(material_hash[index].key != key);
	if (material_hash[index].key != 0)
		return FALSE;
	material_hash[index].key = key;
	material_hash[index].eval_endgame = &known_endgame_KPPvk;

	//-- K vs. k + p + p
	clear_array(material);
	material[BLACKPAWN] = 2;
	key = get_material_hash(material);
	index = key & material_hash_mask;
	assert(material_hash[index].key != key);
	if (material_hash[index].key != 0)
		return FALSE;
	material_hash[index].key = key;
	material_hash[index].eval_endgame = &known_endgame_Kvkpp;

	return TRUE;

}
コード例 #17
0
int main(int argc, char *argv[])
{
	int pseudo_hash[NHASH];
	int x, y, z;

	clear_array(pseudo_hash, NHASH);
	for (x = -5; x <= 5; x++) {
		for (y = -5; y <= 5; y++) {
			struct point p;
			p.x = x;
			p.y = y;
			pseudo_hash[hash_point(&p)]++;
		}
	}
	printf("2D integer\n");
	print_histogram(pseudo_hash, NHASH);

	printf("\n");

	clear_array(pseudo_hash, NHASH);
	for (x = -5; x <= 5; x++) {
		for (y = -5; y <= 5; y++) {
			struct point_polar p;
			p.r = sqrt(x * x + y * y);
			p.theta = atan2(y, x);
			pseudo_hash[hash_point_polar(&p)]++;
		}
	}
	printf("2D integer polar\n");
	print_histogram(pseudo_hash, NHASH);
	printf("\n");

	clear_array(pseudo_hash, NHASH);
	for (x = -4; x <= 4; x++) {
		for (y = -4; y <= 4; y++) {
			for (z = -4; z <= 4; z++) {
				struct point_3d p;
				p.x = x;
				p.y = y;
				p.z = z;
				pseudo_hash[hash_point_3d(&p)]++;
			}
		}
	}
	printf("3D integer\n");
	print_histogram(pseudo_hash, NHASH);

	printf("\n");

	clear_array(pseudo_hash, NHASH);
	for (x = -5; x <= 5; x++) {
		for (y = -5; y <= 5; y++) {
			struct point_float p;
			p.x = cos(x);
			p.y = tan(y);
			pseudo_hash[hash_point_float(&p)]++;
		}
	}
	printf("2D float\n");
	print_histogram(pseudo_hash, NHASH);

	printf("\n");

	clear_array(pseudo_hash, NHASH);
	for (x = -5; x <= 5; x++) {
		for (y = -5; y <= 5; y++) {
			struct point_float p;
			p.x = x / 100.0;
			p.y = y / 100.0;
			pseudo_hash[hash_point_float(&p)]++;
		}
	}
	printf("2D float, closely spaced\n");
	print_histogram(pseudo_hash, NHASH);

	printf("\n");

	clear_array(pseudo_hash, NHASH);
	for (x = -5; x <= 5; x++) {
		for (y = -5; y <= 5; y++) {
			struct point_float p;
			p.x = x / 1000.0;
			p.y = y / 1000.0;
			pseudo_hash[hash_point_float(&p)]++;
		}
	}
	printf("2D float, very closely spaced\n");
	print_histogram(pseudo_hash, NHASH);

	return 0;
}
コード例 #18
0
ファイル: bd.c プロジェクト: matthagy/pbd
static inline void
setup_temp_array(int size, array_t *arr)
{
        clear_array(arr);
        CEX_prealloc_array(arr, size);
}