+/*
+ * FILE: init-common.c
+ *
+ * ----------------------------------------------------------------------
+ * Copyright (c) 1993, 1994, 1995 Matthias Mutz
+ * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
+ * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation
+ *
+ * GNU SHOGI is based on GNU CHESS
+ *
+ * Copyright (c) 1988, 1989, 1990 John Stanback
+ * Copyright (c) 1992 Free Software Foundation
+ *
+ * This file is part of GNU SHOGI.
+ *
+ * GNU Shogi is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNU Shogi; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
+ * ----------------------------------------------------------------------
+ *
+ */
#include "gnushogi.h"
#include "pattern.h"
white, white
};
+int
+AllocateTT(int size)
+{
+ int n = sizeof(struct hashentry)*(size + rehash);
+ static int oldSize;
+ int doit = true;
+
+ if(oldSize == size) return use_ttable;
+ oldSize = ttblsize = size;
+
+ if(ttable[0]) free(ttable[0]);
+ if(ttable[1]) free(ttable[1]);
+
+ while (doit && ttblsize > MINTTABLE)
+ {
+ ttable[0] = malloc(n); /* FIXME: cast to the correct type. */
+ ttable[1] = ttable[0] ? malloc(n) : NULL;
+
+ if (!ttable[0] || !ttable[1])
+ {
+ if (!ttable[0])
+ free(ttable[0]);
+
+ if (!ttable[1])
+ free(ttable[1]);
+
+ ttblsize = ttblsize >> 1;
+ n = sizeof(struct hashentry) * (ttblsize + rehash);
+ }
+ else
+ {
+ doit = false;
+ }
+ }
+
+ if (ttblsize <= MINTTABLE)
+ {
+ use_ttable = false;
+ }
+
+ if (use_ttable)
+ {
+ /* CHECKME: is the precedence here correct? */
+ /* ttbllimit = ttblsize << 1 - ttblsize >> 2; */
+ ttbllimit = (ttblsize << 1) - (ttblsize >> 2);
+ }
+ else
+ {
+ ttable[0] = ttable[1] = NULL;
+ }
+
+ return use_ttable;
+}
int
Initialize_data(void)
size_t n;
int i;
char buffer[60];
- int doit = true;
{
small_short x = -1;
if (rehash < 0)
rehash = MAXrehash;
- n = sizeof(struct hashentry)*(ttblsize + rehash);
-
- while (doit && ttblsize > MINTTABLE)
- {
- ttable[0] = malloc(n); /* FIXME: cast to the correct type. */
- ttable[1] = ttable[0] ? malloc(n) : NULL;
-
- if (!ttable[0] || !ttable[1])
- {
- if (!ttable[0])
- free(ttable[0]);
-
- if (!ttable[1])
- free(ttable[1]);
-
- ttblsize = ttblsize >> 1;
- n = sizeof(struct hashentry) * (ttblsize + rehash);
- }
- else
- {
- doit = false;
- }
- }
-
- if (ttblsize <= MINTTABLE)
- {
- use_ttable = false;
- }
-
- if (use_ttable)
- {
- /* CHECKME: is the precedence here correct? */
- /* ttbllimit = ttblsize << 1 - ttblsize >> 2; */
- ttbllimit = (ttblsize << 1) - (ttblsize >> 2);
- }
- else
+ if (!AllocateTT(ttblsize))
{
sprintf(buffer, "Cannot allocate %ld bytes for transposition table",
(long)(2 * n));
dsp->ShowMessage(buffer);
- ttable[0] = ttable[1] = NULL;
}
#endif /* ttblsz */