/****************** NOTE ******************/

/* This file is for the eventuality of an IA
 * in the game in the future, but I dropped 
 * the project for now so it's useless.
 */



#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <SDL/SDL.h>
/* P.K. */
#include "macros.h"
#include "types.h"
#include "common.h"

#include "main.h"

#define MAXREC 5

#define inv_dir(a) (a)%2 ? (a)+1 : (a)-1

typedef struct {
  int dir[4];
  int bombe;
  int p1;
  int p2;
  int bitmask;
  int note; /* Cette action est-elle intéressante ? */
}GameLogic;

GameLogic IA[7];


int bombedir(int dir, int x, int y)
{
  int a=0;
  //x  while ( 0<=x && x<=16 && 0<=y && y<=15 && (a = libre(x, y, inv_dir(dir))) ) {
  while ( 0 <= x && x <= plan.nivewidth && 0 <= y && y <= plan.niveheight && (a = libre(x, y, inv_dir(dir))) ) {
    x += dx[dir];
    y += dy[dir];
  }
  if (a==-2) return 1;
  return 0; /* Si on sort du plateau 'a' reste sur "libre", c-ŕ-d 1, et on retourne 0 */
}


int notecase(int x, int y)
{
  int a=1;
  if (libre(x,y,TOUTESDIR)<=0)
    return -1;
  if (plan.element[x][y].type==BONUS) a+=5;
  if (plan.element[x][y].type==EVENEMENT) a+=2;
  return a;
}

GameLogic evalue(int n, int nrec, int x, int y)
{
  int i;
  GameLogic GLdir[4];
  GameLogic rt={{0,0,0,0}, 0, 0, 0, 0, 0};
  if (nrec<MAXREC)
    for (i=0; i<4; i++)
      {
	if (libre(x+dx[i], y+dy[i], i)>0) {
	  GLdir[i]=evalue(n, nrec+1, x+dx[i], y+dy[i]);
	  rt.dir[i]=GLdir[i].note; }
	  else rt.dir[i]=-1;
      }
  return rt;
}


int gamelogic_main(int n)
{
  int nIA=perso[n].joueurIA;
  int x=perso[n].pos.x, y=perso[n].pos.y;

  if (!perso[n].mv)
    evalue(n, 0, x, y);
  if (aleat(10)<1)
    IA[nIA].bombe+=10;

  return 0;
}
