コード例 #1
0
ファイル: execute.c プロジェクト: cooperstevenson/Go-Diagrams
int Do_Markup(struct Node *n, struct Property *p, struct BoardStatus *st)
{
	int x, y;
	struct PropValue *v;
	U_SHORT flag;

	if(sgfc->info->GM != 1)		/* game != Go? */
		return(TRUE);

	v = p->value;
	flag = sgf_token[p->id].data;

	while(v)
	{
		x = DecodePosChar(v->value[0]) - 1;
		y = DecodePosChar(v->value[1]) - 1;
	
		if(st->markup[MXY(x,y)] & flag)
		{
			PrintError(E_POSITION_NOT_UNIQUE, v->buffer, "Markup", p->idstr);
			v = Del_PropValue(p, v);
			continue;
		}

		st->markup[MXY(x,y)] |= flag;
		st->mrkp_chngd = TRUE;
		v = v->next;
	}

	return(TRUE);
}
コード例 #2
0
ファイル: execute.c プロジェクト: cooperstevenson/Go-Diagrams
int Do_Mark(struct Node *n, struct Property *p, struct BoardStatus *st)
{
	int x, y;
	struct PropValue *v;

	if(sgfc->info->GM != 1)		/* game != Go? */
		return(TRUE);

	v = p->value;
	while(v)
	{
		x = DecodePosChar(v->value[0]) - 1;
		y = DecodePosChar(v->value[1]) - 1;
	
		if(st->markup[MXY(x,y)] & ST_MARKUP)
		{
			PrintError(E_POSITION_NOT_UNIQUE, v->buffer, "Markup", p->idstr);
		}
		else
		{
			st->markup[MXY(x,y)] |= ST_MARKUP;
			st->mrkp_chngd = TRUE;

			if(st->board[MXY(x,y)])
				New_PropValue(n, TKN_TR, v->value, NULL, FALSE);
			else
				New_PropValue(n, TKN_MA, v->value, NULL, FALSE);
		}
		v = v->next;
	}

	return(FALSE);
}
コード例 #3
0
ファイル: execute.c プロジェクト: cooperstevenson/Go-Diagrams
int Do_Letter(struct Node *n, struct Property *p, struct BoardStatus *st)
{
	int x, y;
	struct PropValue *v;
	char letter[2] = "a";

	if(sgfc->info->GM != 1)		/* game != Go? */
		return(TRUE);

	v = p->value;
	while(v)
	{
		x = DecodePosChar(v->value[0]) - 1;
		y = DecodePosChar(v->value[1]) - 1;
	
		if(st->markup[MXY(x,y)] & ST_LABEL)
		{
			PrintError(E_POSITION_NOT_UNIQUE, v->buffer, "Label", p->idstr);
		}
		else
		{
			st->markup[MXY(x,y)] |= ST_LABEL;
			st->mrkp_chngd = TRUE;
			New_PropValue(n, TKN_LB, v->value, letter, FALSE);
			letter[0]++;
		}

		v = v->next;
	}

	return(FALSE);
}
コード例 #4
0
ファイル: execute.c プロジェクト: cooperstevenson/Go-Diagrams
int Do_Move(struct Node *n, struct Property *p, struct BoardStatus *st)
{
	int x, y;
	char color;

	if(sgfc->info->GM != 1)		/* game != Go? */
		return(TRUE);

	if(st->annotate & ST_MOVE)	/* there's a move already? */
	{
		PrintError(E_TWO_MOVES_IN_NODE, p->buffer);
		Split_Node(n, 0, p->id, TRUE);
		return(TRUE);
	}

	st->annotate |= ST_MOVE;

	if(!strlen(p->value->value))	/* pass move */
		return(TRUE);

	x = DecodePosChar(p->value->value[0]) - 1;
	y = DecodePosChar(p->value->value[1]) - 1;
	color = (char)sgf_token[p->id].data;

	if(st->board[MXY(x,y)])
		PrintError(WS_ILLEGAL_MOVE, p->buffer);

	st->board[MXY(x,y)] = color;
	Capture_Stones(st, color, x-1, y);		/* check for prisoners */
	Capture_Stones(st, color, x+1, y);
	Capture_Stones(st, color, x, y-1);
	Capture_Stones(st, color, x, y+1);
	Capture_Stones(st, ~color, x, y);		/* check for suicide */

	if(option_del_move_markup)			/* if del move markup, then */
	{						/* mark move position as markup */
		st->markup[MXY(x,y)] |= ST_MARKUP;	/* -> other markup at this */
		st->mrkp_chngd = TRUE;			/* position will be deleted */
	}

	return(TRUE);
}
コード例 #5
0
ファイル: parse.c プロジェクト: horaceho/sgfc
int Parse_Move(char *value, U_SHORT flags)
{
	int ret = 1, emptyOrSpace = FALSE, c;

	if(sgfc->info->GM != 1)			/* game != GO ? */
		return(1);

	/* At first only delete space so that we can distinguish
	 * FF4 pass move from erroneous property values */
	if(Kill_Chars(value, C_ISSPACE, NULL))
		ret = -1;
	if(!strlen(value))
		emptyOrSpace = TRUE;

	if(Kill_Chars(value, C_NOT_ISALPHA, NULL))
		ret = -1;

	if(!strlen(value))				/* empty value? */
	{
		if(flags & PARSE_MOVE && emptyOrSpace)
		{
			if(sgfc->info->FF >= 4)
				return(ret);
			else					/* new pass '[]' in old FF[1-3] */
				return(-101);		/* possible cause: missing FF   */
		}
		else
			return(0);
	}

	if(strlen(value) < 2)			/* value too short */
		return(0);

	if(strlen(value) != 2)			/* value too long? */
	{
		*(value+2) = 0;
		ret = -1;
	}

	if((flags & PARSE_MOVE) && !strcmp(value, "tt"))
	{
		if(sgfc->info->bwidth <= 19 && sgfc->info->bheight <= 19)
		{
			*value = 0;					/* new pass */
			return(ret);
		}
	}

	c = DecodePosChar(*value);
	if(!c)								/* check range */
		return(0);
	if(c > sgfc->info->bwidth)
		return(0);

	c = DecodePosChar(*(value+1));
	if(!c)
		return(0);
	if(c > sgfc->info->bheight)
		return(0);

	return(ret);
}
コード例 #6
0
ファイル: execute.c プロジェクト: cooperstevenson/Go-Diagrams
int Do_Addstones(struct Node *n, struct Property *p, struct BoardStatus *st)
{
	int x, y;
	char color;
	struct PropValue *v, *w;
	struct Property h;

	if(sgfc->info->GM != 1)		/* game != Go? */
		return(TRUE);

	h.value = NULL;
	h.valend = NULL;

	color = (char)sgf_token[p->id].data;

	v = p->value;
	while(v)
	{
		x = DecodePosChar(v->value[0]) - 1;
		y = DecodePosChar(v->value[1]) - 1;
	
		if(st->markup[MXY(x,y)] & ST_ADDSTONE)
		{
			PrintError(E_POSITION_NOT_UNIQUE, v->buffer, "AddStone", p->idstr);
			v = Del_PropValue(p, v);
			continue;
		}

		st->markup[MXY(x,y)] |= ST_ADDSTONE;
		st->mrkp_chngd = TRUE;

		if(st->board[MXY(x,y)] == color)		/* Add property is redundant */
		{
			w = v->next;
			Delete(&p->value, v);
			AddTail(&h.value, v);
			v = w;
			continue;
		}

		st->board[MXY(x,y)] = color;
		v = v->next;
	}

	if(h.value)
	{
		x = PrintError(WS_ADDSTONE_REDUNDANT, p->buffer, p->idstr);

		v = h.value;
		while(v)
		{
			if(x)	fprintf(E_OUTPUT, "[%s]", v->value);
			v = Del_PropValue(&h, v);
		}

		if(x)
			fprintf(E_OUTPUT, "\n");
	}

	return(TRUE);
}