void computemove(char *dirp, int *posp, int mark) { int pos, di, high, lvl, s, i, j, bdir = 0, bpos = 0; int dir; struct move *mp, *np, *tmp; mp = moves; for (di = 0; di < 4; di++) { dir = dirs[di]; for (pos = 0; pos < bsize; pos++) { mp->dir = dir; mp->pos = pos; mp++; } } mp = moves; np = nmoves; for (lvl = 3; lvl < MAXLVL; lvl++) { high = -INF; for (i = 0; i < bsize4; i++) { domove(mp[i].dir, mp[i].pos, mark); s = -ab(lvl, OTHER(mark), -INF, -high); if (s > high) { high = s; bdir = mp[i].dir; bpos = mp[i].pos; if (WINNER(high)) { goto done; } } undomove(); /* sort the move into np */ for (j = i; j > 0; j--) { if (np[j-1].score >= s) break; np[j] = np[j-1]; } np[j].dir = mp[i].dir; np[j].pos = mp[i].pos; np[j].score = s; } *dirp = bdir; *posp = bpos; DPRINTF(("lvl=%d nscore=%d, high=%d\n", lvl, nscore, high)); nscore = 0; tmp = mp; mp = np; np = tmp; } done: *dirp = bdir; *posp = bpos; DPRINTF(("high=%d\n", high)); }
gint get_custom_pos(struct custom_matches *cm, gint table, gint pos, gint *real_res) { struct custom_data *cd = get_custom_table(table); struct match *m = cm->m; gint ix = 0; if (!cd || pos < 1 || pos > cd->num_positions) return 0; if (cd->positions[pos-1].type == COMP_TYPE_MATCH) { g_print("posarg=%d pos=%d match=%d\n", pos, cd->positions[pos-1].pos, cd->positions[pos-1].match); if (cd->positions[pos-1].pos == 1) ix = WINNER(cd->positions[pos-1].match); else ix = LOSER(cd->positions[pos-1].match); } else if (cd->positions[pos-1].type == COMP_TYPE_ROUND_ROBIN) { gint poolnum = cd->positions[pos-1].match; if (poolnum <= 0) return 0; //g_print("*** pos=%d poolnum=%d\n", pos, poolnum); struct pool *p = &cm->pm[poolnum-1]; //g_print("*** finished=%d\n", p->finished); if (!p->finished) return 0; ix = p->competitors[p->competitors[pos-1].position].index; } else if (cd->positions[pos-1].type == COMP_TYPE_BEST_OF_3) { gint pairnum = cd->positions[pos-1].match; if (pairnum <= 0) return 0; struct bestof3 *p = &cm->best_of_three[pairnum-1]; if (!p->finished) return 0; if (pos == 1) ix = p->winner; else ix = p->loser; } if (real_res && cd->positions[pos-1].real_contest_pos) *real_res = cd->positions[pos-1].real_contest_pos; if (ix < 10) ix = 0; return ix; }