예제 #1
0
파일: cc.c 프로젝트: Fedjmike/mini-c
void unary () {
    if (try_match("!")) {
        //Recurse to allow chains of unary operations, LIFO order
        unary();

        fputs("cmp eax, 0\n"
              "mov eax, 0\n"
              "sete al\n", output);

    } else if (try_match("-")) {
        unary();
        fputs("neg eax\n", output);

    } else {
        //This function call compiles itself
        object();

        if (see("++") || see("--")) {
            fprintf(output, "mov ebx, eax\n"
                            "mov eax, [ebx]\n"
                            "%s dword ptr [ebx], 1\n", see("++") ? "add" : "sub");

            needs_lvalue("assignment operator '%s' requires a modifiable object\n");
            next();
        }
    }
}
예제 #2
0
파일: code16.cpp 프로젝트: Mr-Phoebe/BOJ-V2
inline int _query(int p) {
	query_info.similar_score=0;
	query_info.similar_score+=test_1(query_info)*0.5;
	see(query_info.similar_score);
	query_info.similar_score+=test_2(query_info)*0.5;
	see(query_info.similar_score);
}
예제 #3
0
파일: parser.c 프로젝트: dario23/tush
static bool waiting_for_delim (parserCtx* ctx) {
    bool seeLowPrecOp =    see_kind(ctx, tokenOp)
                        && !see(ctx, "(")
                        && !see(ctx, "[")
                        && !see(ctx, "!");

    return waiting(ctx) && !seeLowPrecOp;
}
예제 #4
0
파일: cc.c 프로젝트: Fedjmike/mini-c
void object () {
    factor();

    while (true) {
        if (try_match("(")) {
            fputs("push eax\n", output);

            int arg_no = 0;

            if (waiting_for(")")) {
                //cdecl requires arguments to be pushed on backwards
                
                int start_label = new_label();
                int end_label = new_label();
                int prev_label = end_label;

                fprintf(output, "jmp _%08d\n", start_label);

                do {
                    int next_label = emit_label(new_label());
                    expr(0);
                    fprintf(output, "push eax\n"
                                    "jmp _%08d\n", prev_label);
                    arg_no++;

                    prev_label = next_label;
                } while (try_match(","));

                fprintf(output, "_%08d:\n", start_label);
                fprintf(output, "jmp _%08d\n", prev_label);
                fprintf(output, "_%08d:\n", end_label);
            }

            match(")");

            fprintf(output, "call dword ptr [esp+%d]\n", arg_no*word_size);
            fprintf(output, "add esp, %d\n", (arg_no+1)*word_size);

        } else if (try_match("[")) {
            fputs("push eax\n", output);

            expr(0);
            match("]");

            if (see("=") || see("++") || see("--"))
                lvalue = true;

            fprintf(output, "pop ebx\n"
                            "%s eax, [eax*%d+ebx]\n", lvalue ? "lea" : "mov", word_size);

        } else
            return;
    }
}
예제 #5
0
파일: parser.c 프로젝트: dario23/tush
/**
 * Statement = Let | Expr
 */
static ast* parseStatement (parserCtx* ctx) {
    if (see(ctx, "let"))
        return parseLet(ctx);

    else
        return parseExpr(ctx);
}
예제 #6
0
void sort_qsearch_moves(int *scores) {
    Move_t *moves = global_move_list();
    Move_t temp;
    int nMoves = global_move_count();
    int i, fail;
    
    for (i = 0; i < nMoves; i++)
        scores[i] = see(moves[i], global_board());
    
    do {
        fail = 0;
        for (i = 0; i < nMoves - 1; i++) {
            if (scores[i] < scores[i+1]) {
                temp = moves[i];
                moves[i] = moves[i+1];
                moves[i+1] = temp;
                temp = scores[i];
                scores[i] = scores[i+1];
                scores[i+1] = temp;
                fail = 1;
            }
        }
        
        
    } while (fail);
}
예제 #7
0
int simpleQSearch(int alpha, int beta, State &state) {
  bool inCheck = state.isInCheck(state._sideToMove);

  std::vector<int> moves = generatePseudoMoves(state, inCheck);
  int legal = 0;

  int stand_pat = state._material * (state._sideToMove == WHITE ? 1 : -1);
  if (stand_pat >= beta) {
    alpha = beta;
  } else {

    if (alpha < stand_pat) {
      alpha = stand_pat;
    }
    for (Move move : moves) {

      // stop search if found a checkmate
      if (alpha >= CHECKMATE) {
        break;
      }

      if (!inCheck &&
          ((state._pieces[M_TOSQ(move)] == EMPTY && !M_ISPROMOTION(move)) ||
           see(move, state) < 0)) {
        continue;
      }

      state.makeMove(move);

      if (!state.isPositionLegal()) {
        state.takeMove();
        continue;
      }
      legal++;
      state._ply++;
      int score = -simpleQSearch(-beta, -alpha, state);
      state._ply--;

      state.takeMove();

      if (score >= beta) {
        alpha = beta;
        break;
      }
      if (score > alpha) {
        alpha = score;
      }
    }
  }
  if (alpha == beta) { // check game over for beta cutoff
    if (isGameOver(state, moves)) {
      alpha = evaluateGameOver(state, -1);
    }
  } else {
    if (!legal && (inCheck || isGameOver(state, moves))) {
      alpha = evaluateGameOver(state, -1);
    }
  }
  return alpha;
}
예제 #8
0
파일: Board.cpp 프로젝트: dimock/chess
bool Board::isDangerPawn(Move & move) const
{
  const Field & ffrom = getField(move.from_);
  if ( ffrom.type() != Figure::TypePawn )
    return false;

  if ( move.capture_ || move.new_type_ > 0 )
    return true;

  Figure::Color  color = color_;
  Figure::Color ocolor = Figure::otherColor(color);

  // attacking
  const uint64 & p_caps = g_movesTable->pawnCaps_o(ffrom.color(), move.to_);
  const uint64 & o_mask = fmgr_.mask(ocolor);
  if ( p_caps & o_mask )
    return true;

  //// becomes passed
  const uint64 & pmsk = fmgr_.pawn_mask_t(color);
  const uint64 & opmsk = fmgr_.pawn_mask_t(ocolor);
  const uint64 & passmsk = g_pawnMasks->mask_passed(color, move.to_);
  const uint64 & blckmsk = g_pawnMasks->mask_blocked(color, move.to_);

  if ( !(opmsk & passmsk) && !(pmsk & blckmsk) )
		return true;

  if ( !move.seen_ && see(move) >= 0 )
		move.see_good_ = 1;

	move.seen_ = 1;

  return move.see_good_;
}
예제 #9
0
void sort_global_moves(Move_t tt_move, int tt_score, int depth) {
    
    Board_t *board = global_board();
    Move_t *moves = global_move_list();
    Move_t temp;
    int nMoves = global_move_count();
    int n_killers;
    
    Move_t *killers = get_killers(&n_killers, depth);
    
    if (nMoves <= 1)
        return;
    
    int *scores = sort_data.scores[depth];
    int *flags = sort_data.flags[depth];
    
    int i, j, fail;
    for (i = 0; i < nMoves; i++) {
        scores[i] = see(moves[i], board);
        flags[i] = NO_ORDER_FLAG;
        
        if (moves[i] == tt_move) {
            scores[i] = tt_score;
            flags[i] = TT_MOVE;
        } else {
            for (j = 0; j < n_killers; j++) {
                if (moves[i] == killers[j])
                    flags[i] = KILLER_MOVE;
            }
            
        }
        
        if (flags[i] == NO_ORDER_FLAG &&
            (temp = get_history_score(moves[i], TURN(board))) != -VALUE_INFINITE) {
            flags[i] = HISTORY_MOVE;
            scores[i] = temp;
        }
    }
    
    do {
        fail = 0;
        for (i = 0; i < nMoves - 1; i++) {
            if ((flags[i] < flags[i+1]) || (flags[i] == flags[i+1] && scores[i] < scores[i+1])) {
                temp = moves[i];
                moves[i] = moves[i+1];
                moves[i+1] = temp;
                temp = scores[i];
                scores[i] = scores[i+1];
                scores[i+1] = temp;
                temp = flags[i];
                flags[i] = flags[i+1];
                flags[i+1] = temp;
                fail = 1;
            }
        }
        
        
    } while (fail);
    
}
예제 #10
0
void choose(Stack *park_stack, Stack *temp_stack, Link_queue *wait_queue)
{
    char rec[10];
    
    printf("\t\033[40;36m请输入你的选择: \033[0m");
    scanf("%s",rec);

    if(my_strcmp(rec,"1") == 0)                       //比较输入
    {
        system("reset");
	park(park_stack,temp_stack,wait_queue);      //调用函数
    }
    else if(my_strcmp(rec,"2") == 0)
    {
        system("reset");
	out(park_stack,temp_stack,wait_queue);
    }
    else if(my_strcmp(rec,"3") == 0)
    {
        system("reset");
	see(park_stack,temp_stack,wait_queue);
    }
    else if(my_strcmp(rec,"4") == 0)
    {
        system("reset");
	printf("\n\033[40;36m感谢你使用新智停车管理系统,祝你旅途愉快!~^.^~\033[0m\n\n");
	exit(0);
    }
    else
    {
        printf("\t\033[40;36m选择错误,请正确选择你要使用的功能。\033[0m\n\n");
	choose(park_stack,temp_stack,wait_queue);
    }
}
예제 #11
0
void caps_ordering(move_t ms[], int count)
{
  int i;
  for (i = 0; i < count; i++)
  { if(ms[i].type & PROM)
    { ms[i].score = 500000 + pval[ms[i].promoted];
      if(ms[i].type & CAP) 
        ms[i].score += pval[PieceType(ms[i].to)];
    }
    else if(ms[i].type & CAP)
    { if(ms[i].type & EP)
        ms[i].score = 30000 - P_VALUE;
      else
      { int p_from = pval[PieceType(ms[i].from)];
        int p_to = pval[PieceType(ms[i].to)];
        //bishop/knight correction
        if(abs(p_to - p_from) == B_N_DIFF) 
          ms[i].score = 30000 - p_from;
        else if(p_to > p_from)//good caps
          ms[i].score = 40000 + (p_to - p_from);
        else if(p_to == p_from) //equal caps
          ms[i].score = 30000 - p_from;
        else if(p_to < p_from) //presumably bad caps
        { ms[i].score = see(ms[i]);
          if(ms[i].score == 0) ms[i].score = 30000 - p_from;//it's equal.
          else if(ms[i].score > 0) ms[i].score += 40000; //appears to be a good sequence.
        }
      }
    }
  }
}
예제 #12
0
void menu()
{
    int choice;
    printf("\n\n\t\t\tCUSTOMER ACCOUNT BANKING MANAGEMENT SYSTEM");
    printf("\n\n\n\t\t\t WELCOME TO THE MAIN MENU ");
    printf("\n\n\t\t1.Create new account\n\t\t2.Update information of existing account\n\t\t3.For transactions\n\t\t4.Check the details of existing account\n\t\t5.Removing existing account\n\t\t6.View customer's list\n\t\t7.Exit\n\n\n\n\n\t\t Enter your choice:");
    scanf("%d",&choice);

    
    switch(choice)
    {
        case 1:add_acc();
        break;
        case 2:mod_acc();
        break;
        case 3:transaction_acc();
        break;
        case 4:see();
        break;
        case 5:delete_acc();
        break;
        case 6:view_list();
        break;
        case 7:close();
        break;
	
    }
}
예제 #13
0
파일: cc.c 프로젝트: Fedjmike/mini-c
bool try_match (char* look) {
    bool saw = see(look);

    if (saw)
        next();

    return saw;
}
예제 #14
0
파일: cc.c 프로젝트: Fedjmike/mini-c
void match (char* look) {
    if (!see(look)) {
        printf("%s:%d: error: expected '%s', found '%s'\n", inputname, curln, look, buffer);
        errors++;
    }

    next();
}
예제 #15
0
/* Alpha-Beta quiescence search with Nega Max and null-window */
short SEARCH_nullwindow_quiescence(const chess_state_t *state, search_state_t *search_state, short beta)
{
    int num_moves;
    int i;
    short score;
    short best_score;
    chess_state_t next_state;
    move_t moves[256];

    int is_check = SEARCH_is_check(state, state->player);

    if(is_check) best_score = SEARCH_MIN_RESULT(0);
    else {
        /* Stand-pat */
        best_score = EVAL_evaluate_board(state);
        search_state->num_nodes_searched++;
        if(best_score >= beta) {
            return best_score;
        }
    }

    /* Generate and rate moves (captures and promotions only) */
    if(is_check) {
        num_moves = STATE_generate_moves(state, moves);
    } else {
        num_moves = STATE_generate_moves_quiescence(state, moves);
    }
    MOVEORDER_rate_moves_quiescence(state, moves, num_moves);

    for(i = 0; i < num_moves; i++) {
        /* Pick move with the highest score */
        MOVEORDER_best_move_first(&moves[i], num_moves - i);

        /* Prune all captures with SEE < 0 */
        if(!MOVE_IS_PROMOTION(moves[i]) && !is_check) {
            if(SSE_capture_less_valuable(moves[i]) && see(state, moves[i]) < 0) {
                continue;
            }
        }

        next_state = *state;
        STATE_apply_move(&next_state, moves[i]);
        if(SEARCH_is_check(&next_state, state->player)) {
            continue;
        }

        score = -SEARCH_nullwindow_quiescence(&next_state, search_state, -beta+1);
        if(score > best_score) {
            best_score = score;
            if(best_score >= beta) {
                /* Beta-cuttoff */
                break;
            }
        }
    }

    return best_score;
}
예제 #16
0
BOOL no_good_captures(struct t_board *board, struct t_move_list *move_list){

	for (int i = 0; i < move_list->count; i++)
	{
		struct t_move_record *move = move_list->move[i];
		if (move->captured && see(board, move, 0))
			return FALSE;
	}
	return TRUE;
}
예제 #17
0
파일: display.c 프로젝트: quixadhal/conquer
/*make a map*/
void
makemap()
{
	register int x,y;

	for(x=0;x<SCREEN_X_SIZE;x++) for(y=0;y<SCREEN_Y_SIZE;y++)
	if( HAS_SEEN(x,y) ) {
		highlight(x,y,hilmode);
		see(x,y);
	}
	move(ycurs,2*xcurs);
}
예제 #18
0
파일: cc.c 프로젝트: Fedjmike/mini-c
void line () {
    if (see("if"))
        if_branch();

    else if (see("while") || see("do"))
        while_loop();

    else if (see("int") || see("char") || see("bool"))
        decl(decl_local);

    else if (try_match("{")) {
        while (waiting_for("}"))
            line();

        match("}");

    } else {
        bool ret = try_match("return");

        if (waiting_for(";"))
            expr(0);

        if (ret)
            fprintf(output, "jmp _%08d\n", return_to);

        match(";");
    }
}
예제 #19
0
static int dump_file(struct tree_state *t, char *name, char *file)
{
	struct file_state f;
	int fd;
	Elf_Scn *scn;
	GElf_Shdr shdr;

	if ((dup_mode == HIDE_DUPS) && seen(t, name))
		return 0;

	indent(t); printf("%s", name);

	if ((dup_mode == PRUNE_DUPS) && seen(t, name)) {
		printf("...\n");
		return 0;
	} else {
		printf(":\n");
	}

	see(t, name);

	f.t = t;

	fd = open(file, O_RDONLY);
	if (fd < 0) {
		unix_err("open(%s) failed", file);
		return -1;
	}

	f.e = elf_begin(fd, ELF_C_READ, NULL);
	if (!f.e) {
		elf_err("elf_begin failed on %s", file);
		return -1;
	}

	scn = find_scn(&f, SHT_STRTAB, NULL, &shdr);
	f.strtab_data = elf_getdata(scn, NULL);
	if (!f.strtab_data) {
		app_err("%s has no strtab section", file);
		return -1;
	}

	scn = NULL;
	while ((scn = find_scn(&f, SHT_DYNAMIC, scn, &shdr))) {
		dump_dynamic(&f, scn, &shdr);
	}

	elf_end(f.e);
	close(fd);

	return 0;
}
예제 #20
0
파일: see1234.c 프로젝트: mmammel/projects
main(){
int i,j,k,l;
for( i=0 ; i<24 ; i++ ){
for( j=0 ; j<24 ; j++ ){
if( row[i][0] == row[j][0] ) continue;
if( row[i][1] == row[j][1] ) continue;
if( row[i][2] == row[j][2] ) continue;
if( row[i][3] == row[j][3] ) continue;
for( k=0 ; k<24 ; k++ ){
if( row[i][0] == row[k][0] ) continue;
if( row[i][1] == row[k][1] ) continue;
if( row[i][2] == row[k][2] ) continue;
if( row[i][3] == row[k][3] ) continue;
if( row[j][0] == row[k][0] ) continue;
if( row[j][1] == row[k][1] ) continue;
if( row[j][2] == row[k][2] ) continue;
if( row[j][3] == row[k][3] ) continue;
for( l=0 ; l<24 ; l++){
if( row[i][0] == row[l][0] ) continue;
if( row[i][1] == row[l][1] ) continue;
if( row[i][2] == row[l][2] ) continue;
if( row[i][3] == row[l][3] ) continue;
if( row[j][0] == row[l][0] ) continue;
if( row[j][1] == row[l][1] ) continue;
if( row[j][2] == row[l][2] ) continue;
if( row[j][3] == row[l][3] ) continue;
if( row[k][0] == row[l][0] ) continue;
if( row[k][1] == row[l][1] ) continue;
if( row[k][2] == row[l][2] ) continue;
if( row[k][3] == row[l][3] ) continue;

rowSees[0] =  see(row[i][0],row[j][0],row[k][0],row[l][0] ); 
rowSees[1] =  see(row[i][1],row[j][1],row[k][1],row[l][1] );
rowSees[2] =  see(row[i][2],row[j][2],row[k][2],row[l][2] );
rowSees[3] =  see(row[i][3],row[j][3],row[k][3],row[l][3] );

colSees[0] = see(row[i][3],row[i][2],row[i][1],row[i][0] );
colSees[1] = see(row[j][3],row[j][2],row[j][1],row[j][0] );
colSees[2] = see(row[k][3],row[k][2],row[k][1],row[k][0] );
colSees[3] = see(row[l][3],row[l][2],row[l][1],row[l][0] );

printf("%d %d %d %d\n--------\n",rowSees[0],rowSees[1],rowSees[2],rowSees[3]);
printf("%d %d %d %d | %d\n",row[i][0],row[i][1],row[i][2],row[i][3],colSees[0]);
printf("%d %d %d %d | %d\n",row[j][0],row[j][1],row[j][2],row[j][3],colSees[1]);
printf("%d %d %d %d | %d\n",row[k][0],row[k][1],row[k][2],row[k][3],colSees[2]);
printf("%d %d %d %d | %d\n",row[l][0],row[l][1],row[l][2],row[l][3],colSees[3]);
printf("Total: %d\n\n", rowSees[0]+rowSees[1]+rowSees[2]+rowSees[3]+colSees[0]+colSees[1]+colSees[2]+colSees[3]);
}}}}
}
예제 #21
0
int main()
{
	int ch,a[100], p, n, i, pos;
	
	printf("\nEnter the number of elements  ");
	scanf("%d",&n);
	numm=n;
	
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
		
	buildMinHeap(a, numm);	
	
	printf("\n1.See\n2.extract\n3.insert\n4.update\n5.exit  ");

	while(1)
	{
		printf("\nEnter ur choice  ");
		scanf("%d",&ch);
		
		switch(ch)
		{
			case 1:
				see(a, numm);
				break;
			case 2:
				printf("\nthe min element was %d \n",extractMin(a));
				break;
			case 3:
				printf("\nEnter node to insert  ");
				scanf("%d",&i);
				insert(a,i);
				break;
			case 4:
				printf("\nEnter the index to update ");
				scanf("%d",&p);
				printf("nEnter the node key value ");
				scanf("%d",&i);
				update(a, p, i);
				break;
			case 5:
				return (0);
		}
	}
	return 0;
}
예제 #22
0
파일: parser.c 프로젝트: dario23/tush
/**
 * FnApp = { Atom | ( "`" Atom "`" ) }
 *
 * A series of at least one expr-atom. If multiple, then the last is a
 * function to which the others are applied. Instead, one of them may
 * be explicitly marked in backticks as the function.
 */
static ast* parseFnApp (parserCtx* ctx) {
    /*Filled iff there is a backtick function*/
    ast* fn = 0;

    vector(ast*) nodes = vectorInit(3, malloc);

    /*Require at least one expr*/
    if (!see(ctx, "!"))
        vectorPush(&nodes, parseAtom(ctx));

    while (waiting_for_delim(ctx)) {
        if (try_match(ctx, "!")) {
            if (fn) {
                error(ctx)("Multiple explicit functions: '%s'\n", ctx->current.buffer);
                vectorPush(&nodes, fn);
            }

            fn = parseAtom(ctx);

        } else
            vectorPush(&nodes, parseAtom(ctx));
    }

    if (fn)
        return astCreateFnApp(nodes, fn);

    else if (nodes.length == 0) {
        /*Shouldn't happen due to the way it parses*/
        errprintf("FnApp took no AST nodes");
        return astCreateInvalid();

    } else if (nodes.length == 1) {
        /*No application*/
        ast* node = vectorPop(&nodes);
        vectorFree(&nodes);
        return node;

    } else {
    	/*The last node is the fn*/
        fn = vectorPop(&nodes);
        return astCreateFnApp(nodes, fn);
    }
}
예제 #23
0
파일: cc.c 프로젝트: Fedjmike/mini-c
void factor () {
    lvalue = false;

    if (see("true") || see("false")) {
        fprintf(output, "mov eax, %d\n", see("true") ? 1 : 0);
        next();

    } else if (token == token_ident) {
        int global = sym_lookup(globals, global_no, buffer);
        int local = sym_lookup(locals, local_no, buffer);

        require(global >= 0 || local >= 0, "no symbol '%s' declared\n");
        next();

        if (see("=") || see("++") || see("--"))
            lvalue = true;

        if (global >= 0)
            fprintf(output, "%s eax, [%s]\n", is_fn[global] || lvalue ? "lea" : "mov", globals[global]);

        else if (local >= 0)
            fprintf(output, "%s eax, [ebp%+d]\n", lvalue ? "lea" : "mov", offsets[local]);

    } else if (token == token_int || token == token_char) {
        fprintf(output, "mov eax, %s\n", buffer);
        next();

    } else if (token == token_str) {
        fputs(".section .rodata\n", output);
        int str = emit_label(new_label());

        //Consecutive string literals are concatenated
        while (token == token_str) {
            fprintf(output, ".ascii %s\n", buffer);
            next();
        }

        fputs(".byte 0\n"
              ".section .text\n", output);

        fprintf(output, "mov eax, offset _%08d\n", str);

    } else if (try_match("(")) {
        expr(0);
        match(")");

    } else
        error("expected an expression, found '%s'\n");
}
예제 #24
0
main()
{
	int i,j,n,ch=0,st;

	printf("Enter the no of nodes");
	scanf("%d",&n);
	//printf("\nEnter the relation of nodes  ");
	
	for(i=0;i<n;i++)
	{
		while(ch!=-1)
		{
			printf("\nEnter the adjacent nodes of %d  ",i+1);
			scanf("%d",&ch);
			a[i][ch-1]=1;
		
		}
		
		ch=0;
		
	}
	
	printf("\n\nThe relation matrix is \n");
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			printf(" %d ",a[i][j]);
		}
		printf("\n");
	}
	
	printf("Enter the starting node ");
	scanf("%d",&st);
	
	BFS(st,n);
	
	see(n);
	

}
예제 #25
0
void ordering(move_t ms[], int count, uint32 bestmove)
{
  int i,ply = board->ply;
  
  for (i = 0; i < count; i++)
  { if(ms[i].p  == bestmove) 
      ms[i].score = 1000000;
    else if(ms[i].type & PROM)
    { ms[i].score = 500000 + pval[ms[i].promoted];
      if(ms[i].type & CAP) 
        ms[i].score += pval[PieceType(ms[i].to)];
    }
    else if(ms[i].type & CAP)
    { if(ms[i].type & EP)
        ms[i].score = 30000 - P_VALUE;
      else
      { int p_from = pval[PieceType(ms[i].from)];
        int p_to = pval[PieceType(ms[i].to)];
        //bishop/knight correction
        if(abs(p_to - p_from) == B_N_DIFF) 
          ms[i].score = 30000 - p_from;
        else if(p_to > p_from)//good caps
          ms[i].score = 40000 + (p_to - p_from);
        else if(p_to == p_from) //equal caps
          ms[i].score = 30000 - p_from;
        else if(p_to < p_from) //presumably bad caps
        { ms[i].score = see(ms[i]);
          if(ms[i].score == 0) ms[i].score = 30000 - p_from;//it's equal.
          else if(ms[i].score > 0) ms[i].score += 40000; //appears to be a good sequence.
        }
      }
    }
    else if(ms[i].p == si->killer[0][ply])
      ms[i].score = 20000;
    else if(ms[i].p == si->killer[1][ply])
      ms[i].score = 10000;
    else if(ms[i].type & CASTLE) 
      ms[i].score = 5000 - (ms[i].type ^ CASTLE);
    else ms[i].score += si->history[ms[i].from][ms[i].to];
  }
}
예제 #26
0
void Shell::select(const std::string& exec, size_t argc, const std::string* argv)
{
	if(exec == "open")
		open(argc, argv);
	else if(exec == "seek")
		seek(argc, argv);
	else if(exec == "tell")
		tell(argc, argv);
	else if(exec == "write")
		write(argc, argv);
	else if(exec == "read")
		read(argc, argv);
	else if(exec == "close")
		close(argc, argv);
	else if(exec == "useradd")
		useradd(argc, argv);
	else if(exec == "chpsd")
		chpsd(argc, argv);
	else if(exec == "cd")
		cd(argc, argv);
	else if(exec == "mkdir")
		mkdir(argc, argv);
	else if(exec == "mkfile")
		mkfile(argc, argv);
	else if(exec == "rm")
		rm(argc, argv);
	else if(exec == "cat")
		cat(argc, argv);
	else if(exec == "ls")
		ls(argc, argv);
	else if(exec == "chmod")
		chmod(argc, argv);
	else if(exec == "see")
		see(argc, argv);
	else if(exec == "ocp")
		ocp(argc, argv);
	else
		runshell(exec, argc, argv);
}
예제 #27
0
파일: parser.c 프로젝트: dario23/tush
/**
 * FnLit = "\" [{ Pattern }] "->" Expr
 */
static ast* parseFnLit (parserCtx* ctx) {
    match(ctx, "\\");

    /*Enter a new scope*/
    sym* oldscope = push_scope(ctx, symAddScope(ctx->scope));

    /*Arg patterns*/

    vector(ast*) args = vectorInit(2, malloc);

    while (!see(ctx, "->"))
        vectorPush(&args, parserPattern(ctx));

    /*Body*/

    match(ctx, "->");
    ast* expr = parseExpr(ctx);

    /*Pop scope*/
    ctx->scope = oldscope;

    return astCreateFnLit(args, expr);
}
예제 #28
0
int seeSign( const Board &board, Move move, int threshold ) {
   ASSERT(!IsNull(move));
#ifdef ATTACK_TRACE
   cout << "see ";
   MoveImage(move,cout);
   cout << endl;
#endif
   ColorType my_side = PieceColor(board[StartSquare(move)]);
   ColorType side = my_side;
   ColorType oside = OppositeColor(side);
   Square square = DestSquare(move);
   Square attack_square = StartSquare(move);
   Piece attacker = board[attack_square];
   Piece on_square = (TypeOfMove(move) == EnPassant) ? 
       MakePiece(Pawn,oside) : board[square];
   Bitboard opp_attacks(board.calcAttacks(square,oside));
   if (opp_attacks.isClear()) {
       // piece is undefended
#ifdef ATTACK_TRACE
       cout << "undefended, returning " << (Gain(move) >= threshold) << endl;
#endif
       return Gain(move) >= threshold;
   }
   int score_list[20];
   int swap_score = 0;
   int gain;
   Bitboard attacks[2]; 
   Square last_attack_sq[2] = {InvalidSquare, InvalidSquare};
   attacks[side] = board.calcAttacks(square,side);
   attacks[oside] = opp_attacks;
   int count = 0;

   for (;;) {
      last_attack_sq[side] = attack_square; 
      attacker = board[attack_square];
#ifdef ATTACK_TRACE
      cout << " " << PieceImage(TypeOfPiece(attacker))
           << " on " <<
           FileImage(attack_square) <<
           RankImage(attack_square) <<
           " takes " << PieceImage(TypeOfPiece(on_square))
           << endl;
#endif
      gain = PieceValue(on_square);
      if (TypeOfPiece(attacker) == Pawn && Rank(square,side) == 8) {
          if (count == 0) {
             // initial capture is a promotion (could be under-promotion)
             gain += (PieceValues[PromoteTo(move)] - PAWN_VALUE);
             on_square = MakePiece(PromoteTo(move),side);
          }
          else {
             // assume Queen promotion
             gain += QUEEN_VALUE-PAWN_VALUE;
             on_square = MakePiece(Queen,side);
          }
      }
      else {
          on_square = attacker;
      }
      if (side == my_side)
          swap_score += gain;
      else
          swap_score -= gain;

      ASSERT(count < 20);
      score_list[count++] = swap_score;
      // remove piece we used from attacks
      attacks[side].clear(attack_square);
      // switch sides
      side = OppositeColor(side);
      if (count % 2 == 0) {
          // If it is our turn to move and we are above the threshold
          // then we can exit - if we capture it only improves the score.
          if (swap_score >= threshold) {
              ASSERT(see(board,move) >= threshold);
              return 1;
          }
          // Futility: If capturing the opponent piece for free does
          // not bring us up to the threshold, exit. (Do not cut off
          // if we have a potential promotion).
          if ((Rank(square,side) != 8 ||
               !(attacks[side] & board.pawn_bits[side])) &&
              swap_score + PieceValue(on_square) < threshold) {
              ASSERT(see(board,move) < threshold);
              return 0;
          }
      } else {
          // See if opponent already has captured enough that SEE is
          // below threshold
          if (swap_score < threshold) {
              ASSERT(see(board,move) < threshold);
              return 0;
          }
          // Futility: opponent capture cannot get us below threshold
          if ((Rank(square,side) != 8 ||
               !(attacks[side] & board.pawn_bits[side])) &&
              swap_score - PieceValue(on_square) >= threshold) {
              ASSERT(see(board,move) >= threshold);
              return 1;
          }
      }
      const Square atk = last_attack_sq[side];
      if (atk != InvalidSquare &&
          TypeOfPiece(board[atk]) != Knight) {
          // add in x-ray attacks if any
          Square xray = board.getDirectionalAttack(atk,
                                                   -Attacks::directions[atk][square],
                                                   side);
          if (xray != InvalidSquare) {
             attacks[side].set(xray);
          }
      }
      if (attacks[side]) {
          // get next opponent attacker
          attack_square = minAttacker(board,attacks[side],side);
      } else {
          // no more attackers (including x-rays)
          break;
      }
   }
   ASSERT(count >= 1);
   // minimax over the score list 
   for (int i = count-1; i > 0; --i) {
       if (i % 2 == 0) {
           score_list[i-1] = max(score_list[i],score_list[i-1]);
       } else {
           score_list[i-1] = min(score_list[i],score_list[i-1]);
       }
   }
#ifdef ATTACK_TRACE
   cout << "returning " << (score_list[0]>=threshold) << endl;
#endif
   ASSERT((score_list[0] >= threshold) == (see(board,move) >= threshold));
   return score_list[0] >= threshold;
}
예제 #29
0
void main()
{
	setlocale(LC_ALL, "Russian");
	struct der *dr;
	dr = NULL;
	int flag = 0, sh, i;
	FILE *file;

	GG = (struct der **)calloc(M, sizeof(struct der *));

	while (1)
	{
		puts("Выбирите вид операции:");
		puts("	1 - Создать дерево");//
		puts("	2 - Загрузить дерево из файла");
		puts("	3 - Вывод содержимого дерева");//
		puts("	4 - Добавление элемента в дерево");//
		puts("	5 - Удаление элемента из дерева");//
		puts("	6 - Полное удалнение (очистка) дерева");//
		puts("	7 - Сорханить в файл");//
		puts("	8 - Удалить все до определенной даты");//
		puts("	9 - Выход");
		do
		{
			//fflush(stdin);
			__fpurge(stdin);
			if (!scanf("%d", &flag) || (flag < 1) || (flag > 9))
			{
				puts("Ошибка ввода. Введите заново");
			}
		} while (!flag || (flag < 1) || (flag > 9));

		switch (flag)
		{
		case 1: dr = sozd(dr); break;
		case 2: 
		{
			file = fopen("file.txt", "r");
			if (!file)
			{
				puts("Файл не найден");
				break;
			}
			fscanf(file, "%d", &GP);
			
			if (dr || GP == 0)
			{
				fclose(file);
				puts("Бинарное дерево уже создано");
				break;
			}
			dr = read(dr, file);
			sh = 1;
			while (sh != GP)
			{
				read_add(dr, file);
				sh++;
			}
			
			fclose(file);
			break;
		}
		case 3: see(dr); puts("Если пусто, то элементы дерева удалены, добавте."); break;
		case 4: add(dr); break;
		case 5: del(dr); break;
		case 6: f_free(dr); dr = NULL; break;
		case 7:
		{
			file = fopen("file.txt", "w");
			fprintf(file, "%d\r\n\r\n", GP);
			save(dr, file);
			fclose(file);
			break;
		}
		case 8: del_op(dr); break;
		case 9: f_free(dr); free(GG); return;
		}
	}
}
예제 #30
0
파일: parser.c 프로젝트: dario23/tush
/**
 * Atom =   ( "(" [ Expr [{ "," Expr }] ] ")" )
 *        | ( "[" [{ Expr }] "]" )
 *        | FnLit | Path | <Str> | <Symbol>
 */
static ast* parseAtom (parserCtx* ctx) {
    ast* node;

    if (try_match(ctx, "(")) {
        /*Empty brackets => unit literal*/
        if (see(ctx, ")"))
            node = astCreateUnitLit();

        else {
            node = parseExpr(ctx);

            /*Tuple literal*/
            if (see(ctx, ",")) {
                vector(ast*) nodes = vectorInit(3, malloc);
                vectorPush(&nodes, node);

                while (try_match(ctx, ","))
                    vectorPush(&nodes, parseExpr(ctx));

                node = astCreateTupleLit(nodes);
            }
        }

        match(ctx, ")");

    /*List literal*/
    } else if (try_match(ctx, "[")) {
        vector(ast*) nodes = vectorInit(4, malloc);

        if (waiting_for(ctx, "]")) do {
            vectorPush(&nodes, parseExpr(ctx));
        } while (try_match(ctx, ","));

        node = astCreateListLit(nodes);

        match(ctx, "]");

    } else if (see(ctx, "\\")) {
        node = parseFnLit(ctx);

    } else if (see(ctx, "true") || see(ctx, "false")) {
        node = astCreateBoolLit(see(ctx, "true"));
        accept(ctx);

    } else if (see_kind(ctx, tokenIntLit)) {
        node = astCreateIntLit(atoi(ctx->current.buffer));
        accept(ctx);

    } else if (see_kind(ctx, tokenStrLit)) {
        node = astCreateStrLit(ctx->current.buffer);
        accept(ctx);

    } else if (see_kind(ctx, tokenNormal)) {
        sym* symbol;

        if (isPathToken(ctx->current.buffer))
            node = parsePath(ctx);

        else if ((symbol = symLookup(ctx->scope, ctx->current.buffer)))
            node = astCreateSymbol(symbol);

        else
            node = astCreateFileLit(ctx->current.buffer);

        accept(ctx);

    } else {
        expected(ctx, "expression");
        node = astCreateInvalid();
    }

    return node;
}