示例#1
0
void SEARCHER::do_move(const int& move) {

	int from = m_from(move),to = m_to(move),sq;

	/*remove captured piece*/
	if(m_capture(move)) {
		if(is_ep(move)) {
			sq = to - pawn_dir[player];
		} else {
			sq = to;
		}
		pcRemove(m_capture(move),sq);
		board[sq] = empty;
	}

	/*move piece*/
	if(m_promote(move)) {
		board[to] = m_promote(move);
		board[from] = empty;
		pcAdd(m_promote(move),to);
		pcRemove(COMBINE(player,pawn),from);
	} else {
		board[to] = board[from];
		board[from] = empty;
		pcSwap(from,to);
	}

	/*move castle*/
	if(is_castle(move)) {
        int fromc,toc;
		if(to > from) {
           fromc = to + RR;
		   toc = to + LL;
		} else {
           fromc = to + 2*LL;
		   toc = to + RR;
		}
		board[toc] = board[fromc];
		board[fromc] = empty;
		pcSwap(fromc,toc);
	} 

	/*update current state*/
	epsquare = 0;
	fifty++;
	if(DECOMB(player,m_piece(move)) == pawn) {
		fifty = 0;
	    if(to - from == (2 * pawn_dir[player])) {
            epsquare = ((to + from) >> 1);
		}
示例#2
0
void print_move(const int& move) {
    char f[6],t[6];
    sq_str(m_from(move),f);
    sq_str(m_to(move),t);
    print("%s %s %c %c %c ep = %d",f,t,piece_name[m_piece(move)],
        piece_name[m_capture(move)],piece_name[m_promote(move)],is_ep(move));
}
示例#3
0
文件: misc.c 项目: detiffel/benchmark
static void
prepare_call(void)
{
    call_argc = 0;
    /* Gnuplot "call" command can have up to 10 arguments "$0" to "$9" */
    while (!END_OF_COMMAND && call_argc <= 9) {
	if (isstring(c_token))
	    m_quote_capture(&call_args[call_argc++], c_token, c_token);
	else
	    m_capture(&call_args[call_argc++], c_token, c_token);
	c_token++;
    }
    if (!END_OF_COMMAND)
	int_error(++c_token, "too many arguments for 'call <file>'");
}
示例#4
0
文件: parse.c 项目: Reen/gnuplot
static int
parse_assignment_expression()
{
    /* Check for assignment operator */
    if (isletter(c_token) && equals(c_token + 1, "=")) {
	/* push the variable name */
	union argument *foo = add_action(PUSHC);
	char *varname = NULL;
	m_capture(&varname,c_token,c_token);
	foo->v_arg.type = STRING;
	foo->v_arg.v.string_val = varname;
	c_token += 2;
	/* and the expression whose value it will get */
	parse_expression();
	/* and the actual assignment operation */
	(void) add_action(ASSIGN);
	return 1;
    }
    return 0;
}
示例#5
0
void define()
{
    register int start_token;	/* the 1st token in the function definition */
    register struct udvt_entry *udv;
    register struct udft_entry *udf;

    if (equals(c_token + 1, "(")) {
	/* function ! */
	int dummy_num = 0;
	struct at_type *at_tmp;
	char save_dummy[MAX_NUM_VAR][MAX_ID_LEN + 1];
	memcpy(save_dummy, c_dummy_var, sizeof(save_dummy));
	start_token = c_token;
	do {
	    c_token += 2;	/* skip to the next dummy */
	    copy_str(c_dummy_var[dummy_num++], c_token, MAX_ID_LEN);
	} while (equals(c_token + 1, ",") && (dummy_num < MAX_NUM_VAR));
	if (equals(c_token + 1, ","))
	    int_error("function contains too many parameters", c_token + 2);
	c_token += 3;		/* skip (, dummy, ) and = */
	if (END_OF_COMMAND)
	    int_error("function definition expected", c_token);
	udf = dummy_func = add_udf(start_token);
	if ((at_tmp = perm_at()) == (struct at_type *) NULL)
	    int_error("not enough memory for function", start_token);
	if (udf->at)		/* already a dynamic a.t. there */
	    free((char *) udf->at);	/* so free it first */
	udf->at = at_tmp;	/* before re-assigning it. */
	memcpy(c_dummy_var, save_dummy, sizeof(save_dummy));
	m_capture(&(udf->definition), start_token, c_token - 1);
	dummy_func = NULL;	/* dont let anyone else use our workspace */
    } else {
	/* variable ! */
	start_token = c_token;
	c_token += 2;
	udv = add_udv(start_token);
	(void) const_express(&(udv->udv_value));
	udv->udv_undef = FALSE;
    }
}
示例#6
0
文件: parse.c 项目: Reen/gnuplot
/*
 * Syntax: set link {x2|y2} {via <expression1> inverse <expression2>}
 * Create action code tables for the functions linking primary and secondary axes.
 * expression1 maps primary coordinates into the secondary coordinate space.
 * expression2 maps secondary coordinates into the primary coordinate space.
 */
void
parse_link_via( struct udft_entry *udf )
{
    int start_token;
    
    /* Caller left us pointing at "via" or "inverse" */
    c_token++;
    start_token = c_token;
    if (END_OF_COMMAND)
	int_error(c_token,"Missing expression");

    /* Save action table for the linkage mapping */
    strcpy(c_dummy_var[0], "x");
    strcpy(c_dummy_var[1], "y");
    dummy_func = udf;
    free_at(udf->at);
    udf->at = perm_at();
    dummy_func = NULL;

    /* Save the mapping expression itself */
    m_capture(&(udf->definition), start_token, c_token - 1);
}
示例#7
0
bool CACBot::CanTakeFlag(const entity &e)
{
    if(!m_flags(gamemode)) return false;
    if(m_secure(gamemode))
    {
        if(e.type != CTF_FLAG || e.attr2 < 2 || e.attr2 > 2 + TEAM_SPECT) return false;
        return (e.attr2 - 2) != m_pMyEnt->team || e.attr4;
    }
    else
    {
        if(e.type != CTF_FLAG || (e.attr2 != 0 && e.attr2 != 1)) return false;
        flaginfo &f = flaginfos[e.attr2];
        flaginfo &of = flaginfos[team_opposite(e.attr2)];
        const int i = f.team;
        switch(f.state)
        {
            case CTFF_INBASE: // go to this base
                // if CTF capturing our flag
                if(m_capture(gamemode) && (i != m_pMyEnt->team || of.state != CTFF_STOLEN || of.actor != m_pMyEnt)) return false;
                // in HTF to take out own flag
                else if(m_hunt(gamemode) && i != m_pMyEnt->team) return false;
                // in BTF to take own flag, and to score it on the enemy base
                else if(m_bomber(gamemode) && i != m_pMyEnt->team && (of.state != CTFF_STOLEN || of.actor != m_pMyEnt)) return false;
                // if KTF
                break;
            case CTFF_STOLEN: // go to our stolen flag's base
                // if rCTF and we have our flag
                if(!m_return(gamemode, mutators) || f.actor != m_pMyEnt || f.team != m_pMyEnt->team) return false;
                break;
            case CTFF_IDLE: // not active
                return false;
            case CTFF_DROPPED: // take every dropped flag, regardless of anything!
                break;
        }
        return true;
    }
}
示例#8
0
文件: parse.c 项目: Reen/gnuplot
/* create action code for 'sum' expressions */
static void
parse_sum_expression()
{
    /* sum [<var>=<range>] <expr>
     * - Pass a udf to f_sum (with action code (for <expr>) that is not added
     *   to the global action table).
     * - f_sum uses a newly created udv (<var>) to pass the current value of
     *   <var> to <expr> (resp. its ac).
     * - The original idea was to treat <expr> as function f(<var>), but there
     *   was the following problem: Consider 'g(x) = sum [k=1:4] f(k)'. There
     *   are two dummy variables 'x' and 'k' from different functions 'g' and
     *   'f' which would require changing the parsing of dummy variables.
     */

    char *errormsg = "Expecting 'sum [<var> = <start>:<end>] <expression>'\n";
    char *varname = NULL;
    union argument *arg;
    struct udft_entry *udf;

    struct at_type * save_at;
    int save_at_size;
    int i;
    
    /* Caller already checked for string "sum [" so skip both tokens */
    c_token += 2;

    /* <var> */
    if (!isletter(c_token))
        int_error(c_token, errormsg);
    /* create a user defined variable and pass it to f_sum via PUSHC, since the
     * argument of f_sum is already used by the udf */
    m_capture(&varname, c_token, c_token);
    add_udv(c_token);
    arg = add_action(PUSHC);
    Gstring(&(arg->v_arg), varname);
    c_token++;

    if (!equals(c_token, "="))
        int_error(c_token, errormsg);
    c_token++;

    /* <start> */
    parse_expression();

    if (!equals(c_token, ":"))
        int_error(c_token, errormsg);
    c_token++;

    /* <end> */
    parse_expression();

    if (!equals(c_token, "]"))
        int_error(c_token, errormsg);
    c_token++;

    /* parse <expr> and convert it to a new action table. */
    /* modeled on code from temp_at(). */
    /* 1. save environment to restart parsing */
    save_at = at;
    save_at_size = at_size;
    at = NULL;

    /* 2. save action table in a user defined function */
    udf = (struct udft_entry *) gp_alloc(sizeof(struct udft_entry), "sum");
    udf->next_udf = (struct udft_entry *) NULL;
    udf->udf_name = NULL; /* TODO maybe add a name and definition */ 
    udf->at = perm_at();
    udf->definition = NULL;
    udf->dummy_num = 0;
    for (i = 0; i < MAX_NUM_VAR; i++)
        (void) Ginteger(&(udf->dummy_values[i]), 0);

    /* 3. restore environment */
    at = save_at;
    at_size = save_at_size;

    /* pass the udf to f_sum using the argument */
    add_action(SUM)->udf_arg = udf;
}
示例#9
0
文件: misc.c 项目: student-t/quast
static void
prepare_call(int calltype)
{
    struct udvt_entry *udv;
    int argindex;
    if (calltype == 2) {
	call_argc = 0;
	while (!END_OF_COMMAND && call_argc <= 9) {
	    call_args[call_argc] = try_to_get_string();
	    if (!call_args[call_argc]) {
		int save_token = c_token;

		/* This catches call "file" STRINGVAR (expression) */
		if (type_udv(c_token) == STRING) {
		    call_args[call_argc] = gp_strdup(add_udv(c_token)->udv_value.v.string_val);
		    c_token++;

		/* Evaluates a parenthesized expression and store the result in a string */
		} else if (equals(c_token, "(")) {
		    char val_as_string[32];
		    struct value a;
		    const_express(&a);
		    switch(a.type) {
			case CMPLX: /* FIXME: More precision? Some way to provide a format? */
				sprintf(val_as_string, "%g", a.v.cmplx_val.real);
				call_args[call_argc] = gp_strdup(val_as_string);
				break;
			default:
				int_error(save_token, "Unrecognized argument type");
				break;
			case INTGR:	
				sprintf(val_as_string, "%d", a.v.int_val);
				call_args[call_argc] = gp_strdup(val_as_string);
				break;
		    } 

		/* old (pre version 5) style wrapping of bare tokens as strings */
		/* is still useful for passing unquoted numbers */
		} else {
		    m_capture(&call_args[call_argc], c_token, c_token);
		    c_token++;
		}
	    }
	    call_argc++;
	}
	lf_head->c_token = c_token;
	if (!END_OF_COMMAND)
	    int_error(++c_token, "too many arguments for 'call <file>'");

    } else if (calltype == 5) {
	/* lf_push() moved our call arguments from call_args[] to lf->call_args[] */
	/* call_argc was determined at program entry */
	for (argindex = 0; argindex < 10; argindex++) {
	    call_args[argindex] = lf_head->call_args[argindex];
	    lf_head->call_args[argindex] = NULL;	/* just to be safe */
	}

    } else {
	/* "load" command has no arguments */
	call_argc = 0;
    }

    /* Old-style "call" arguments were referenced as $0 ... $9 and $# */
    /* New-style has ARG0 = script-name, ARG1 ... ARG9 and ARGC */
    /* FIXME:  If we defined these on entry, we could use get_udv* here */
    udv = add_udv_by_name("ARGC");
    Ginteger(&(udv->udv_value), call_argc);
    udv->udv_undef = FALSE;
    udv = add_udv_by_name("ARG0");
    gpfree_string(&(udv->udv_value));
    Gstring(&(udv->udv_value), gp_strdup(lf_head->name));
    udv->udv_undef = FALSE;
    for (argindex = 1; argindex <= 9; argindex++) {
	char *arg = gp_strdup(call_args[argindex-1]);
	udv = add_udv_by_name(argname[argindex]);
	gpfree_string(&(udv->udv_value));
	Gstring(&(udv->udv_value), arg ? arg : gp_strdup(""));
	udv->udv_undef = FALSE;
    }
}
示例#10
0
文件: misc.c 项目: easeip/GnuPlot-OSX
void
load_file(FILE *fp, char *name, TBOOLEAN can_do_args)
{
    int len;

    int start, left;
    int more;
    int stop = FALSE;

    lf_push(fp);		/* save state for errors and recursion */
    do_load_arg_substitution = can_do_args;

    if (fp == (FILE *) NULL) {
	os_error(c_token, "Cannot open %s file '%s'",
		 can_do_args ? "call" : "load", name);
    } else if (fp == stdin) {
	/* DBT 10-6-98  go interactive if "-" named as load file */
	interactive = TRUE;
	while (!com_line());
    } else {
	/* go into non-interactive mode during load */
	/* will be undone below, or in load_file_error */
	int argc = 0; /* number arguments passed by "call" */
	interactive = FALSE;
	inline_num = 0;
	lf_head->name = name;

	if (can_do_args) {
	    /* Gnuplot "call" command can have up to 10 arguments "$0" to "$9" */
	    while (!END_OF_COMMAND && argc <= 9) {
		if (isstring(c_token))
		    m_quote_capture(&call_args[argc++], c_token, c_token);
		else
		    m_capture(&call_args[argc++], c_token, c_token);
		c_token++;
	    }
	    if (!END_OF_COMMAND)
		int_error(++c_token, "too many arguments for 'call <file>'");
	}

	/* These were initialized to NULL in lf_push(); will be freed in lf_pop() */
	lf_head->c_token = c_token;
	lf_head->num_tokens = num_tokens;
	lf_head->tokens = gp_alloc(num_tokens * sizeof(struct lexical_unit), "lf tokens");
	memcpy(lf_head->tokens, token, num_tokens * sizeof(struct lexical_unit));
	lf_head->input_line = gp_strdup(gp_input_line);
	
	while (!stop) {		/* read all commands in file */
	    /* read one command */
	    left = gp_input_line_len;
	    start = 0;
	    more = TRUE;

	    while (more) {
		if (fgets(&(gp_input_line[start]), left, fp) == (char *) NULL) {
		    stop = TRUE;	/* EOF in file */
		    gp_input_line[start] = '\0';
		    more = FALSE;
		} else {
		    inline_num++;
		    len = strlen(gp_input_line) - 1;
		    if (gp_input_line[len] == '\n') {	/* remove any newline */
			gp_input_line[len] = '\0';
			/* Look, len was 1-1 = 0 before, take care here! */
			if (len > 0)
			    --len;
			if (gp_input_line[len] == '\r') {	/* remove any carriage return */
			    gp_input_line[len] = NUL;
			    if (len > 0)
				--len;
			}
		    } else if (len + 2 >= left) {
			extend_input_line();
			left = gp_input_line_len - len - 1;
			start = len + 1;
			continue;	/* don't check for '\' */
		    }
		    if (gp_input_line[len] == '\\') {
			/* line continuation */
			start = len;
			left = gp_input_line_len - start;
		    } else
			more = FALSE;
		}
	    }

	    if (strlen(gp_input_line) > 0) {
		if (can_do_args) {
		    int il = 0;
		    char *rl;
		    char *raw_line = gp_strdup(gp_input_line);

		    rl = raw_line;
		    *gp_input_line = '\0';
		    while (*rl) {
			int aix;
			if (*rl == '$'
			    && ((aix = *(++rl)) != 0)	/* HBB 980308: quiet BCC warning */
			    && ((aix >= '0' && aix <= '9') || aix == '#')) {
			    if (aix == '#') {
				/* replace $# by number of passed arguments */
				len = argc < 10 ? 1 : 2; /* argc can be 0 .. 10 */
				while (gp_input_line_len - il < len + 1) {
				    extend_input_line();
				}
				sprintf(gp_input_line + il, "%i", argc);
				il += len;
			    } else
			    if (call_args[aix -= '0']) {
				/* replace $n for n=0..9 by the passed argument */
				len = strlen(call_args[aix]);
				while (gp_input_line_len - il < len + 1) {
				    extend_input_line();
				}
				strcpy(gp_input_line + il, call_args[aix]);
				il += len;
			    }
			} else {
			    /* substitute for $<n> here */
			    if (il + 1 > gp_input_line_len) {
				extend_input_line();
			    }
			    gp_input_line[il++] = *rl;
			}
			rl++;
		    }
		    if (il + 1 > gp_input_line_len) {
			extend_input_line();
		    }
		    gp_input_line[il] = '\0';
		    free(raw_line);
		}
		screen_ok = FALSE;	/* make sure command line is
					   echoed on error */
		if (do_line())
		    stop = TRUE;
	    }
	}
    }

    /* pop state */
    (void) lf_pop();		/* also closes file fp */
}
示例#11
0
文件: see.cpp 项目: dshawul/Scorpio
int SEARCHER::see(MOVE move) {
    
    int list[32],n;
    int from = m_from(move),to = m_to(move),sq,score;
    int w_atkers[16],b_atkers[16];
    int w_atks = 0,b_atks = 0;
    int w_count , b_count;
    int col,atkd_val;
    int i,bi,bv,v,step,temp;

    PLIST current;

    /*initial value*/
    col = PCOLOR(m_piece(move));
    score = piece_see_v[m_capture(move)];
    atkd_val = piece_see_v[m_piece(move)];
    
    /*king captures*/
    if(atkd_val > 1000)
        return score;

    /*collect pawn attackers*/
    temp = score - atkd_val + piece_see_v[pawn];

    if (board[to + RD] == wpawn && from != (to + RD)) {
        QUICK_CUT(black);
        w_atkers[w_atks++] = to + RD;
    }
    if (board[to + LD] == wpawn && from != (to + LD)) {
        QUICK_CUT(black);
        w_atkers[w_atks++] = to + LD;
    }
    if (board[to + RU] == bpawn && from != (to + RU)) {
        QUICK_CUT(white);
        b_atkers[b_atks++] = to + RU;
    }
    if (board[to + LU] == bpawn && from != (to + LU)) {
        QUICK_CUT(white);
        b_atkers[b_atks++] = to + LU;
    }

    /*knight attackers*/
    temp = score - atkd_val + piece_see_v[knight];

    current = plist[wknight];
    while (current) {
        sq = current->sq;
        if (sqatt_pieces(to - sq) & NM) {
            if(sq != from) {
                QUICK_CUT(black);
                w_atkers[w_atks++] = sq;
            }
        }
        current = current->next;
    }

    current = plist[bknight];
    while (current) {
        sq = current->sq;
        if (sqatt_pieces(to - sq) & NM) {
            if(sq != from) {
                QUICK_CUT(white);
                b_atkers[b_atks++] = sq;
            }
        }
        current = current->next;
    }
    /*sliders*/
    temp = score - atkd_val + piece_see_v[bishop];
    AddSlider(to,RU,wbishop,bbishop,1);
    AddSlider(to,LU,wbishop,bbishop,1);
    AddSlider(to,RD,wbishop,bbishop,1);
    AddSlider(to,LD,wbishop,bbishop,1);
    temp = score - atkd_val + piece_see_v[rook];
    AddSlider(to,UU,wrook,brook,1);
    AddSlider(to,DD,wrook,brook,1);
    AddSlider(to,RR,wrook,brook,1);
    AddSlider(to,LL,wrook,brook,1);

    /*king attackers*/
    sq = plist[wking]->sq;
    if (sq != from && (sqatt_pieces(to - sq) & KM)) {
        w_atkers[w_atks++] = sq;
    }
    sq = plist[bking]->sq;
    if (sq != from && (sqatt_pieces(to - sq) & KM)) {
        b_atkers[b_atks++] = sq;
    }

    /*we start by capturing*/
    col = invert(col);
    if(col == opponent)
        AddHiddenAttacker(from);

    /*no attackers*/
    if((col == white && !w_atks)
       || (col == black && !b_atks))
       return score;

    /*swap*/
    list[0] = score;
    n = 1;
    w_count  = 0;
    b_count  = 0;
    
    while(true) {
        if((col == white && w_count == w_atks) || 
           (col == black && b_count == b_atks) )
            break;
        
        list[n] = -list[n-1] + atkd_val; 
        n++;
        
        if(col == white) {
            /*get smallest attacker to the front*/
            bi = w_count;
            bv = piece_see_v[board[w_atkers[bi]]];
            
            for(i = w_count + 1;i < w_atks;i++) {
                v = piece_see_v[board[w_atkers[i]]]; 
                if(v < bv) {
                    bi = i;
                    bv = v;
                }
            }
            if(bi != w_count) {
                temp = w_atkers[bi];
                w_atkers[bi] = w_atkers[w_count];
                w_atkers[w_count] = temp;
            }
            /*add hidden attacker*/
            sq = w_atkers[w_count];
            AddHiddenAttacker(sq);

            atkd_val = bv;
            col = black;
            w_count++;
        } else {
            /*get smallest attacker to the front*/
            bi = b_count;
            bv = piece_see_v[board[b_atkers[bi]]];
            
            for(i = b_count + 1;i < b_atks;i++) {
                v = piece_see_v[board[b_atkers[i]]]; 
                if(v < bv) {
                    bi = i;
                    bv = v;
                }
            }
            if(bi != b_count) {
                temp = b_atkers[bi];
                b_atkers[bi] = b_atkers[b_count];
                b_atkers[b_count] = temp;
            }
            /*add hidden attacker*/
            sq = b_atkers[b_count];
            AddHiddenAttacker(sq);

            atkd_val = bv;
            col = white;
            b_count++;
        }
    }

    while(--n)
        list[n-1] = MIN(-list[n], list[n-1]);

    score = list[0];

    return score;
}