/** * N-shape 1 * ## * ## */ Piece * n_shape1(int x, int y) { int blocks[4][2] = {{-1,0}, {0,0}, {0,1}, {1,1}}; return piece_create(x, y, blocks, "#2ea4ff"); };
double find_eps(polymatrix_t *game, strategy_profile_t *x, strategy_profile_t *xp, double deps, int *scount) { matrix_t *piece = piece_create(game, x, xp, scount); //fprintf(stderr,"%d %d\n", piece->nrows, piece->ncols); //print_piece(piece, stderr); //fprintf(stderr, "\n"); //print_piece(piece_p(piece), stderr); struct timespec start, end, t; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); double steps = 1.0 / line_search; double eps, val, meps, mval; meps = deps; //mval = piece_eval(piece, 0); //printf("V0 -> %lf\n", mval); mval = piece_eval(piece, meps); //printf("Vt -> %lf\n", mval); double res, me, e; //strategy_profile_t *np; for (eps = 0; eps < 1; eps+=steps) { //np = new_point(x, xp, eps); //e = compute_eps(game, np, NULL); val = piece_eval(piece, eps); //printf("%lf %lf %lf\n", eps, val, e); if (val < mval) { mval = val; meps = eps; } /* if (e < me) { me = e; res = eps; } */ } eps = 1; //np = new_point(x, xp, eps); val = piece_eval(piece, eps); if (val < mval) { mval = val; meps = eps; } //printf("%lf %lf %lf\n", eps, val, e); //exit(1); /* double me, res = 0; me = 1; //double eps; for (eps = 0; eps < 1; eps += 0.005) { strategy_profile_t *np = new_point(x, xp, eps); double e = compute_eps(game, np, NULL); if (e < me) { me = e; res = eps; } //fprintf(stderr, "%lf %lf\n", eps, e); } */ //printf("Vm -> %lf %lf\n", meps, mval); //printf("Vm2 -> %lf %lf\n", res, me); //return res; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); double elapsed = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) * 1e-9; piece_time += elapsed; matrix_free(piece); return meps; }
/** * L-shape 2 * # * ### */ Piece * l_shape2(int x, int y) { int blocks[4][2] = {{-1,0}, {0,0}, {1,0}, {1,-1}}; return piece_create(x, y, blocks, "#ff950c"); };
/** * L-shape 1 * ### * # */ Piece * l_shape1(int x, int y) { int blocks[4][2] = {{-1,0}, {0,0}, {1,0}, {1,1}}; return piece_create(x, y, blocks, "#2dd400"); };
/** * Square shape * ## * ## */ Piece * square(int x, int y) { int blocks[4][2] = {{0,0}, {1,0}, {1,1}, {0,1}}; return piece_create(x, y, blocks, "#BB0000"); };
/** * Line shape * # * # * # * # */ Piece * line(int x, int y) { int blocks[4][2] = {{0,-1}, {0,0}, {0,1}, {0,2}}; return piece_create(x, y, blocks, "blue"); };
/** * N-shape 2 * ## * ## */ Piece * n_shape2(int x, int y) { int blocks[4][2] = {{-1,0}, {0,0}, {0,-1}, {1,-1}}; return piece_create(x, y, blocks, "#4b0063"); };