示例#1
0
文件: play.c 项目: SimonBoeuf/filler
int	play(t_map *map, t_token *token, int x, int y)
{
	int	i;
	int	j;
	int	touch;
	int	xtoplay;
	int	ytoplay;

	touch = 0;
	i = 0;
	while (i < token->rows && touch < 2)
	{
		j = 0;
		while (j < token->cols && touch < 2)
		{
			xtoplay = i + x < 0 ? map->rows + i + x : x + i;
			ytoplay = y + j < 0 ? map->cols + j + y : y + j;
			if (is_player(map->token[xtoplay][ytoplay]) && is_shape(token->token[i][j]))
				touch++;
			if (is_opponent_player(map->token[xtoplay][ytoplay]) && is_shape(token->token[i][j]))
				touch += 2;
			j++;
		}
		i++;
	}
	return (touch == 1);
}
示例#2
0
文件: cell.c 项目: SimonBoeuf/filler
int	get_cell_val(t_cell *c, t_token *t, t_play *p, t_map *m)
{
	int	val;
	int	i;
	int	j;
	int	xtp;
	int	ytp;

	val = 0;
	i = 0;
	while (i < t->rows)
	{
		j = 0;
		while (j < t->cols)
		{
			if (is_shape(t->token[i][j]))
			{
				xtp = i + p->x < 0 ? m->rows + i + p->x : i + p->x;
				ytp = j + p->y < 0 ? m->cols + j + p->y : j + p->y;
				if (abs(xtp - c->x) - abs(ytp - c->y) == 1)
					return(-1);
				if (m->rows + m->cols - min(abs(xtp - c->x), abs(ytp - c->y)) > val)
						val = m->rows + m->cols - min(abs(xtp - c->x), abs(ytp - c->y));
			}
			j++;
		}
		i++;
	}
	return (val);
}
示例#3
0
文件: text.c 项目: regnauld/citaa
void
extract_text(struct image *img)
{
	int y, x, sx;
	CHAR *buf, *s;
	struct rgb rgb;
	struct component *c, *last_c = NULL;
	int shape;
	struct text *t, *last_t = NULL;

	buf = malloc(sizeof(CHAR)*img->w);
	if (!buf)	croak(1, "extract_text:malloc(buf)");

	for (y = 0; y < img->h; y++) {
		last_c = NULL;
		last_t = NULL;
		for (x = 0; x < img->w; x++) {
			s = buf;
			sx = x;

			while (img->d[y][x] != ' ' && component_marks->d[y][x] == ' ') {
				*s++ = img->d[y][x++];
			}
			*s = '\0';
			if (s != buf) {
				printf("%d,%d: |%s|\n", y, sx, buf);
				c = find_enclosing_component(&components, y, sx);
				if (is_color(buf, &rgb) && c) {
					double percepted_luminance = 1 - ( 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b)/0xF;

					c->has_custom_background = 1;
					c->custom_background = rgb;
					if (percepted_luminance >= 0.5)
						c->white_text = 1;
					printf("COLOR %x%x%x\n", rgb.r, rgb.g, rgb.b);
				} else if (is_shape(buf, &shape) && c) {
					c->shape = shape;
				} else {
					if (last_t && last_c == c &&
						sx > 0 && img->d[y][sx-1] == ' ' &&
						last_t->x + last_t->len + 1 == sx)
					{
						extend_text(last_t, 1, buf);
					} else {
						t = create_text(y, sx, buf);
						TAILQ_INSERT_TAIL(c ? &c->text : &free_text, t, list);
						last_c = c;
						last_t = t;
					}
				}
			}
		}
	}
	free(buf);
}