object *eval (object *sexp, object *env) { if(sexp->type == CONS && strcmp(name(car(sexp)), "LAMBDA") == 0){ object* largs = car(cdr(sexp)); object* lsexp = car(cdr(cdr(sexp))); return lambda(largs,lsexp); }else if(sexp->type == CONS){ object *accum = cons(eval(car(sexp),env),NULL); sexp = cdr(sexp); while (sexp != NULL && sexp->type == CONS){ append(accum,eval(car(sexp),env)); sexp = cdr(sexp); } return eval_fn(accum,env); }else{ object *val = lookup(name(sexp),env); if(val == NULL) return sexp; else return val; } }
static double factor() { if (follows(MT_BRA)) { next_token(); MItem* it = expression(); if (it->n >= 0) serror("invalid use of list."); if (!follows(MT_KET)) serror("')' expected."); next_token(); return it->val; } else if (follows(MT_NUMBER)) { double val = token->value; next_token(); return val; } else if (follows(MT_IDENT)) { MSymbol* sym = peek_symbol(token->text); if (sym == NULL) serror("unknown identifier '%s'.", token->text); next_token(); if (follows(MT_BRA)) { if (sym->built_in == NULL) serror("unknown function '%s'.", sym->name); next_token(); return eval_fn(sym); } else { if (sym->built_in != NULL) serror("invalid use of function."); if (sym->data->n >= 0) serror("invalid use of list."); return sym->data->val; } } else { serror("syntax error: '%s'", token->text); return 0.0; } }
int value(int alpha, int beta, int depth, int max, int algo, int max_depth) { int v = -INF, i, move[2]; if (depth > min(max_depth, NUM_MOVES_REMAINING)){ return eval_fn(); } for (i = 0; i < MAX_NUMBER_OF_POINTS; i++) { if(!next_point(move, i, algo)) break; if(do_move(move) > 0) { if (max) { v = max(v, value(alpha, beta, depth + 1, 0, algo, max_depth)); if (v >= beta) { undo_move(move); return v; } alpha = max(alpha, v); } else { v = min(v, value(alpha, beta, depth + 1, 1, algo, max_depth)); if (v <= alpha) { undo_move(move); return v; } beta = min(beta, v); } undo_move(move); } } return v; }
object *eval(object *sexp, object *env) { if (sexp == NULL) { // Return the empty list for NULL. return nil; } // List if (sexp->type == CONS) { // ATOM and LAMBDA don't need evaluated, just parameter extraction. if (first(sexp)->type == ATOM && strcmp(name(first(sexp)), "LAMBDA") == 0) { object* largs =first(second(sexp)); object* lsexp = first(second(second(sexp))); return lambda(largs, lsexp); } else { // Otherwise just evaluate it. object *accum = cons(eval(first(sexp), env), NULL); sexp = second(sexp); // Evaluate every cell in the inner-list while (sexp != NULL && sexp->type == CONS) { append(accum, eval(first(sexp), env)); sexp = second(sexp); } return eval_fn(accum, env); } } else { // Transform the value into an environment value object *val = lookup(name(sexp), env); if (val == NULL) return sexp; else return val; } }
SeriesC<RVHP> worker_cut_part::eval(const eval_param<RVHP>& ep){ return eval_fn(ep); }
int value(int alpha, int beta, int depth, int max, int phase) { int v = -inf, i, next = 0, j, *pw; int t[2], wleft = 0, tmp, p1wn = 0; for (i = 0; i < 12; i++) { wleft += p1w[i] + p2w[i]; } if (!wleft) { phase += 1; p1w[0] = 2; } player = -1 * player; if (depth > d){ return eval_fn(0, phase); } if (phase == 1) { if (player > 0) pw = p1w; else pw = p2w; for (j = 0; j < 12; j++) { if (pw[j]) pw[j] = 0; else continue; for (i = 0; i < 31; i++) { if (board[i]) continue; board[i] = player * (j + 1); torques(t); if(!tipped(t)) { next = 1; if (max) { v = max(v, value(alpha, beta, depth + 1, 0, phase)); if (v >= beta) { player = -1 * player; board[i] = 0; return v; } alpha = max(alpha, v); } else { v = min(v, value(alpha, beta, depth + 1, 1, phase)); if (v <= alpha) { player = -1 * player; board[i] = 0; return v; } beta = min(beta, v); } } board[i] = 0; } pw[j] = 1; } } if (phase == 2) { for (i = 0; i < 31; i++) { if (board[i] > 0) p1wn += 1; } for (i = 0; i < 31; i++) { if (p1wn > 0 && board[i] < 0) continue; if (!board[i]) continue; tmp = board[i]; board[i] = 0; torques(t); if(!tipped(t)) { next = 1; if (max) { v = max(v, value(alpha, beta, depth + 1, 0, phase)); if (v >= beta) { player = -1 * player; board[i] = tmp; return v; } alpha = max(alpha, v); } else { v = min(v, value(alpha, beta, depth + 1, 1, phase)); if (v <= alpha) { player = -1 * player; board[i] = tmp; return v; } beta = min(beta, v); } } board[i] = tmp; } } if (!next) return eval_fn(1, phase); player = -1 * player; return v; }