// Copyright 1993-1995 by Jon Dart.  All Rights Reserved.

#include "stdafx.h"
#include "bookentr.h"

Pool Book_Entry::allocator;

Book_Entry::Book_Entry( hash_t hc, byte rec, byte mv_indx, 
   BOOL last )
  : my_hash_code(hc), recommend(rec + (last ? 0x80 : 0)),
  move_index(mv_indx), winloss(0)
{
}

void Book_Entry::init( hash_t hc, uint16 freq,byte rec, byte mv_indx, 
                       BOOL last)
{
  my_hash_code = hc;
  frequency = freq;
  recommend = rec;
  winloss = 0;
  if (last)
     recommend |= 0x80;
  move_index = mv_indx;
}

BOOL Book_Entry::is_equal ( const Hashable &c) const
{
   Book_Entry *b = (Book_Entry*)&c;
   return (my_hash_code == b->my_hash_code);
}

BOOL Book_Entry::is_last() const
{
   return (recommend & 0x80) != 0;
}

void Book_Entry::set_last(BOOL b)
{
   if (b)
      recommend |= 0x80;
   else
      recommend &= ~0x80;
}

unsigned Book_Entry::get_recommend() const
{
   return (unsigned)(recommend & 0x7f);
}

