struct bitmap clippy;
struct bitmap clipeye;
struct bitmap clipupil;
struct bitmap clipbrowl;
struct bitmap clipbrowr;
struct bitmap cliparrw;
//unsigned char enable_clippy = 1;

void draw_clippy(unsigned x, unsigned y, signed char lookver, signed char lookhor)
{
  if(!setup.enable_clippy) return;

  push_scrbitmap(x, y, &clippy, 2);
  push_scrbitmap(x-4, y+25, &clipeye, 1);
  push_scrbitmap(x+22, y+27, &clipeye, 1);
  push_scrbitmap(x-2+lookhor, y+27+lookver, &clipupil, 0);
  push_scrbitmap(x+24+lookhor, y+29+lookver, &clipupil, 0);
  push_scrbitmap(x-6, y+18, &clipbrowl, 0);
  push_scrbitmap(x+22, y+20, &clipbrowr, 0);
}

struct move do_ai_move(struct coord king_pos, signed char *dontcommit);

struct move clippy_help_move(signed char *s)
{
  struct move move;
  struct coord king_pos = find_king(&board, game_status->turn);
  unsigned char oldblunders = setup.blunders;

  setup.depth1++;
  setup.depth2++;
  setup.blunders = 0;

  move = do_ai_move(king_pos, s);

  setup.blunders = oldblunders;
  setup.depth2--;
  setup.depth1--;

  return move;
}

void coord_to_str(struct coord coord, char *str);
void show_dialog_nokey(char *str);

void clippy_recommend_move(void)
{
  char str[50];
  signed char s;
  struct move move = clippy_help_move(&s);

  if(!move.staledraw && move.score < -CHECKMATE_SCORE/4)
  {
    strcpy(str, "I think you have lost this game.");
  }
  else
  {
    strcpy(str, "Try __-__.");
    coord_to_str(move.src, str+4);
    coord_to_str(move.dst, str+7);
  }
  show_dialog_nokey(str);
}

int clippy_accept_resign(void)
{
  signed char s;
  struct move move = clippy_help_move(&s);

  if(s > 2 && move.score < QUEEN_VALUE)
  {
    show_dialog_nokey("Resignation accepted.");
    return 1;
  }
  else
  {
    show_dialog_nokey("I think you can still win this.");
    return 0;
  }
}

int clippy_accept_draw(void)
{
  signed char s;
  struct move move = clippy_help_move(&s);

  if(turn_count > 20 && s <= 0 && move.score >= ROOK_VALUE)
  {
    show_dialog_nokey("Draw accepted.");
    return 1;
  }
  else
  {
    show_dialog_nokey("I think I can still win this.");
    return 0;
  }
}

int init_clippy(void)
{
  unsigned char width, height;
  int rc;

  rc = load_bitmap("clippy.spr", &clippy, &width, &height);
  rc |= load_bitmap("clipeye.spr", &clipeye, &width, &height);
  rc |= load_bitmap("clippupl.spr", &clipupil, &width, &height);
  rc |= load_bitmap("clipbrwl.spr", &clipbrowl, &width, &height);
  rc |= load_bitmap("clipbrwr.spr", &clipbrowr, &width, &height);
  rc |= load_bitmap("cliparrw.spr", &cliparrw, &width, &height);

  return rc;
}
