2012-10-13 23:19:38 +04:00
|
|
|
/* $NetBSD: one.c,v 1.9 2012/10/13 19:19:39 dholland Exp $ */
|
1995-03-21 18:03:38 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-03-21 18:03:38 +03:00
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 13:36:50 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-03-21 18:03:38 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)one.c 8.1 (Berkeley) 5/31/93";
|
|
|
|
#else
|
2012-10-13 23:19:38 +04:00
|
|
|
__RCSID("$NetBSD: one.c,v 1.9 2012/10/13 19:19:39 dholland Exp $");
|
1995-03-21 18:03:38 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include "back.h"
|
|
|
|
|
2012-10-13 23:19:38 +04:00
|
|
|
static int checkd(struct move *, int);
|
2009-08-12 09:17:57 +04:00
|
|
|
static int last(void);
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
int
|
2012-10-13 23:19:38 +04:00
|
|
|
makmove(struct move *mm, int i)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
int n, d;
|
|
|
|
int max;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2012-10-13 22:44:14 +04:00
|
|
|
d = mm->d0;
|
|
|
|
n = abs(mm->g[i] - mm->p[i]);
|
1997-10-10 12:59:32 +04:00
|
|
|
max = (*offptr < 0 ? 7 : last());
|
2012-10-13 22:44:14 +04:00
|
|
|
if (board[mm->p[i]] * cturn <= 0)
|
2012-10-13 23:19:38 +04:00
|
|
|
return (checkd(mm, d) + 2);
|
2012-10-13 22:44:14 +04:00
|
|
|
if (mm->g[i] != home && board[mm->g[i]] * cturn < -1)
|
2012-10-13 23:19:38 +04:00
|
|
|
return (checkd(mm, d) + 3);
|
2012-10-13 22:44:14 +04:00
|
|
|
if (i || mm->D0 == mm->D1) {
|
|
|
|
if (n == max ? mm->D1 < n : mm->D1 != n)
|
2012-10-13 23:19:38 +04:00
|
|
|
return (checkd(mm, d) + 1);
|
1997-10-10 12:59:32 +04:00
|
|
|
} else {
|
2012-10-13 22:44:14 +04:00
|
|
|
if (n == max ? mm->D0 < n && mm->D1 < n : mm->D0 != n && mm->D1 != n)
|
2012-10-13 23:19:38 +04:00
|
|
|
return (checkd(mm, d) + 1);
|
2012-10-13 22:44:14 +04:00
|
|
|
if (n == max ? mm->D0 < n : mm->D0 != n) {
|
|
|
|
if (mm->d0)
|
2012-10-13 23:19:38 +04:00
|
|
|
return (checkd(mm, d) + 1);
|
2012-10-13 22:44:14 +04:00
|
|
|
mswap(mm);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
2012-10-13 22:44:14 +04:00
|
|
|
if (mm->g[i] == home && *offptr < 0)
|
2012-10-13 23:19:38 +04:00
|
|
|
return (checkd(mm, d) + 4);
|
2012-10-13 22:44:14 +04:00
|
|
|
mm->h[i] = 0;
|
|
|
|
board[mm->p[i]] -= cturn;
|
|
|
|
if (mm->g[i] != home) {
|
|
|
|
if (board[mm->g[i]] == -cturn) {
|
1993-03-21 12:45:37 +03:00
|
|
|
board[home] -= cturn;
|
2012-10-13 22:44:14 +04:00
|
|
|
board[mm->g[i]] = 0;
|
|
|
|
mm->h[i] = 1;
|
|
|
|
if (abs(bar - mm->g[i]) < 7) {
|
1993-03-21 12:45:37 +03:00
|
|
|
(*inopp)--;
|
|
|
|
if (*offopp >= 0)
|
|
|
|
*offopp -= 15;
|
|
|
|
}
|
|
|
|
}
|
2012-10-13 22:44:14 +04:00
|
|
|
board[mm->g[i]] += cturn;
|
|
|
|
if (abs(home - mm->g[i]) < 7 && abs(home - mm->p[i]) > 6) {
|
1993-03-21 12:45:37 +03:00
|
|
|
(*inptr)++;
|
1997-10-10 12:59:32 +04:00
|
|
|
if (*inptr + *offptr == 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
*offptr += 15;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
(*offptr)++;
|
|
|
|
(*inptr)--;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
2012-10-13 23:19:38 +04:00
|
|
|
moverr(struct move *mm, int i)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
int j;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (tflag)
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(20, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1997-10-10 12:59:32 +04:00
|
|
|
writec('\n');
|
|
|
|
writel("Error: ");
|
|
|
|
for (j = 0; j <= i; j++) {
|
2012-10-13 22:44:14 +04:00
|
|
|
wrint(mm->p[j]);
|
1997-10-10 12:59:32 +04:00
|
|
|
writec('-');
|
2012-10-13 22:44:14 +04:00
|
|
|
wrint(mm->g[j]);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (j < i)
|
1997-10-10 12:59:32 +04:00
|
|
|
writec(',');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
writel("... ");
|
2012-10-13 23:19:38 +04:00
|
|
|
movback(mm, i);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-12 09:17:57 +04:00
|
|
|
static int
|
2012-10-13 23:19:38 +04:00
|
|
|
checkd(struct move *mm, int d)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2012-10-13 22:44:14 +04:00
|
|
|
if (mm->d0 != d)
|
|
|
|
mswap(mm);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:17:57 +04:00
|
|
|
static int
|
2005-07-01 05:12:39 +04:00
|
|
|
last(void)
|
1997-10-10 12:59:32 +04:00
|
|
|
{
|
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = home - 6 * cturn; i != home; i += cturn)
|
|
|
|
if (board[i] * cturn > 0)
|
|
|
|
return (abs(home - i));
|
|
|
|
return (-1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
2012-10-13 23:19:38 +04:00
|
|
|
movback(struct move *mm, int i)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
int j;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
for (j = i - 1; j >= 0; j--)
|
2012-10-13 23:19:38 +04:00
|
|
|
backone(mm, j);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
2012-10-13 23:19:38 +04:00
|
|
|
backone(struct move *mm, int i)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2012-10-13 22:44:14 +04:00
|
|
|
board[mm->p[i]] += cturn;
|
|
|
|
if (mm->g[i] != home) {
|
|
|
|
board[mm->g[i]] -= cturn;
|
|
|
|
if (abs(mm->g[i] - home) < 7 && abs(mm->p[i] - home) > 6) {
|
1993-03-21 12:45:37 +03:00
|
|
|
(*inptr)--;
|
1997-10-10 12:59:32 +04:00
|
|
|
if (*inptr + *offptr < 15 && *offptr >= 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
*offptr -= 15;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
} else {
|
1993-03-21 12:45:37 +03:00
|
|
|
(*offptr)--;
|
|
|
|
(*inptr)++;
|
|
|
|
}
|
2012-10-13 22:44:14 +04:00
|
|
|
if (mm->h[i]) {
|
1993-03-21 12:45:37 +03:00
|
|
|
board[home] += cturn;
|
2012-10-13 22:44:14 +04:00
|
|
|
board[mm->g[i]] = -cturn;
|
|
|
|
if (abs(bar - mm->g[i]) < 7) {
|
1993-03-21 12:45:37 +03:00
|
|
|
(*inopp)++;
|
1997-10-10 12:59:32 +04:00
|
|
|
if (*inopp + *offopp == 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
*offopp += 15;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|