Commits

Shlomi Fish committed 59be913

Convert tabs to spaces.

  • Participants
  • Parent commits d65fc2e
  • Branches make-code-suitable-for-fc-solve

Comments (0)

Files changed (15)

File patsolve/fnv.h

 
 static GCC_INLINE u_int32_t fnv_hash_buf(u_char *s, int len)
 {
-	int i;
-	u_int32_t h;
+    int i;
+    u_int32_t h;
 
-	h = FNV1_32_INIT;
-	for (i = 0; i < len; i++) {
-		h = fnv_hash(*s++, h);
-	}
+    h = FNV1_32_INIT;
+    for (i = 0; i < len; i++) {
+        h = fnv_hash(*s++, h);
+    }
 
-	return h;
+    return h;
 }
 
 /* Hash a 0 terminated string. */
 
 static GCC_INLINE u_int32_t fnv_hash_str(u_char *s)
 {
-	u_int32_t h;
+    u_int32_t h;
 
-	h = FNV1_32_INIT;
-	while (*s) {
-		h = fnv_hash(*s++, h);
-	}
+    h = FNV1_32_INIT;
+    while (*s) {
+        h = fnv_hash(*s++, h);
+    }
 
-	return h;
+    return h;
 }
 
 #endif

File patsolve/ga/findfit.py

 optlist, args = parseargs("n:")
 
 for opt, arg in optlist:
-	if opt == '-n':
-		N = int(arg)
+    if opt == '-n':
+        N = int(arg)
 
 if len(args) < 1:
-	printusage()
-	sys.exit(1)
+    printusage()
+    sys.exit(1)
 
 parse = re.compile(r"running (.*) fitness = ([-+0-9.e]+)")
 
 def sgn(x):
-	if x < 0: return -1
-	return 1
+    if x < 0: return -1
+    return 1
 
 fit = {}
 
 for filename in args:
-	f = open(filename, 'r')
-	for line in f.xreadlines():
-		p = parse.match(line)
-		if p:
-			s = string.split(p.group(1))
-			s[11] = str(sgn(int(s[11])))
-			s = string.join(s)
-			if fit.has_key(s):
-				fit[s].append(float(p.group(2)))
-			else:
-				fit[s] = [float(p.group(2))]
-	f.close()
+    f = open(filename, 'r')
+    for line in f.xreadlines():
+        p = parse.match(line)
+        if p:
+            s = string.split(p.group(1))
+            s[11] = str(sgn(int(s[11])))
+            s = string.join(s)
+            if fit.has_key(s):
+                fit[s].append(float(p.group(2)))
+            else:
+                fit[s] = [float(p.group(2))]
+    f.close()
 
 def add(a, b):
-	return a + b
+    return a + b
 
 m = []
 
 for id in fit.keys():
-	l = fit[id]
-	avg = reduce(add, l, 0) / float(len(l))
-	m.append((avg, id, len(l)))
+    l = fit[id]
+    avg = reduce(add, l, 0) / float(len(l))
+    m.append((avg, id, len(l)))
 
 m.sort(lambda x, y: sgn(x[0] - y[0]))
 #m.sort(lambda x, y: sgn(y[2] - x[2]))
 for i in xrange(N):
-	print m[i][1], 'fitness =', m[i][0], '(%d)' % m[i][2]
+    print m[i][1], 'fitness =', m[i][0], '(%d)' % m[i][2]

File patsolve/ga/ga.py

 optlist, args = parseargs("c:m:n:l:")
 
 for opt, arg in optlist:
-	if opt == '-c':
-		crossprob = float(arg)
-	elif opt == '-m':
-		mutateprob = float(arg)
-	elif opt == '-n':
-		Npop = int(arg)
-	elif opt == '-l':
-		Len = int(arg)
+    if opt == '-c':
+        crossprob = float(arg)
+    elif opt == '-m':
+        mutateprob = float(arg)
+    elif opt == '-n':
+        Npop = int(arg)
+    elif opt == '-l':
+        Len = int(arg)
 
 if len(args) > 1:
-	printusage()
-	sys.exit(1)
+    printusage()
+    sys.exit(1)
 
 seed = int((time.time() * 10000.) % (1<<30))
 rng.seed(seed)
 
 def mutate(l, p):
-	"""mutate(list, probability) -> list
+    """mutate(list, probability) -> list
 
-	Given a list of integers and a mutation probability, mutate the list
-	by either adding or subtracting from some of the elements.  The
-	mutated list is returned."""
+    Given a list of integers and a mutation probability, mutate the list
+    by either adding or subtracting from some of the elements.  The
+    mutated list is returned."""
 
-	(p, q) = torat(p)
-	m = [1] * 24 + [2] * 12 + [3] * 6 + [4] * 3 + [5] * 2 + [6] * 1
-	def flip(x, p = p, q = q, m = m):
-		if rng.flip(p, q):
-			y = m[rng.random() % len(m)]
-			if rng.flip(1, 2):
-				return x + y
-			return x - y
-		return x
+    (p, q) = torat(p)
+    m = [1] * 24 + [2] * 12 + [3] * 6 + [4] * 3 + [5] * 2 + [6] * 1
+    def flip(x, p = p, q = q, m = m):
+        if rng.flip(p, q):
+            y = m[rng.random() % len(m)]
+            if rng.flip(1, 2):
+                return x + y
+            return x - y
+        return x
 
-	return map(flip, l)
+    return map(flip, l)
 
 def cross(l1, l2, p):
-	"""cross(list, list, probability) -> list
+    """cross(list, list, probability) -> list
 
-	Take elements from one list until a crossover is made, then take
-	elements from the other list, and so on, with the given probability
-	of a crossover at each position.  The initial list is chosen at
-	random from one of the two lists with equal probability.  The lists
-	must be the same length."""
+    Take elements from one list until a crossover is made, then take
+    elements from the other list, and so on, with the given probability
+    of a crossover at each position.  The initial list is chosen at
+    random from one of the two lists with equal probability.  The lists
+    must be the same length."""
 
-	l = [0] * len(l1)
-	x = map(None, l1, l2)
-	j = rng.random() % 2
-	(p, q) = torat(p)
-	for i in xrange(len(l1)):
-		if rng.flip(p, q):
-			j = 1 - j
-		l[i] = x[i][j]
+    l = [0] * len(l1)
+    x = map(None, l1, l2)
+    j = rng.random() % 2
+    (p, q) = torat(p)
+    for i in xrange(len(l1)):
+        if rng.flip(p, q):
+            j = 1 - j
+        l[i] = x[i][j]
 
-	return l
+    return l
 
 def breed(l1, l2):
-	"""breed(list, list) -> list
+    """breed(list, list) -> list
 
-	Given two individuals, cross them and mutate the result."""
+    Given two individuals, cross them and mutate the result."""
 
-	return mutate(cross(l1, l2, crossprob), mutateprob)
+    return mutate(cross(l1, l2, crossprob), mutateprob)
 
 def initpop(nl = None):
-	"""The initial population is a list of length Npop of lists of
-	length Nparam."""
+    """The initial population is a list of length Npop of lists of
+    length Nparam."""
 
-	global Npop, Nparam
+    global Npop, Nparam
 
-	if nl:
-		l = []
-		f = open(nl[0], 'r')
-		for s in f.readlines():
-			if s[0] != '#':
-				m = map(int, string.split(s))
-				l.append(m)
-		f.close()
-		Npop = len(l)
-		Nparam = len(l[0])
-	else:
-		oldcanon = [5, 4, 6, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 1]
-		canon0 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
-		canon1 = [2, 6, 2, 0, -5, -9, -5, -11, 3, 1, -5, 2, 2, 0]
-		canon2 = [1, 1, 6, -2, -1, -2, -2, -3, 0, -1, 2, 4, 6, 1]
-		Nparam = len(canon1)
-		l = [breed(canon1, canon2) for x in xrange(Npop)]
+    if nl:
+        l = []
+        f = open(nl[0], 'r')
+        for s in f.readlines():
+            if s[0] != '#':
+                m = map(int, string.split(s))
+                l.append(m)
+        f.close()
+        Npop = len(l)
+        Nparam = len(l[0])
+    else:
+        oldcanon = [5, 4, 6, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 1]
+        canon0 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
+        canon1 = [2, 6, 2, 0, -5, -9, -5, -11, 3, 1, -5, 2, 2, 0]
+        canon2 = [1, 1, 6, -2, -1, -2, -2, -3, 0, -1, 2, 4, 6, 1]
+        Nparam = len(canon1)
+        l = [breed(canon1, canon2) for x in xrange(Npop)]
 #                l = [mutate(canon0, .9) for x in xrange(Npop)]
 
-	return l
+    return l
 
 def newpop(result):
-	"""The result of a generation is a list of pairs, where each
-	pair consists of the fitness value and the individual that
-	generated it.  Construct a new population (formatted as a
-	list of lists) using the following steps:
-		1. Sort by the fitness value (smallest first).
-		2. Replace the last half of the sorted population with
-		   new individuals bred from pairs chosen at random
-		   from the first half.
-	The new population is returned."""
+    """The result of a generation is a list of pairs, where each
+    pair consists of the fitness value and the individual that
+    generated it.  Construct a new population (formatted as a
+    list of lists) using the following steps:
+        1. Sort by the fitness value (smallest first).
+        2. Replace the last half of the sorted population with
+           new individuals bred from pairs chosen at random
+           from the first half.
+    The new population is returned."""
 
-	result.sort()
-	printf('%d: %g, %s\n', Gen, result[0][0], result[0][1])
-	pop = [0] * Npop
-	cut = int(Npop * .5)
-	for i in xrange(cut):
-		pop[i] = result[i][1]
-	for i in xrange(cut, Npop):
-		a = rng.random() % cut
-		b = rng.random() % cut
-		pop[i] = breed(result[a][1], result[b][1])
+    result.sort()
+    printf('%d: %g, %s\n', Gen, result[0][0], result[0][1])
+    pop = [0] * Npop
+    cut = int(Npop * .5)
+    for i in xrange(cut):
+        pop[i] = result[i][1]
+    for i in xrange(cut, Npop):
+        a = rng.random() % cut
+        b = rng.random() % cut
+        pop[i] = breed(result[a][1], result[b][1])
 
-	return pop
+    return pop
 
 def sgn(x):
-	if x < 0: return -1
-	return 1
+    if x < 0: return -1
+    return 1
 
 def refill(pop):
-	"""Get rid of duplicates."""
+    """Get rid of duplicates."""
 
-	for l in pop:
-		l[9] = sgn(l[9])
-		l[-1] = abs(l[-1])
-	pop.sort()
+    for l in pop:
+        l[9] = sgn(l[9])
+        l[-1] = abs(l[-1])
+    pop.sort()
 
-	newpop = [0] * Npop
-	i = 0
-	last = None
-	for l in pop:
-		if l != last:
-			newpop[i] = l
-			i += 1
-		last = l
-	for j in xrange(i, Npop):
-		a = rng.random() % i
-		b = rng.random() % i
-		newpop[j] = breed(newpop[a], newpop[b])
+    newpop = [0] * Npop
+    i = 0
+    last = None
+    for l in pop:
+        if l != last:
+            newpop[i] = l
+            i += 1
+        last = l
+    for j in xrange(i, Npop):
+        a = rng.random() % i
+        b = rng.random() % i
+        newpop[j] = breed(newpop[a], newpop[b])
 
-	return newpop
+    return newpop
 
 def run(pop):
-	"""Test each member of the population and save it with its
-	fitness value."""
+    """Test each member of the population and save it with its
+    fitness value."""
 
-	result = [0] * Npop
-	i = 0
-	for l in pop:
-		result[i] = (fitness(l), l)
-		i += 1
+    result = [0] * Npop
+    i = 0
+    for l in pop:
+        result[i] = (fitness(l), l)
+        i += 1
 
-	return result
+    return result
 
 def get_ycoeff(l):
-	"""Find the quadratic through (0, l[0]), (25, l[1]), and (50, l[2]).
-	Return the coefficients as a string, e.g., '.5 1.2 2.'"""
+    """Find the quadratic through (0, l[0]), (25, l[1]), and (50, l[2]).
+    Return the coefficients as a string, e.g., '.5 1.2 2.'"""
 
-	f = open('/tmp/x', 'w')
-	fprintf(f, '0 %d\n', l[0])
-	fprintf(f, '25 %d\n', l[1])
-	fprintf(f, '50 %d\n', l[2])
-	f.close()
-	os.system('fit/dofit /tmp/x > /tmp/coeff')
-	f = open('/tmp/coeff', 'r')
-	l = f.readlines()
-	f.close()
-	return string.join(map(str, map(float, l)))
+    f = open('/tmp/x', 'w')
+    fprintf(f, '0 %d\n', l[0])
+    fprintf(f, '25 %d\n', l[1])
+    fprintf(f, '50 %d\n', l[2])
+    f.close()
+    os.system('fit/dofit /tmp/x > /tmp/coeff')
+    f = open('/tmp/coeff', 'r')
+    l = f.readlines()
+    f.close()
+    return string.join(map(str, map(float, l)))
 
 move = re.compile(r"([0-9]+) moves.")
 pos = re.compile(r"([0-9]+) positions generated.")
 malloc = re.compile(r".*memory.*")
 
 def fitness(l):
-	"""Run the individual and return the fitness value."""
+    """Run the individual and return the fitness value."""
 
-	nx = Nparam - 4
-	param = '-c%d ' % (abs(l[-1]) + 1)
-	param += '-X%d %s ' % (nx, string.join(map(str, l[:nx])))
-	s = get_ycoeff(l[-4:-1])
-	param += '-Y %s' % s
-	resname = 'res'
+    nx = Nparam - 4
+    param = '-c%d ' % (abs(l[-1]) + 1)
+    param += '-X%d %s ' % (nx, string.join(map(str, l[:nx])))
+    s = get_ycoeff(l[-4:-1])
+    param += '-Y %s' % s
+    resname = 'res'
 
-	cmd = '/home/tomh/src/patsolve/xpatsolve %s -N%d %d %s > %s'
-	cmd %= (Opts, Start, Start + Len, param, resname)
+    cmd = '/home/tomh/src/patsolve/xpatsolve %s -N%d %d %s > %s'
+    cmd %= (Opts, Start, Start + Len, param, resname)
 
-	printf('running %s ', param)
-	sys.stdout.flush()
-	t0 = os.times()[2]
-	os.system(cmd)
-	t1 = os.times()[2]
+    printf('running %s ', param)
+    sys.stdout.flush()
+    t0 = os.times()[2]
+    os.system(cmd)
+    t1 = os.times()[2]
 
-	f = open(resname, 'r')
-	sum = 0
-	n = 0
-	mem = 0
-	for s in f.xreadlines():
-		x = move.findall(s)
+    f = open(resname, 'r')
+    sum = 0
+    n = 0
+    mem = 0
+    for s in f.xreadlines():
+        x = move.findall(s)
 #                x = pos.findall(s)
 #                x = memrem.findall(s)
-		if x:
-			m = int(x[-1])
-			sum += m
-			n += 1
-		elif malloc.match(s):
-			sum += 1000
-			mem += 1
-			n += 1
-	f.close()
+        if x:
+            m = int(x[-1])
+            sum += m
+            n += 1
+        elif malloc.match(s):
+            sum += 1000
+            mem += 1
+            n += 1
+    f.close()
 
-	if n == 0:
-		printf('no result\n')
-		return 1000000
+    if n == 0:
+        printf('no result\n')
+        return 1000000
 #        fit = Mem - float(sum) / n
 #        fit = float(sum) / n
-	fit = (t1 - t0) / Len
-	if mem > 0:
-		printf('fitness = %g, oom = %d\n', fit, mem)
-	else:
-		printf('fitness = %g\n', fit)
-	return fit
+    fit = (t1 - t0) / Len
+    if mem > 0:
+        printf('fitness = %g, oom = %d\n', fit, mem)
+    else:
+        printf('fitness = %g\n', fit)
+    return fit
 
 def ga():
-	"""Run the GA over many generations."""
+    """Run the GA over many generations."""
 
-	global Start, Gen
+    global Start, Gen
 
-	pop = initpop(args)
-	while 1:
-		f = open('curpop', 'w')
-		fprintf(f, '# %s\n', Opts)
-		for l in pop:
-			fprintf(f, '%s\n', string.join(map(str, l)))
-		f.close()
-		pop = refill(pop)
-		result = run(pop)
-		pop = newpop(result)
+    pop = initpop(args)
+    while 1:
+        f = open('curpop', 'w')
+        fprintf(f, '# %s\n', Opts)
+        for l in pop:
+            fprintf(f, '%s\n', string.join(map(str, l)))
+        f.close()
+        pop = refill(pop)
+        result = run(pop)
+        pop = newpop(result)
 #                Start = Start + Len
-		Start = rng.random() % 1000000000
-		Gen += 1
+        Start = rng.random() % 1000000000
+        Gen += 1
 
 ga()

File patsolve/ga/mt19937.c

 
 void seedMT(uint32 seed)
 {
-	register uint32 x = (seed | 1U) & 0xFFFFFFFFU, *s = state;
-	register int j;
+    register uint32 x = (seed | 1U) & 0xFFFFFFFFU, *s = state;
+    register int j;
 
-	left = 0;
-	for (*s++ = x, j = N; --j; *s++ = (x *= 69069U) & 0xFFFFFFFFU) {
-	}
+    left = 0;
+    for (*s++ = x, j = N; --j; *s++ = (x *= 69069U) & 0xFFFFFFFFU) {
+    }
 }
 
 static uint32 reloadMT(void)
 {
-	register uint32 *p0 = state, *p2 = state + 2, *pM = state + M, s0, s1;
-	register int j;
+    register uint32 *p0 = state, *p2 = state + 2, *pM = state + M, s0, s1;
+    register int j;
 
-	left = N - 1;
-	next = state + 1;
+    left = N - 1;
+    next = state + 1;
 
-	for (s0 = state[0], s1 = state[1], j = L; --j; s0 = s1, s1 = *p2++) {
-		*p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K1 : 0U);
-	}
-	for (pM = state, j = M; --j; s0 = s1, s1 = *p2++) {
-		*p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K1 : 0U);
-	}
-	s1 = state[0];
-	*p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K1 : 0U);
+    for (s0 = state[0], s1 = state[1], j = L; --j; s0 = s1, s1 = *p2++) {
+        *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K1 : 0U);
+    }
+    for (pM = state, j = M; --j; s0 = s1, s1 = *p2++) {
+        *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K1 : 0U);
+    }
+    s1 = state[0];
+    *p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K1 : 0U);
 
-	s1 ^= (s1 >> 11);
-	s1 ^= (s1 <<  7) & K2;
-	s1 ^= (s1 << 15) & K3;
-	return (s1 ^ (s1 >> 18));
+    s1 ^= (s1 >> 11);
+    s1 ^= (s1 <<  7) & K2;
+    s1 ^= (s1 << 15) & K3;
+    return (s1 ^ (s1 >> 18));
 }
 
 uint32 randomMT(void)
 {
-	uint32 y;
+    uint32 y;
 
-	if (--left < 0) {
-		return (reloadMT());
-	}
-	y  = *next++;
-	y ^= (y >> 11);
-	y ^= (y <<  7) & K2;
-	y ^= (y << 15) & K3;
-	return (y ^ (y >> 18));
+    if (--left < 0) {
+        return (reloadMT());
+    }
+    y  = *next++;
+    y ^= (y >> 11);
+    y ^= (y <<  7) & K2;
+    y ^= (y << 15) & K3;
+    return (y ^ (y >> 18));
 }

File patsolve/msdeal.c

 
 VOID srandp(UINT s)
 {
-	seedx = (LONG) s;
+    seedx = (LONG) s;
 }
 
 UINT randp()
 {
-	seedx = seedx * 214013L + 2531011L;
-	return (seedx >> 16) & 0xffff;
+    seedx = seedx * 214013L + 2531011L;
+    return (seedx >> 16) & 0xffff;
 }
 
 VOID srando(UINT s)
 {
-	seedx = (LONG) s;
+    seedx = (LONG) s;
 }
 
 UINT rando()
 {
-	seedx = seedx * 214013L + 2531011L;
-	return (seedx >> 16) & 0x7fff;
+    seedx = seedx * 214013L + 2531011L;
+    return (seedx >> 16) & 0x7fff;
 }
 
 char Rank[] = "A23456789TJQK";
 
 int main(int argc, char **argv)
 {
-	int i, j, c;
-	int wLeft = NUM_CARDS;  // cards left to be chosen in shuffle
-	CARD deck[NUM_CARDS];
-	CARD pos[10][10];
-	LONG gnGameNumber;
+    int i, j, c;
+    int wLeft = NUM_CARDS;  // cards left to be chosen in shuffle
+    CARD deck[NUM_CARDS];
+    CARD pos[10][10];
+    LONG gnGameNumber;
 
-	if (argc > 2 && argv[1][0] == 's') {
-		Nwpiles = 10;
-		argv++;
-		argc--;
-	}
+    if (argc > 2 && argv[1][0] == 's') {
+        Nwpiles = 10;
+        argv++;
+        argc--;
+    }
 
-	if (argc != 2) {
-		fprintf(stderr, "usage: %s number\n", argv[0]);
-		exit(1);
-	}
-	gnGameNumber = strtoul(argv[1], NULL, 10);
+    if (argc != 2) {
+        fprintf(stderr, "usage: %s number\n", argv[0]);
+        exit(1);
+    }
+    gnGameNumber = strtoul(argv[1], NULL, 10);
 
-	memset(pos, 0, sizeof(pos));
-	for (i = 0; i < NUM_CARDS; i++) {
-		deck[i] = i + 1;
-	}
+    memset(pos, 0, sizeof(pos));
+    for (i = 0; i < NUM_CARDS; i++) {
+        deck[i] = i + 1;
+    }
 
-	if (gnGameNumber < 0x100000000) {
-		srando((UINT) gnGameNumber);
-	} else {
-		srandp((UINT) (gnGameNumber - 0x100000000));
-	}
-	for (i = 0; i < NUM_CARDS; i++) {
-		if (gnGameNumber < 0x100000000) {
-			if (gnGameNumber < 0x80000000) {
-				j = rando() % wLeft;
-			} else {
-				j = (rando() | 0x8000) % wLeft;
-			}
-		} else {
-			j = (randp() + 1) % wLeft;
-		}
-		pos[i % Nwpiles][i / Nwpiles] = deck[j];
-		deck[j] = deck[--wLeft];
-		if (Nwpiles == 10 && i == 49) {
-			break;
-		}
-	}
-	for (i = 0; i < Nwpiles; i++) {
-		j = 0;
-		while (pos[i][j]) {
-			c = pos[i][j] - 1;
-			j++;
-			printf("%c%c ", Rank[c / 4], Suit[c % 4]);
-		}
-		putchar('\n');
-	}
-	/* leftover cards to temp */
-	c = -1;
-	for (i = 0; i < 4; i++) {
-		if (wLeft) {
-			j = --wLeft;
-			c = deck[j] - 1;
-			printf("%c%c ", Rank[c / 4], Suit[c % 4]);
-		}
-	}
-	if (c >= 0) putchar('\n');
-	return 0;
+    if (gnGameNumber < 0x100000000) {
+        srando((UINT) gnGameNumber);
+    } else {
+        srandp((UINT) (gnGameNumber - 0x100000000));
+    }
+    for (i = 0; i < NUM_CARDS; i++) {
+        if (gnGameNumber < 0x100000000) {
+            if (gnGameNumber < 0x80000000) {
+                j = rando() % wLeft;
+            } else {
+                j = (rando() | 0x8000) % wLeft;
+            }
+        } else {
+            j = (randp() + 1) % wLeft;
+        }
+        pos[i % Nwpiles][i / Nwpiles] = deck[j];
+        deck[j] = deck[--wLeft];
+        if (Nwpiles == 10 && i == 49) {
+            break;
+        }
+    }
+    for (i = 0; i < Nwpiles; i++) {
+        j = 0;
+        while (pos[i][j]) {
+            c = pos[i][j] - 1;
+            j++;
+            printf("%c%c ", Rank[c / 4], Suit[c % 4]);
+        }
+        putchar('\n');
+    }
+    /* leftover cards to temp */
+    c = -1;
+    for (i = 0; i < 4; i++) {
+        if (wLeft) {
+            j = --wLeft;
+            c = deck[j] - 1;
+            printf("%c%c ", Rank[c / 4], Suit[c % 4]);
+        }
+    }
+    if (c >= 0) putchar('\n');
+    return 0;
 }

File patsolve/msdealsub.c

 
 static VOID srandp(LONG * seedx_ptr, UINT s)
 {
-	*(seedx_ptr) = (LONG) s;
+    *(seedx_ptr) = (LONG) s;
 }
 
 static UINT randp(LONG * seedx_ptr)
 {
-	*(seedx_ptr) = *(seedx_ptr) * 214013L + 2531011L;
-	return (((*seedx_ptr) >> 16) & 0xffff);
+    *(seedx_ptr) = *(seedx_ptr) * 214013L + 2531011L;
+    return (((*seedx_ptr) >> 16) & 0xffff);
 }
 
 #define srando(a,b) srandp(a,b)
 static UINT rando(LONG * seedx_ptr)
 {
-	*(seedx_ptr) = *(seedx_ptr) * 214013L + 2531011L;
-	return ((*seedx_ptr) >> 16) & 0x7fff;
+    *(seedx_ptr) = *(seedx_ptr) * 214013L + 2531011L;
+    return ((*seedx_ptr) >> 16) & 0x7fff;
 }
 
 #define PS_DIAMOND 0x00         /* red */
 
 void msdeal(fc_solve_soft_thread_t * soft_thread, LONG gnGameNumber)
 {
-	int i, j, c;
-	int wLeft = NUM_CARDS;  // cards left to be chosen in shuffle
-	CARD deck[NUM_CARDS];
-	CARD pos[MAXWPILES][NUM_CARDS+1];
+    int i, j, c;
+    int wLeft = NUM_CARDS;  // cards left to be chosen in shuffle
+    CARD deck[NUM_CARDS];
+    CARD pos[MAXWPILES][NUM_CARDS+1];
     LONG seedx;
 
-	memset(pos, 0, sizeof(pos));
-	for (i = 0; i < NUM_CARDS; i++) {
-		deck[i] = i + 1;
-	}
+    memset(pos, 0, sizeof(pos));
+    for (i = 0; i < NUM_CARDS; i++) {
+        deck[i] = i + 1;
+    }
 
-	if (gnGameNumber < 0x100000000LL) {
-		srando(&seedx, (UINT) gnGameNumber);
-	} else {
-		srandp(&seedx, (UINT) (gnGameNumber - 0x100000000LL));
-	}
+    if (gnGameNumber < 0x100000000LL) {
+        srando(&seedx, (UINT) gnGameNumber);
+    } else {
+        srandp(&seedx, (UINT) (gnGameNumber - 0x100000000LL));
+    }
 
-	for (i = 0; i < NUM_CARDS; i++) {
-		if (gnGameNumber < 0x100000000LL) {
-			if (gnGameNumber < 0x80000000) {
-				j = rando(&seedx) % wLeft;
-			} else {
-				j = (rando(&seedx) | 0x8000) % wLeft;
-			}
-		} else {
-			j = (randp(&seedx) + 1) % wLeft;
-		}
-		pos[i % soft_thread->Nwpiles][i / soft_thread->Nwpiles] = deck[j];
-		deck[j] = deck[--wLeft];
-		if (soft_thread->Nwpiles == 10 && i == 49) {
-			break;
-		}
-	}
-	for (i = 0; i < soft_thread->Nwpiles; i++) {
-		j = 0;
-		while (pos[i][j]) {
-			c = pos[i][j] - 1;
-			soft_thread->W[i][j] = msdeal_Suit[c % 4] + (c / 4) + 1;
-			j++;
-		}
-		soft_thread->Wp[i] = &soft_thread->W[i][j - 1];
-		soft_thread->Wlen[i] = j;
-	}
-	/* leftover cards to temp */
-	for (i = 0; i < MAXTPILES; i++) {
-		soft_thread->T[i] = 0;
-		if (wLeft) {
-			j = --wLeft;
-			c = deck[j] - 1;
-			soft_thread->T[i] = msdeal_Suit[c % 4] + (c / 4) + 1;
-		}
-	}
-	for (i = 0; i < 4; i++) {
-		soft_thread->O[i] = 0;
-	}
+    for (i = 0; i < NUM_CARDS; i++) {
+        if (gnGameNumber < 0x100000000LL) {
+            if (gnGameNumber < 0x80000000) {
+                j = rando(&seedx) % wLeft;
+            } else {
+                j = (rando(&seedx) | 0x8000) % wLeft;
+            }
+        } else {
+            j = (randp(&seedx) + 1) % wLeft;
+        }
+        pos[i % soft_thread->Nwpiles][i / soft_thread->Nwpiles] = deck[j];
+        deck[j] = deck[--wLeft];
+        if (soft_thread->Nwpiles == 10 && i == 49) {
+            break;
+        }
+    }
+    for (i = 0; i < soft_thread->Nwpiles; i++) {
+        j = 0;
+        while (pos[i][j]) {
+            c = pos[i][j] - 1;
+            soft_thread->W[i][j] = msdeal_Suit[c % 4] + (c / 4) + 1;
+            j++;
+        }
+        soft_thread->Wp[i] = &soft_thread->W[i][j - 1];
+        soft_thread->Wlen[i] = j;
+    }
+    /* leftover cards to temp */
+    for (i = 0; i < MAXTPILES; i++) {
+        soft_thread->T[i] = 0;
+        if (wLeft) {
+            j = --wLeft;
+            c = deck[j] - 1;
+            soft_thread->T[i] = msdeal_Suit[c % 4] + (c / 4) + 1;
+        }
+    }
+    for (i = 0; i < 4; i++) {
+        soft_thread->O[i] = 0;
+    }
 }

File patsolve/param.h

 #define NYPARAM 3
 
 typedef struct {
-	int x[NXPARAM];
-	double y[NYPARAM];
+    int x[NXPARAM];
+    double y[NYPARAM];
 } XYparam_t;
 
 extern const XYparam_t XYparam[];

File patsolve/param.py

 #define NYPARAM %d
 
 typedef struct {
-	int x[NXPARAM];
-	double y[NYPARAM];
+    int x[NXPARAM];
+    double y[NYPARAM];
 } XYparam_t;
 
 extern const XYparam_t XYparam[];
 p = 0
 f = open(filename)
 for line in f.xreadlines():
-	if line[0] == '#' or line[0] == '\n':
-		continue
-	l = string.split(line)
-	h.write("#define %s %d\n" % (l[0], p))
-	c.write(" {{ ")
-	for x in l[1:NXPARAM + 1]:
-		c.write("%s, " % x)
-	c.write("}, { ")
-	for y in l[NXPARAM + 1:]:
-		c.write("%s, " % y)
-	c.write("}},\n")
-	p += 1
+    if line[0] == '#' or line[0] == '\n':
+        continue
+    l = string.split(line)
+    h.write("#define %s %d\n" % (l[0], p))
+    c.write(" {{ ")
+    for x in l[1:NXPARAM + 1]:
+        c.write("%s, " % x)
+    c.write("}, { ")
+    for y in l[NXPARAM + 1:]:
+        c.write("%s, " % y)
+    c.write("}},\n")
+    p += 1
 
 c.write("};\n")
 

File patsolve/pat.c

 
 static GCC_INLINE void hashpile(fc_solve_soft_thread_t * soft_thread, int w)
 {
-	soft_thread->W[w][soft_thread->Wlen[w]] = 0;
-	soft_thread->Whash[w] = fnv_hash_str(soft_thread->W[w]);
+    soft_thread->W[w][soft_thread->Wlen[w]] = 0;
+    soft_thread->Whash[w] = fnv_hash_str(soft_thread->W[w]);
 
-	/* Invalidate this pile's id.  We'll calculate it later. */
+    /* Invalidate this pile's id.  We'll calculate it later. */
 
-	soft_thread->Wpilenum[w] = -1;
+    soft_thread->Wpilenum[w] = -1;
 }
 
 /* Hash the whole layout.  This is called once, at the start. */
 
 void hash_layout(fc_solve_soft_thread_t * soft_thread)
 {
-	int w;
+    int w;
 
-	for (w = 0; w < soft_thread->Nwpiles; w++) {
-		hashpile(soft_thread, w);
-	}
+    for (w = 0; w < soft_thread->Nwpiles; w++) {
+        hashpile(soft_thread, w);
+    }
 }
 
 /* These two routines make and unmake moves. */
 
 void make_move(fc_solve_soft_thread_t * soft_thread, MOVE *m)
 {
-	int from, to;
-	card_t card;
+    int from, to;
+    card_t card;
 
-	from = m->from;
-	to = m->to;
+    from = m->from;
+    to = m->to;
 
-	/* Remove from pile. */
+    /* Remove from pile. */
 
-	if (m->fromtype == T_TYPE) {
-		card = soft_thread->T[from];
-		soft_thread->T[from] = NONE;
-	} else {
-		card = *soft_thread->Wp[from]--;
-		soft_thread->Wlen[from]--;
-		hashpile(soft_thread, from);
-	}
+    if (m->fromtype == T_TYPE) {
+        card = soft_thread->T[from];
+        soft_thread->T[from] = NONE;
+    } else {
+        card = *soft_thread->Wp[from]--;
+        soft_thread->Wlen[from]--;
+        hashpile(soft_thread, from);
+    }
 
-	/* Add to pile. */
+    /* Add to pile. */
 
-	if (m->totype == T_TYPE) {
-		soft_thread->T[to] = card;
-	} else if (m->totype == W_TYPE) {
-		*++soft_thread->Wp[to] = card;
-		soft_thread->Wlen[to]++;
-		hashpile(soft_thread, to);
-	} else {
-		soft_thread->O[to]++;
-	}
+    if (m->totype == T_TYPE) {
+        soft_thread->T[to] = card;
+    } else if (m->totype == W_TYPE) {
+        *++soft_thread->Wp[to] = card;
+        soft_thread->Wlen[to]++;
+        hashpile(soft_thread, to);
+    } else {
+        soft_thread->O[to]++;
+    }
 }
 
 void undo_move(fc_solve_soft_thread_t * soft_thread, MOVE *m)
 {
-	int from, to;
-	card_t card;
+    int from, to;
+    card_t card;
 
-	from = m->from;
-	to = m->to;
+    from = m->from;
+    to = m->to;
 
-	/* Remove from 'to' pile. */
+    /* Remove from 'to' pile. */
 
-	if (m->totype == T_TYPE) {
-		card = soft_thread->T[to];
-		soft_thread->T[to] = NONE;
-	} else if (m->totype == W_TYPE) {
-		card = *soft_thread->Wp[to]--;
-		soft_thread->Wlen[to]--;
-		hashpile(soft_thread, to);
-	} else {
-		card = soft_thread->O[to] + Osuit[to];
-		soft_thread->O[to]--;
-	}
+    if (m->totype == T_TYPE) {
+        card = soft_thread->T[to];
+        soft_thread->T[to] = NONE;
+    } else if (m->totype == W_TYPE) {
+        card = *soft_thread->Wp[to]--;
+        soft_thread->Wlen[to]--;
+        hashpile(soft_thread, to);
+    } else {
+        card = soft_thread->O[to] + Osuit[to];
+        soft_thread->O[to]--;
+    }
 
-	/* Add to 'from' pile. */
+    /* Add to 'from' pile. */
 
-	if (m->fromtype == T_TYPE) {
-		soft_thread->T[from] = card;
-	} else {
-		*++soft_thread->Wp[from] = card;
-		soft_thread->Wlen[from]++;
-		hashpile(soft_thread, from);
-	}
+    if (m->fromtype == T_TYPE) {
+        soft_thread->T[from] = card;
+    } else {
+        *++soft_thread->Wp[from] = card;
+        soft_thread->Wlen[from]++;
+        hashpile(soft_thread, from);
+    }
 }
 
 /* This prune applies only to Seahaven in -k mode: if we're putting a card
 
 static int prune_seahaven(fc_solve_soft_thread_t * soft_thread, MOVE *mp)
 {
-	int i, j, w, r, s;
+    int i, j, w, r, s;
 
-	if (!soft_thread->Same_suit || !soft_thread->King_only || mp->totype != W_TYPE) {
-		return FALSE;
-	}
-	w = mp->to;
+    if (!soft_thread->Same_suit || !soft_thread->King_only || mp->totype != W_TYPE) {
+        return FALSE;
+    }
+    w = mp->to;
 
-	/* Count the number of cards below this card. */
+    /* Count the number of cards below this card. */
 
-	j = 0;
-	r = rank(mp->card) + 1;
-	s = suit(mp->card);
-	for (i = soft_thread->Wlen[w] - 1; i >= 0; i--) {
-		if (suit(soft_thread->W[w][i]) == s && rank(soft_thread->W[w][i]) == r + j) {
-			j++;
-		}
-	}
-	if (j < soft_thread->Ntpiles + 1) {
-		return FALSE;
-	}
+    j = 0;
+    r = rank(mp->card) + 1;
+    s = suit(mp->card);
+    for (i = soft_thread->Wlen[w] - 1; i >= 0; i--) {
+        if (suit(soft_thread->W[w][i]) == s && rank(soft_thread->W[w][i]) == r + j) {
+            j++;
+        }
+    }
+    if (j < soft_thread->Ntpiles + 1) {
+        return FALSE;
+    }
 
-	/* If there's a smaller card of this suit in the pile, we can prune
-	the move. */
+    /* If there's a smaller card of this suit in the pile, we can prune
+    the move. */
 
-	j = soft_thread->Wlen[w];
-	r -= 1;
-	for (i = 0; i < j; i++) {
-		if (suit(soft_thread->W[w][i]) == s && rank(soft_thread->W[w][i]) < r) {
-			return TRUE;
-		}
-	}
+    j = soft_thread->Wlen[w];
+    r -= 1;
+    for (i = 0; i < j; i++) {
+        if (suit(soft_thread->W[w][i]) == s && rank(soft_thread->W[w][i]) < r) {
+            return TRUE;
+        }
+    }
 
-	return FALSE;
+    return FALSE;
 }
 
 /* This utility routine is used to check if a card is ever moved in
 
 static GCC_INLINE int cardmoved(card_t card, MOVE **mpp, int j)
 {
-	int i;
+    int i;
 
-	for (i = 0; i < j; i++) {
-		if (mpp[i]->card == card) {
-			return TRUE;
-		}
-	}
-	return FALSE;
+    for (i = 0; i < j; i++) {
+        if (mpp[i]->card == card) {
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 /* This utility routine is used to check if a card is ever used as a
 
 static GCC_INLINE int cardisdest(card_t card, MOVE **mpp, int j)
 {
-	int i;
+    int i;
 
-	for (i = 0; i < j; i++) {
-		if (mpp[i]->destcard == card) {
-			return TRUE;
-		}
-	}
-	return FALSE;
+    for (i = 0; i < j; i++) {
+        if (mpp[i]->destcard == card) {
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 /* Prune redundant moves, if we can prove that they really are redundant. */
 
 static int prune_redundant(fc_solve_soft_thread_t * soft_thread, MOVE *mp, POSITION *pos0)
 {
-	int i, j;
-	int zerot;
-	MOVE *m, *prev[MAXPREVMOVE];
-	POSITION *pos;
+    int i, j;
+    int zerot;
+    MOVE *m, *prev[MAXPREVMOVE];
+    POSITION *pos;
 
-	/* Don't move the same card twice in a row. */
+    /* Don't move the same card twice in a row. */
 
-	pos = pos0;
-	if (pos->depth == 0) {
-		return FALSE;
-	}
-	m = &pos->move;
-	if (m->card == mp->card) {
-		return TRUE;
-	}
+    pos = pos0;
+    if (pos->depth == 0) {
+        return FALSE;
+    }
+    m = &pos->move;
+    if (m->card == mp->card) {
+        return TRUE;
+    }
 
-	/* The check above is the simplest case of the more general strategy
-	of searching the move stack (up the chain of parents) to prove that
-	the current move is redundant.  To do that, we need some more data. */
+    /* The check above is the simplest case of the more general strategy
+    of searching the move stack (up the chain of parents) to prove that
+    the current move is redundant.  To do that, we need some more data. */
 
-	pos = pos->parent;
-	if (pos->depth == 0) {
-		return FALSE;
-	}
-	prev[0] = m;
-	j = -1;
-	for (i = 1; i < MAXPREVMOVE; i++) {
+    pos = pos->parent;
+    if (pos->depth == 0) {
+        return FALSE;
+    }
+    prev[0] = m;
+    j = -1;
+    for (i = 1; i < MAXPREVMOVE; i++) {
 
-		/* Make a list of the last few moves. */
+        /* Make a list of the last few moves. */
 
-		prev[i] = &pos->move;
+        prev[i] = &pos->move;
 
-		/* Locate the last time we moved this card. */
+        /* Locate the last time we moved this card. */
 
-		if (m->card == mp->card) {
-			j = i;
-			break;
-		}
+        if (m->card == mp->card) {
+            j = i;
+            break;
+        }
 
-		/* Keep going up the move stack, looking for this
-		card, until we run out of moves (or patience). */
+        /* Keep going up the move stack, looking for this
+        card, until we run out of moves (or patience). */
 
-		pos = pos->parent;
-		if (pos->depth == 0) {
-			return FALSE;
-		}
-	}
+        pos = pos->parent;
+        if (pos->depth == 0) {
+            return FALSE;
+        }
+    }
 
-	/* If we haven't moved this card recently, assume this isn't
-	a redundant move. */
+    /* If we haven't moved this card recently, assume this isn't
+    a redundant move. */
 
-	if (j < 0) {
-		return FALSE;
-	}
+    if (j < 0) {
+        return FALSE;
+    }
 
-	/* If the number of empty soft_thread->T cells ever goes to zero, from prev[0] to
-	prev[j-1], there may be a dependency.  We also want to know if there
-	were any empty soft_thread->T cells on move prev[j]. */
+    /* If the number of empty soft_thread->T cells ever goes to zero, from prev[0] to
+    prev[j-1], there may be a dependency.  We also want to know if there
+    were any empty soft_thread->T cells on move prev[j]. */
 
-	zerot = 0;
-	pos = pos0;
-	for (i = 0; i < j; i++) {
-		zerot |= (pos->ntemp == soft_thread->Ntpiles);
-		pos = pos->parent;
-	}
+    zerot = 0;
+    pos = pos0;
+    for (i = 0; i < j; i++) {
+        zerot |= (pos->ntemp == soft_thread->Ntpiles);
+        pos = pos->parent;
+    }
 
-	/* Now, prev[j] (m) is a move involving the same card as the current
-	move.  See if the current move inverts that move.  There are several
-	cases. */
+    /* Now, prev[j] (m) is a move involving the same card as the current
+    move.  See if the current move inverts that move.  There are several
+    cases. */
 
-	/* soft_thread->T -> soft_thread->W, ..., soft_thread->W -> soft_thread->T */
+    /* soft_thread->T -> soft_thread->W, ..., soft_thread->W -> soft_thread->T */
 
-	if (m->fromtype == T_TYPE && m->totype == W_TYPE &&
-	    mp->fromtype == W_TYPE && mp->totype == T_TYPE) {
+    if (m->fromtype == T_TYPE && m->totype == W_TYPE &&
+        mp->fromtype == W_TYPE && mp->totype == T_TYPE) {
 
-		/* If the number of soft_thread->T cells goes to zero, we have a soft_thread->T
-		dependency, and we can't prune. */
+        /* If the number of soft_thread->T cells goes to zero, we have a soft_thread->T
+        dependency, and we can't prune. */
 
-		if (zerot) {
-			return FALSE;
-		}
+        if (zerot) {
+            return FALSE;
+        }
 
-		/* If any intervening move used this card as a destination,
-		we have a dependency and we can't prune. */
+        /* If any intervening move used this card as a destination,
+        we have a dependency and we can't prune. */
 
-		if (cardisdest(mp->card, prev, j)) {
-			return FALSE;
-		}
+        if (cardisdest(mp->card, prev, j)) {
+            return FALSE;
+        }
 
-		return TRUE;
-	}
+        return TRUE;
+    }
 
-	/* soft_thread->W -> soft_thread->T, ..., soft_thread->T -> soft_thread->W */
-	/* soft_thread->W -> soft_thread->W, ..., soft_thread->W -> soft_thread->W */
+    /* soft_thread->W -> soft_thread->T, ..., soft_thread->T -> soft_thread->W */
+    /* soft_thread->W -> soft_thread->W, ..., soft_thread->W -> soft_thread->W */
 
-	if ((m->fromtype == W_TYPE && m->totype == T_TYPE &&
-	     mp->fromtype == T_TYPE && mp->totype == W_TYPE) ||
-	    (m->fromtype == W_TYPE && m->totype == W_TYPE &&
-	     mp->fromtype == W_TYPE && mp->totype == W_TYPE)) {
+    if ((m->fromtype == W_TYPE && m->totype == T_TYPE &&
+         mp->fromtype == T_TYPE && mp->totype == W_TYPE) ||
+        (m->fromtype == W_TYPE && m->totype == W_TYPE &&
+         mp->fromtype == W_TYPE && mp->totype == W_TYPE)) {
 
-		/* If we're not putting the card back where we found it,
-		it's not an inverse. */
+        /* If we're not putting the card back where we found it,
+        it's not an inverse. */
 
-		if (m->srccard != mp->destcard) {
-			return FALSE;
-		}
+        if (m->srccard != mp->destcard) {
+            return FALSE;
+        }
 
-		/* If any of the intervening moves either moves the card
-		that was uncovered or uses it as a destination (including
-		NONE), there is a dependency. */
+        /* If any of the intervening moves either moves the card
+        that was uncovered or uses it as a destination (including
+        NONE), there is a dependency. */
 
-		if (cardmoved(mp->destcard, prev, j) ||
-		    cardisdest(mp->destcard, prev, j)) {
-			return FALSE;
-		}
+        if (cardmoved(mp->destcard, prev, j) ||
+            cardisdest(mp->destcard, prev, j)) {
+            return FALSE;
+        }
 
-		return TRUE;
-	}
+        return TRUE;
+    }
 
-	/* These are not inverse prunes, we're taking a shortcut. */
+    /* These are not inverse prunes, we're taking a shortcut. */
 
-	/* soft_thread->W -> soft_thread->W, ..., soft_thread->W -> soft_thread->T */
+    /* soft_thread->W -> soft_thread->W, ..., soft_thread->W -> soft_thread->T */
 
-	if (m->fromtype == W_TYPE && m->totype == W_TYPE &&
-	    mp->fromtype == W_TYPE && mp->totype == T_TYPE) {
+    if (m->fromtype == W_TYPE && m->totype == W_TYPE &&
+        mp->fromtype == W_TYPE && mp->totype == T_TYPE) {
 
-		/* If we could have moved the card to soft_thread->T on the
-		first move, prune.  There are other cases, but they
-		are more complicated. */
+        /* If we could have moved the card to soft_thread->T on the
+        first move, prune.  There are other cases, but they
+        are more complicated. */
 
-		if (pos->ntemp != soft_thread->Ntpiles && !zerot) {
-			return TRUE;
-		}
+        if (pos->ntemp != soft_thread->Ntpiles && !zerot) {
+            return TRUE;
+        }
 
-		return FALSE;
-	}
+        return FALSE;
+    }
 
-	/* soft_thread->T -> soft_thread->W, ..., soft_thread->W -> soft_thread->W */
+    /* soft_thread->T -> soft_thread->W, ..., soft_thread->W -> soft_thread->W */
 
-	if (m->fromtype == T_TYPE && m->totype == W_TYPE &&
-	    mp->fromtype == W_TYPE && mp->totype == W_TYPE) {
+    if (m->fromtype == T_TYPE && m->totype == W_TYPE &&
+        mp->fromtype == W_TYPE && mp->totype == W_TYPE) {
 
-		/* We can prune these moves as long as the intervening
-		moves don't touch mp->destcard. */
+        /* We can prune these moves as long as the intervening
+        moves don't touch mp->destcard. */
 
-		if (cardmoved(mp->destcard, prev, j) ||
-		    cardisdest(mp->destcard, prev, j)) {
-			return FALSE;
-		}
+        if (cardmoved(mp->destcard, prev, j) ||
+            cardisdest(mp->destcard, prev, j)) {
+            return FALSE;
+        }
 
-		return TRUE;
-	}
+        return TRUE;
+    }
 
-	return FALSE;
+    return FALSE;
 }
 
 /* Move prioritization.  Given legal, pruned moves, there are still some
 
 static void prioritize(fc_solve_soft_thread_t * soft_thread, MOVE *mp0, int n)
 {
-	int i, j, s, w, pile[NNEED], npile;
-	card_t card, need[4];
-	MOVE *mp;
+    int i, j, s, w, pile[NNEED], npile;
+    card_t card, need[4];
+    MOVE *mp;
 
-	/* There are 4 cards that we "need": the next cards to go out.  We
-	give higher priority to the moves that remove cards from the piles
-	containing these cards. */
+    /* There are 4 cards that we "need": the next cards to go out.  We
+    give higher priority to the moves that remove cards from the piles
+    containing these cards. */
 
-	for (i = 0; i < NNEED; i++) {
-		pile[i] = -1;
-	}
-	npile = 0;
+    for (i = 0; i < NNEED; i++) {
+        pile[i] = -1;
+    }
+    npile = 0;
 
-	for (s = 0; s < 4; s++) {
-		need[s] = NONE;
-		if (soft_thread->O[s] == NONE) {
-			need[s] = Osuit[s] + PS_ACE;
-		} else if (soft_thread->O[s] != PS_KING) {
-			need[s] = Osuit[s] + soft_thread->O[s] + 1;
-		}
-	}
+    for (s = 0; s < 4; s++) {
+        need[s] = NONE;
+        if (soft_thread->O[s] == NONE) {
+            need[s] = Osuit[s] + PS_ACE;
+        } else if (soft_thread->O[s] != PS_KING) {
+            need[s] = Osuit[s] + soft_thread->O[s] + 1;
+        }
+    }
 
-	/* Locate the needed cards.  There's room for optimization here,
-	like maybe an array that keeps track of every card; if maintaining
-	such an array is not too expensive. */
+    /* Locate the needed cards.  There's room for optimization here,
+    like maybe an array that keeps track of every card; if maintaining
+    such an array is not too expensive. */
 
-	for (w = 0; w < soft_thread->Nwpiles; w++) {
-		j = soft_thread->Wlen[w];
-		for (i = 0; i < j; i++) {
-			card = soft_thread->W[w][i];
-			s = suit(card);
+    for (w = 0; w < soft_thread->Nwpiles; w++) {
+        j = soft_thread->Wlen[w];
+        for (i = 0; i < j; i++) {
+            card = soft_thread->W[w][i];
+            s = suit(card);
 
-			/* Save the locations of the piles containing
-			not only the card we need next, but the card
-			after that as well. */
+            /* Save the locations of the piles containing
+            not only the card we need next, but the card
+            after that as well. */
 
-			if (need[s] != NONE &&
-			    (card == need[s] || card == need[s] + 1)) {
-				pile[npile++] = w;
-				if (npile == NNEED) {
-					break;
-				}
-			}
-		}
-		if (npile == NNEED) {
-			break;
-		}
-	}
+            if (need[s] != NONE &&
+                (card == need[s] || card == need[s] + 1)) {
+                pile[npile++] = w;
+                if (npile == NNEED) {
+                    break;
+                }
+            }
+        }
+        if (npile == NNEED) {
+            break;
+        }
+    }
 
-	/* Now if any of the moves remove a card from any of the piles
-	listed in pile[], bump their priority.  Likewise, if a move
-	covers a card we need, decrease its priority.  These priority
-	increments and decrements were determined empirically. */
+    /* Now if any of the moves remove a card from any of the piles
+    listed in pile[], bump their priority.  Likewise, if a move
+    covers a card we need, decrease its priority.  These priority
+    increments and decrements were determined empirically. */
 
-	for (i = 0, mp = mp0; i < n; i++, mp++) {
-		if (mp->card != NONE) {
-			if (mp->fromtype == W_TYPE) {
-				w = mp->from;
-				for (j = 0; j < npile; j++) {
-					if (w == pile[j]) {
-						mp->pri += soft_thread->Xparam[0];
-					}
-				}
-				if (soft_thread->Wlen[w] > 1) {
-					card = soft_thread->W[w][soft_thread->Wlen[w] - 2];
-					for (s = 0; s < 4; s++) {
-						if (card == need[s]) {
-							mp->pri += soft_thread->Xparam[1];
-							break;
-						}
-					}
-				}
-			}
-			if (mp->totype == W_TYPE) {
-				for (j = 0; j < npile; j++) {
-					if (mp->to == pile[j]) {
-						mp->pri -= soft_thread->Xparam[2];
-					}
-				}
-			}
-		}
-	}
+    for (i = 0, mp = mp0; i < n; i++, mp++) {
+        if (mp->card != NONE) {
+            if (mp->fromtype == W_TYPE) {
+                w = mp->from;
+                for (j = 0; j < npile; j++) {
+                    if (w == pile[j]) {
+                        mp->pri += soft_thread->Xparam[0];
+                    }
+                }
+                if (soft_thread->Wlen[w] > 1) {
+                    card = soft_thread->W[w][soft_thread->Wlen[w] - 2];
+                    for (s = 0; s < 4; s++) {
+                        if (card == need[s]) {
+                            mp->pri += soft_thread->Xparam[1];
+                            break;
+                        }
+                    }
+                }
+            }
+            if (mp->totype == W_TYPE) {
+                for (j = 0; j < npile; j++) {
+                    if (mp->to == pile[j]) {
+                        mp->pri -= soft_thread->Xparam[2];
+                    }
+                }
+            }
+        }
+    }
 }
 
 /* Generate an array of the moves we can make from this position. */
 
 MOVE *get_moves(fc_solve_soft_thread_t * soft_thread, POSITION *pos, int *nmoves)
 {
-	int i, n, alln, o, a, numout;
-	MOVE *mp, *mp0;
+    int i, n, alln, o, a, numout;
+    MOVE *mp, *mp0;
 
-	/* Fill in the soft_thread->Possible array. */
+    /* Fill in the soft_thread->Possible array. */
 
-	alln = n = get_possible_moves(soft_thread, &a, &numout);
+    alln = n = get_possible_moves(soft_thread, &a, &numout);
 
-	if (!a) {
+    if (!a) {
 
-		/* Throw out some obviously bad (non-auto)moves. */
+        /* Throw out some obviously bad (non-auto)moves. */
 
-		for (i = 0, mp = soft_thread->Possible; i < alln; i++, mp++) {
+        for (i = 0, mp = soft_thread->Possible; i < alln; i++, mp++) {
 
-			/* Special prune for Seahaven -k. */
+            /* Special prune for Seahaven -k. */
 
-			if (prune_seahaven(soft_thread, mp)) {
-				mp->card = NONE;
-				n--;
-				continue;
-			}
+            if (prune_seahaven(soft_thread, mp)) {
+                mp->card = NONE;
+                n--;
+                continue;
+            }
 
-			/* Prune redundant moves. */
+            /* Prune redundant moves. */
 
-			if (prune_redundant(soft_thread, mp, pos)) {
-				mp->card = NONE;
-				n--;
-			}
-		}
+            if (prune_redundant(soft_thread, mp, pos)) {
+                mp->card = NONE;
+                n--;
+            }
+        }
 
-		/* Mark any irreversible moves. */
+        /* Mark any irreversible moves. */
 
-		mark_irreversible(soft_thread, n);
-	}
+        mark_irreversible(soft_thread, n);
+    }
 
-	/* No moves?  Maybe we won. */
+    /* No moves?  Maybe we won. */
 
-	if (n == 0) {
-		for (o = 0; o < 4; o++) {
-			if (soft_thread->O[o] != PS_KING) {
-				break;
-			}
-		}
+    if (n == 0) {
+        for (o = 0; o < 4; o++) {
+            if (soft_thread->O[o] != PS_KING) {
+                break;
+            }
+        }
 
-		if (o == 4) {
+        if (o == 4) {
 
-			/* Report the win. */
+            /* Report the win. */
 
-			win(soft_thread, pos);
+            win(soft_thread, pos);
 
-			if (soft_thread->Noexit) {
-				soft_thread->num_solutions++;
-				return NULL;
-			}
-			soft_thread->Status = WIN;
+            if (soft_thread->Noexit) {
+                soft_thread->num_solutions++;
+                return NULL;
+            }
+            soft_thread->Status = WIN;
 
-			if (soft_thread->Interactive) {
-				exit(0);
-			}
+            if (soft_thread->Interactive) {
+                exit(0);
+            }
 
-			return NULL;
-		}
+            return NULL;
+        }
 
-		/* We lost. */
+        /* We lost. */
 
-		return NULL;
-	}
+        return NULL;
+    }
 
-	/* Prioritize these moves.  Automoves don't get queued, so they
-	don't need a priority. */
+    /* Prioritize these moves.  Automoves don't get queued, so they
+    don't need a priority. */
 
-	if (!a) {
-		prioritize(soft_thread, soft_thread->Possible, alln);
-	}
+    if (!a) {
+        prioritize(soft_thread, soft_thread->Possible, alln);
+    }
 
-	/* Now copy to safe storage and return.  Non-auto moves out get put
-	at the end.  Queueing them isn't a good idea because they are still
-	good moves, even if they didn't pass the automove test.  So we still
-	do the recursive solve() on them, but only after queueing the other
-	moves. */
+    /* Now copy to safe storage and return.  Non-auto moves out get put
+    at the end.  Queueing them isn't a good idea because they are still
+    good moves, even if they didn't pass the automove test.  So we still
+    do the recursive solve() on them, but only after queueing the other
+    moves. */
 
-	mp = mp0 = new_array(soft_thread, MOVE, n);
-	if (mp == NULL) {
-		return NULL;
-	}
-	*nmoves = n;
-	i = 0;
-	if (a || numout == 0) {
-		for (i = 0; i < alln; i++) {
-			if (soft_thread->Possible[i].card != NONE) {
-				*mp = soft_thread->Possible[i];      /* struct copy */
-				mp++;
-			}
-		}
-	} else {
-		for (i = numout; i < alln; i++) {
-			if (soft_thread->Possible[i].card != NONE) {
-				*mp = soft_thread->Possible[i];      /* struct copy */
-				mp++;
-			}
-		}
-		for (i = 0; i < numout; i++) {
-			if (soft_thread->Possible[i].card != NONE) {
-				*mp = soft_thread->Possible[i];      /* struct copy */
-				mp++;
-			}
-		}
-	}
+    mp = mp0 = new_array(soft_thread, MOVE, n);
+    if (mp == NULL) {
+        return NULL;
+    }
+    *nmoves = n;
+    i = 0;
+    if (a || numout == 0) {
+        for (i = 0; i < alln; i++) {
+            if (soft_thread->Possible[i].card != NONE) {
+                *mp = soft_thread->Possible[i];      /* struct copy */
+                mp++;
+            }
+        }
+    } else {
+        for (i = numout; i < alln; i++) {
+            if (soft_thread->Possible[i].card != NONE) {
+                *mp = soft_thread->Possible[i];      /* struct copy */
+                mp++;
+            }
+        }
+        for (i = 0; i < numout; i++) {
+            if (soft_thread->Possible[i].card != NONE) {
+                *mp = soft_thread->Possible[i];      /* struct copy */
+                mp++;
+            }
+        }
+    }
 
-	return mp0;
+    return mp0;
 }
 
 /* Automove logic.  Freecell games must avoid certain types of automoves. */
 
 static GCC_INLINE int good_automove(fc_solve_soft_thread_t * soft_thread, int o, int r)
 {
-	int i;
+    int i;
 
-	if (soft_thread->Same_suit || r <= 2) {
-		return TRUE;
-	}
+    if (soft_thread->Same_suit || r <= 2) {
+        return TRUE;
+    }
 
-	/* Check the Out piles of opposite color. */
+    /* Check the Out piles of opposite color. */
 
-	for (i = 1 - (o & 1); i < 4; i += 2) {
-		if (soft_thread->O[i] < r - 1) {
+    for (i = 1 - (o & 1); i < 4; i += 2) {
+        if (soft_thread->O[i] < r - 1) {
 
 #if 1   /* Raymond's Rule */
-			/* Not all the N-1's of opposite color are out
-			yet.  We can still make an automove if either
-			both N-2's are out or the other same color N-3
-			is out (Raymond's rule).  Note the re-use of
-			the loop variable i.  We return here and never
-			make it back to the outer loop. */
+            /* Not all the N-1's of opposite color are out
+            yet.  We can still make an automove if either
+            both N-2's are out or the other same color N-3
+            is out (Raymond's rule).  Note the re-use of
+            the loop variable i.  We return here and never
+            make it back to the outer loop. */
 
-			for (i = 1 - (o & 1); i < 4; i += 2) {
-				if (soft_thread->O[i] < r - 2) {
-					return FALSE;
-				}
-			}
-			if (soft_thread->O[(o + 2) & 3] < r - 3) {
-				return FALSE;
-			}
+            for (i = 1 - (o & 1); i < 4; i += 2) {
+                if (soft_thread->O[i] < r - 2) {
+                    return FALSE;
+                }
+            }
+            if (soft_thread->O[(o + 2) & 3] < r - 3) {
+                return FALSE;
+            }
 
-			return TRUE;
+            return TRUE;
 #else   /* Horne's Rule */
-			return FALSE;
+            return FALSE;
 #endif
-		}
-	}
+        }
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 /* Get the possible moves from a position, and store them in soft_thread->Possible[]. */
 
 static int get_possible_moves(fc_solve_soft_thread_t * soft_thread, int *a, int *numout)
 {
-	int i, n, t, w, o, empty, emptyw;
-	card_t card;
-	MOVE *mp;
+    int i, n, t, w, o, empty, emptyw;
+    card_t card;
+    MOVE *mp;
 
-	/* Check for moves from soft_thread->W to soft_thread->O. */
+    /* Check for moves from soft_thread->W to soft_thread->O. */
 
-	n = 0;
-	mp = soft_thread->Possible;
-	for (w = 0; w < soft_thread->Nwpiles; w++) {
-		if (soft_thread->Wlen[w] > 0) {
-			card = *soft_thread->Wp[w];
-			o = suit(card);
-			empty = (soft_thread->O[o] == NONE);
-			if ((empty && (rank(card) == PS_ACE)) ||
-			    (!empty && (rank(card) == soft_thread->O[o] + 1))) {
-				mp->card = card;
-				mp->from = w;
-				mp->fromtype = W_TYPE;
-				mp->to = o;
-				mp->totype = O_TYPE;
-				mp->srccard = NONE;
-				if (soft_thread->Wlen[w] > 1) {
-					mp->srccard = soft_thread->Wp[w][-1];
-				}
-				mp->destcard = NONE;
-				mp->pri = 0;    /* unused */
-				n++;
-				mp++;
+    n = 0;
+    mp = soft_thread->Possible;
+    for (w = 0; w < soft_thread->Nwpiles; w++) {
+        if (soft_thread->Wlen[w] > 0) {
+            card = *soft_thread->Wp[w];
+            o = suit(card);
+            empty = (soft_thread->O[o] == NONE);
+            if ((empty && (rank(card) == PS_ACE)) ||
+                (!empty && (rank(card) == soft_thread->O[o] + 1))) {
+                mp->card = card;
+                mp->from = w;
+                mp->fromtype = W_TYPE;
+                mp->to = o;
+                mp->totype = O_TYPE;
+                mp->srccard = NONE;
+                if (soft_thread->Wlen[w] > 1) {
+                    mp->srccard = soft_thread->Wp[w][-1];
+                }
+                mp->destcard = NONE;
+                mp->pri = 0;    /* unused */
+                n++;
+                mp++;
 
-				/* If it's an automove, just do it. */
+                /* If it's an automove, just do it. */
 
-				if (good_automove(soft_thread, o, rank(card))) {
-					*a = TRUE;
-					if (n != 1) {
-						soft_thread->Possible[0] = mp[-1];
-						return 1;
-					}
-					return n;
-				}
-			}
-		}
-	}
+                if (good_automove(soft_thread, o, rank(card))) {
+                    *a = TRUE;
+                    if (n != 1) {
+                        soft_thread->Possible[0] = mp[-1];
+                        return 1;
+                    }
+                    return n;
+                }
+            }
+        }
+    }
 
-	/* Check for moves from soft_thread->T to soft_thread->O. */
+    /* Check for moves from soft_thread->T to soft_thread->O. */
 
-	for (t = 0; t < soft_thread->Ntpiles; t++) {
-		if (soft_thread->T[t] != NONE) {
-			card = soft_thread->T[t];
-			o = suit(card);
-			empty = (soft_thread->O[o] == NONE);
-			if ((empty && (rank(card) == PS_ACE)) ||
-			    (!empty && (rank(card) == soft_thread->O[o] + 1))) {
-				mp->card = card;
-				mp->from = t;
-				mp->fromtype = T_TYPE;
-				mp->to = o;
-				mp->totype = O_TYPE;
-				mp->srccard = NONE;
-				mp->destcard = NONE;
-				mp->pri = 0;    /* unused */
-				n++;
-				mp++;
+    for (t = 0; t < soft_thread->Ntpiles; t++) {
+        if (soft_thread->T[t] != NONE) {
+            card = soft_thread->T[t];
+            o = suit(card);
+            empty = (soft_thread->O[o] == NONE);
+            if ((empty && (rank(card) == PS_ACE)) ||
+                (!empty && (rank(card) == soft_thread->O[o] + 1))) {
+                mp->card = card;
+                mp->from = t;
+                mp->fromtype = T_TYPE;
+                mp->to = o;
+                mp->totype = O_TYPE;
+                mp->srccard = NONE;
+                mp->destcard = NONE;
+                mp->pri = 0;    /* unused */
+                n++;
+                mp++;
 
-				/* If it's an automove, just do it. */
+                /* If it's an automove, just do it. */
 
-				if (good_automove(soft_thread, o, rank(card))) {
-					*a = TRUE;
-					if (n != 1) {
-						soft_thread->Possible[0] = mp[-1];
-						return 1;
-					}
-					return n;
-				}
-			}
-		}
-	}
+                if (good_automove(soft_thread, o, rank(card))) {
+                    *a = TRUE;
+                    if (n != 1) {
+                        soft_thread->Possible[0] = mp[-1];
+                        return 1;
+                    }
+                    return n;
+                }
+            }
+        }
+    }
 
-	/* No more automoves, but remember if there were any moves out. */
+    /* No more automoves, but remember if there were any moves out. */
 
-	*a = FALSE;
-	*numout = n;
+    *a = FALSE;
+    *numout = n;
 
-	/* Check for moves from non-singleton soft_thread->W cells to one of any
-	empty soft_thread->W cells. */
+    /* Check for moves from non-singleton soft_thread->W cells to one of any
+    empty soft_thread->W cells. */
 
-	emptyw = -1;
-	for (w = 0; w < soft_thread->Nwpiles; w++) {
-		if (soft_thread->Wlen[w] == 0) {
-			emptyw = w;
-			break;
-		}
-	}
-	if (emptyw >= 0) {
-		for (i = 0; i < soft_thread->Nwpiles; i++) {
-			if (i == emptyw) {
-				continue;
-			}
-			if (soft_thread->Wlen[i] > 1 && king_only(*soft_thread->Wp[i])) {
-				card = *soft_thread->Wp[i];
-				mp->card = card;
-				mp->from = i;
-				mp->fromtype = W_TYPE;
-				mp->to = emptyw;
-				mp->totype = W_TYPE;
-				mp->srccard = soft_thread->Wp[i][-1];
-				mp->destcard = NONE;
-				mp->pri = soft_thread->Xparam[3];
-				n++;
-				mp++;
-			}
-		}
-	}
+    emptyw = -1;
+    for (w = 0; w < soft_thread->Nwpiles; w++) {
+        if (soft_thread->Wlen[w] == 0) {
+            emptyw = w;
+            break;
+        }
+    }
+    if (emptyw >= 0) {
+        for (i = 0; i < soft_thread->Nwpiles; i++) {
+            if (i == emptyw) {
+                continue;
+            }
+            if (soft_thread->Wlen[i] > 1 && king_only(*soft_thread->Wp[i])) {
+                card = *soft_thread->Wp[i];
+                mp->card = card;
+                mp->from = i;
+                mp->fromtype = W_TYPE;
+                mp->to = emptyw;
+                mp->totype = W_TYPE;
+                mp->srccard = soft_thread->Wp[i][-1];
+                mp->destcard = NONE;
+                mp->pri = soft_thread->Xparam[3];
+                n++;
+                mp++;
+            }
+        }
+    }
 
-	/* Check for moves from soft_thread->W to non-empty soft_thread->W cells. */
+    /* Check for moves from soft_thread->W to non-empty soft_thread->W cells. */
 
-	for (i = 0; i < soft_thread->Nwpiles; i++) {
-		if (soft_thread->Wlen[i] > 0) {
-			card = *soft_thread->Wp[i];
-			for (w = 0; w < soft_thread->Nwpiles; w++) {
-				if (i == w) {
-					continue;
-				}
-				if (soft_thread->Wlen[w] > 0 &&
-				    (rank(card) == rank(*soft_thread->Wp[w]) - 1 &&
-				     suitable(card, *soft_thread->Wp[w]))) {
-					mp->card = card;
-					mp->from = i;
-					mp->fromtype = W_TYPE;
-					mp->to = w;
-					mp->totype = W_TYPE;
-					mp->srccard = NONE;
-					if (soft_thread->Wlen[i] > 1) {
-						mp->srccard = soft_thread->Wp[i][-1];
-					}
-					mp->destcard = *soft_thread->Wp[w];
-					mp->pri = soft_thread->Xparam[4];
-					n++;
-					mp++;
-				}
-			}
-		}
-	}
+    for (i = 0; i < soft_thread->Nwpiles; i++) {
+        if (soft_thread->Wlen[i] > 0) {
+            card = *soft_thread->Wp[i];
+            for (w = 0; w < soft_thread->Nwpiles; w++) {
+                if (i == w) {
+                    continue;
+                }
+                if (soft_thread->Wlen[w] > 0 &&
+                    (rank(card) == rank(*soft_thread->Wp[w]) - 1 &&
+                     suitable(card, *soft_thread->Wp[w]))) {
+                    mp->card = card;