コード例 #1
0
ファイル: one.c プロジェクト: Bluerise/openbsd-src
void
movback(int i)
{
	int     j;

	for (j = i - 1; j >= 0; j--)
		backone(j);
}
コード例 #2
0
/*
 * mvnum is number of move (rel zero)
 * see if swapped also tested
 */
static void
trymove(int mvnum, int swapped)
{
    int pos;		/* position on board */
    int rval;		/* value of roll */

    /* if recursed through all dice values, compare move */
    if (mvnum == mvlim) {
        binsert(bsave());
        return;
    }

    /* make sure dice in always same order */
    if (d0 == swapped)
        swap;
    /* choose value for this move */
    rval = dice[mvnum != 0];

    /* find all legitimate moves */
    for (pos = bar; pos != home; pos += cturn) {
        /* fix order of dice */
        if (d0 == swapped)
            swap;
        /* break if stuck on bar */
        if (board[bar] != 0 && pos != bar)
            break;
        /* on to next if not occupied */
        if (board[pos] * cturn <= 0)
            continue;
        /* set up arrays for move */
        p[mvnum] = pos;
        g[mvnum] = pos + rval * cturn;
        if (g[mvnum] * cturn >= home) {
            if (*offptr < 0)
                break;
            g[mvnum] = home;
        }
        /* try to move */
        if (makmove(mvnum))
            continue;
        else
            trymove(mvnum + 1, 2);
        /* undo move to try another */
        backone(mvnum);
    }

    /* swap dice and try again */
    if ((!swapped) && D0 != D1)
        trymove(0, 1);
}