#include "c.h"

/**
 * These functions are available to use in your curses programs.
 */

/**
 * Returns a random integer between 'a' and 'b' (inclusive)
 */
int R(int a, int b)
{
  int diff = (a < b? b-a : a-b)+1;
  int min = a < b? a : b;
  return min + (rand()%diff);
}

/**
 * All the normal curses setup stuff
 */
void init_curses(void)
{
  setlocale(LC_ALL, "en_US.utf-8");
  initscr();
  noecho();
  cbreak();
  keypad(stdscr, TRUE);
  // Setup colors:
  start_color();
  for(int i=0;i<8;i++)
    for(int j=0;j<8;j++)
      init_pair(i*8+j, i, j);
  // Turn off the cursor:
  curs_set(0);
}

/**
 * Shuts curses down
 */
void leave_curses(void)
{
  curs_set(1);
  echo();
  nocbreak();
  endwin();
}
