1/* 2 Sjeng - a chess variants playing program 3 Copyright (C) 2000 Gian-Carlo Pascutto 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 File: ecache.c 20 Purpose: handling of the evaluation cache 21 22*/ 23 24#include "sjeng.h" 25#include "protos.h" 26#include "extvars.h" 27 28typedef struct 29{ 30uint32_t stored_hash; 31uint32_t hold_hash; 32int32_t score; 33} ECacheType; 34 35/*ECacheType ECache[ECACHESIZE];*/ 36ECacheType *ECache; 37 38uint32_t ECacheProbes; 39uint32_t ECacheHits; 40 41void storeECache(int32_t score) 42{ 43 int index; 44 45 index = hash % ECacheSize; 46 47 ECache[index].stored_hash = hash; 48 ECache[index].hold_hash = hold_hash; 49 ECache[index].score = score; 50} 51 52void checkECache(int32_t *score, int *in_cache) 53{ 54 int index; 55 56 ECacheProbes++; 57 58 index = hash % ECacheSize; 59 60 if(ECache[index].stored_hash == hash && 61 ECache[index].hold_hash == hold_hash) 62 63 { 64 ECacheHits++; 65 66 *in_cache = 1; 67 *score = ECache[index].score; 68 } 69} 70 71void reset_ecache(void) 72{ 73 memset(ECache, 0, sizeof(ECacheType)*ECacheSize); 74 return; 75} 76 77void alloc_ecache(void) 78{ 79 ECache = (ECacheType*)malloc(sizeof(ECacheType)*ECacheSize); 80 81 if (ECache == NULL) 82 { 83 printf("Out of memory allocating ECache.\n"); 84 exit(EXIT_FAILURE); 85 } 86 87 printf("Allocated %u eval cache entries, totalling %u bytes.\n", 88 (uint32_t)ECacheSize, (uint32_t)(sizeof(ECacheType)*ECacheSize)); 89 return; 90} 91 92void free_ecache(void) 93{ 94 free(ECache); 95 return; 96} 97