Shlomi Fish avatar Shlomi Fish committed 572e602

Convert more global variables to soft_thread.

Comments (0)

Files changed (8)

-/* Copyright (c) 2002 Tom Holroyd
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
 /* This file was generated by param.py.  Do not edit. */
 
 #include "param.h"
 
-XYparam_t XYparam[] = {
+const XYparam_t XYparam[] = {
  {{ 4, 1, 8, -1, 7, 11, 4, 2, 2, 1, 2, }, { 0.0032, 0.32, -3.0, }},
  {{ 3, 4, 7, -4, -2, 1, 0, -4, 4, -1, 1, }, { -0.0008, 0.14, -1.0, }},
  {{ 2, 4, 7, -2, -2, 1, 0, -5, 4, -1, 1, }, { -0.0024, 0.22, 0.0, }},
-/* Copyright (c) 2002 Tom Holroyd
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
 /* This file was generated by param.py.  Do not edit. */
 
+#ifndef PATSOLVE_PARAM_H
+#define PATSOLVE_PARAM_H
+
 #define NXPARAM 11
 #define NYPARAM 3
 
 	double y[NYPARAM];
 } XYparam_t;
 
-extern XYparam_t XYparam[];
+extern const XYparam_t XYparam[];
 
+#endif /* PATSOLVE_PARAM_H */
 #define FreecellSpeed 0
 #define FreecellBest 1
 #define FreecellBestA 2

patsolve/param.py

 #! /usr/bin/env python
 
 import sys, string
-from util import *
+# from util import *
 
-usage("""filename""")
+# usage("""filename""")
 
-optlist, args = parseargs("")
-
-for opt, arg in optlist:
-	pass
-
-if len(args) != 1:
-	printusage()
-	sys.exit(1)
-
-filename = args[0]
+filename = 'param.dat'
 
 c = open('param.c', 'w')
 h = open('param.h', 'w')
 
 h.write("""/* This file was generated by param.py.  Do not edit. */
 
+#ifndef PATSOLVE_PARAM_H
+#define PATSOLVE_PARAM_H
+
 #define NXPARAM %d
 #define NYPARAM %d
 
 	double y[NYPARAM];
 } XYparam_t;
 
-extern XYparam_t XYparam[];
+extern const XYparam_t XYparam[];
 
+#endif /* PATSOLVE_PARAM_H */
 """ % (NXPARAM, NYPARAM))
 
 c.write("""/* This file was generated by param.py.  Do not edit. */
 
 #include "param.h"
 
-XYparam_t XYparam[] = {
+const XYparam_t XYparam[] = {
 """)
 
 p = 0
 				w = mp->from;
 				for (j = 0; j < npile; j++) {
 					if (w == pile[j]) {
-						mp->pri += Xparam[0];
+						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 += Xparam[1];
+							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 -= Xparam[2];
+						mp->pri -= soft_thread->Xparam[2];
 					}
 				}
 			}
 				mp->totype = W_TYPE;
 				mp->srccard = soft_thread->Wp[i][-1];
 				mp->destcard = NONE;
-				mp->pri = Xparam[3];
+				mp->pri = soft_thread->Xparam[3];
 				n++;
 				mp++;
 			}
 						mp->srccard = soft_thread->Wp[i][-1];
 					}
 					mp->destcard = *soft_thread->Wp[w];
-					mp->pri = Xparam[4];
+					mp->pri = soft_thread->Xparam[4];
 					n++;
 					mp++;
 				}
 					mp->totype = W_TYPE;
 					mp->srccard = NONE;
 					mp->destcard = *soft_thread->Wp[w];
-					mp->pri = Xparam[5];
+					mp->pri = soft_thread->Xparam[5];
 					n++;
 					mp++;
 				}
 				mp->totype = W_TYPE;
 				mp->srccard = NONE;
 				mp->destcard = NONE;
-				mp->pri = Xparam[6];
+				mp->pri = soft_thread->Xparam[6];
 				n++;
 				mp++;
 			}
 					mp->srccard = soft_thread->Wp[w][-1];
 				}
 				mp->destcard = NONE;
-				mp->pri = Xparam[7];
+				mp->pri = soft_thread->Xparam[7];
 				n++;
 				mp++;
 			}
 			}
 		}
 		if (irr) {
-			mp->pri += Xparam[8];
+			mp->pri += soft_thread->Xparam[8];
 		}
 	}
 }
 	}
 	i = insert(soft_thread, &cluster, depth, &node);
 	if (i == NEW) {
-		Total_positions++;
+		soft_thread->Total_positions++;
 	} else if (i != FOUND_BETTER) {
 		return NULL;
 	}
 
 static INLINE int wcmp(fc_solve_soft_thread_t * soft_thread, int a, int b)
 {
-	if (Xparam[9] < 0) {
+	if (soft_thread->Xparam[9] < 0) {
 		return soft_thread->Wpilenum[b] - soft_thread->Wpilenum[a];       /* newer piles first */
 	} else {
 		return soft_thread->Wpilenum[a] - soft_thread->Wpilenum[b];       /* older piles first */
 #if 0
 static INLINE int wcmp(int a, int b)
 {
-	if (Xparam[9] < 0) {
+	if (soft_thread->Xparam[9] < 0) {
 		return soft_thread->Wlen[b] - soft_thread->Wlen[a];       /* longer piles first */
 	} else {
 		return soft_thread->Wlen[a] - soft_thread->Wlen[b];       /* shorter piles first */
 		printf("A winner.\n");
 		printf("%d moves.\n", nmoves);
 #if DEBUG
-		printf("%d positions generated.\n", Total_generated);
-		printf("%d unique positions.\n", Total_positions);
+		printf("%d positions generated.\n", soft_thread->Total_generated);
+		printf("%d unique positions.\n", soft_thread->Total_positions);
 		printf("Mem_remain = %ld\n", Mem_remain);
 #endif
 	}
 #include <sys/types.h>
 #include "config.h"
 #include "tree.h"
+#include "param.h"
 
 /* A card is represented as (suit << 4) + rank. */
 
 
 /* Statistics. */
 
-extern int Total_positions;
-extern int Total_generated;
 extern long Mem_remain;
 
-extern int Xparam[];
-extern double Yparam[];
-
 #define NQUEUES 100
 
 struct fc_solve_soft_thread_struct
 
     MOVE Possible[MAXMOVES];
 
+
+    /* Statistics. */
+
+    int Total_positions;
+    int Total_generated;
+
+    int Xparam[NXPARAM];
+    double Yparam[NYPARAM];
 };
 
 typedef struct fc_solve_soft_thread_struct fc_solve_soft_thread_t;

patsolve/patmain.c

 #include <signal.h>
 #include "pat.h"
 #include "tree.h"
-#include "param.h"
 
 char Usage[] =
   "usage: %s [-s|f] [-k|a] [-w<n>] [-t<n>] [-E] [-S] [-q|v] [layout]\n"
 #if DEBUG
 long Init_mem_remain;
 #endif
-
-/* Statistics. */
-
-int Total_positions;
-int Total_generated;
-
-int Xparam[NXPARAM];
-double Yparam[NYPARAM];
-
-void set_param(int pnum)
+void set_param(fc_solve_soft_thread_t * soft_thread, int pnum)
 {
-	int i, *x;
-	double *y;
+	const int *x;
+	const double *y;
+    int i;
 
 	x = XYparam[pnum].x;
 	y = XYparam[pnum].y;
 	for (i = 0; i < NXPARAM; i++) {
-		Xparam[i] = x[i];
+		soft_thread->Xparam[i] = x[i];
 	}
-	Cutoff = Xparam[NXPARAM - 1];
+	Cutoff = soft_thread->Xparam[NXPARAM - 1];
 	for (i = 0; i < NYPARAM; i++) {
-		Yparam[i] = y[i];
+		soft_thread->Yparam[i] = y[i];
 	}
 }
 
 	/* Set parameters. */
 
 	if (!soft_thread_struct.Same_suit && !soft_thread_struct.King_only && !Stack) {
-		set_param(FreecellBest);
+		set_param(soft_thread, FreecellBest);
 	} else if (!soft_thread_struct.Same_suit && !soft_thread_struct.King_only && Stack) {
-		set_param(FreecellSpeed);
+		set_param(soft_thread, FreecellSpeed);
 	} else if (soft_thread_struct.Same_suit && !soft_thread_struct.King_only && !Stack) {
-		set_param(SeahavenBest);
+		set_param(soft_thread, SeahavenBest);
 	} else if (soft_thread_struct.Same_suit && !soft_thread_struct.King_only && Stack) {
-		set_param(SeahavenSpeed);
+		set_param(soft_thread, SeahavenSpeed);
 	} else if (soft_thread_struct.Same_suit && soft_thread_struct.King_only && !Stack) {
-		set_param(SeahavenKing);
+		set_param(soft_thread, SeahavenKing);
 	} else if (soft_thread_struct.Same_suit && soft_thread_struct.King_only && Stack) {
-		set_param(SeahavenKingSpeed);
+		set_param(soft_thread, SeahavenKingSpeed);
 	} else {
-		set_param(0);   /* default */
+		set_param(soft_thread, 0);   /* default */
 	}
 
 	/* Now get the other args, and allow overriding the parameters. */
 				/* use -c for the last X param */
 
 				for (i = 0; i < NXPARAM - 1; i++) {
-					Xparam[i] = atoi(argv[i + 1]);
+					soft_thread->Xparam[i] = atoi(argv[i + 1]);
 				}
 				argv += NXPARAM - 1;
 				argc -= NXPARAM - 1;
 
 			case 'Y':
 				for (i = 0; i < NYPARAM; i++) {
-					Yparam[i] = atof(argv[i + 1]);
+					soft_thread->Yparam[i] = atof(argv[i + 1]);
 				}
 				argv += NYPARAM;
 				argc -= NYPARAM;
 				if (i < 0 || i > LastParam) {
 					fatalerr("invalid parameter code");
 				}
-				set_param(i);
+				set_param(soft_thread, i);
 				curr_arg = NULL;
 				break;
 
 
 	/* Reset stats. */
 
-	Total_positions = 0;
-	Total_generated = 0;
+	soft_thread->Total_positions = 0;
+	soft_thread->Total_generated = 0;
 	Numsol = 0;
 
 	Status = NOSOL;
 			printf("No solution.\n");
 		}
 #if DEBUG
-		printf("%d positions generated.\n", Total_generated);
-		printf("%d unique positions.\n", Total_positions);
+		printf("%d positions generated.\n", soft_thread->Total_generated);
+		printf("%d unique positions.\n", soft_thread->Total_positions);
 		printf("Mem_remain = %ld\n", Mem_remain);
 #endif
 	}

patsolve/patsolve.c

 
 	nout = soft_thread->O[0] + soft_thread->O[1] + soft_thread->O[2] + soft_thread->O[3];
 
-	/* Yparam[0] * nout^2 + Yparam[1] * nout + Yparam[2] */
+	/* soft_thread->Yparam[0] * nout^2 + soft_thread->Yparam[1] * nout + soft_thread->Yparam[2] */
 
-	x = (Yparam[0] * nout + Yparam[1]) * nout + Yparam[2];
+	x = (soft_thread->Yparam[0] * nout + soft_thread->Yparam[1]) * nout + soft_thread->Yparam[2];
 	pri += (int)floor(x + .5);
 
 	if (pri < 0) {
 	if (new == NULL) {
 		return ERR;
 	}
-	Total_generated++;
+	soft_thread->Total_generated++;
 
 	i = insert_node(new, d, &tl->tree, node);
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.