snake.h
typedef struct snake
{
int headx;
int heady;
int headdir;
int snake_remainx[1000];
int snake_remainy[1000];
int length;
}SNAKEOBJ;
typedef struct food
{
int foodx;
int foody;
}FOODOBJ;
typedef struct board
{
int width=100;
int height=50;
SNAKEOBJ snake1;
SNAKEOBJ snake2;
FOODOBJ food;
}BOARDOBJ;
int get_move(BOARDOBJ *board);
player1
#include "snake.h"
int get_move(const BOARDOBJ *board)
{
int input;
/*Virtual declaration*/
int fx=board->food.foodx;
int fy=board->food.foody;
int hx=board->board->snake1.headx;
int hy=board->board->snake1.heady;
int dir=board->snake1.headdir;
/*moving possibilities*/
/*moving towards right direction if these are the possiblities*/
if((fx > hx)&&(fy < hy)&&(dir == LEFT))
input =0;
else
if((fx > hx)&&(fy < hy)&&(dir == UP))
input =0;
else
if((fx < hx)&&(fy < hy)&&(dir == RIGHT))
input =0;
else
if((fx < hx)&&(fy < hy)&&(dir == UP))
input =0;
else
if((fx > hx)&&(fy == hy)&&(dir == LEFT))
input =0;
else
if((fx == hx)&&(fy < hy)&&(dir == LEFT))
input =0;
else
if((fx == hx)&&(fy < hy)&&(dir == RIGHT))
input =0;
else
if((fx == hx)&&(fy < hy)&&(dir == UP))
input =0;
else
/*moving towards down direction if these are the possiblities*/
if((fx > hx)&&(fy > hy)&&(dir == LEFT))
input =1;
else
if((fx > hx)&&(fy > hy)&&(dir == DOWN))
input =1;
else
if((fx < hx)&&(fy > hy)&&(dir == RIGHT))
input =1;
else
if((fx < hx)&&(fy > hy)&&(dir == DOWN))
input =1;
else
if((fx == hx)&&(fy > hy)&&(dir == DOWN))
input =1;
else
if((fx == hx)&&(fy > hy)&&(dir == RIGHT))
input =1;
else
if((fx < hx)&&(fy == hy)&&(dir == RIGHT))
input =1;
else
if((fx == hx)&&(fy > hy)&&(dir == LEFT))
input =1;
else
/*moving towards left direction if these are the possiblities*/
if((fx < hx)&&(fy < hy)&&(dir == LEFT))
input =2;
else
if((fx < hx)&&(fy < hy)&&(dir == DOWN))
input =2;
else
if((fx == hx)&&(fy > hy)&&(dir == UP))
input =2;
else
if((fx < hx)&&(fy == hy)&&(dir == LEFT))
input =2;
else
if((fx < hx)&&(fy == hy)&&(dir == UP))
input =2;
else
if((fx < hx)&&(fy == hy)&&(dir == DOWN))
input =2;
else
if((fx < hx)&&(fy > hy)&&(dir == LEFT))
input =2;
else
if((fx < hx)&&(fy > hy)&&(dir == UP))
input =2;
else
/*moving towards right direction if these are the possiblities*/
if((fx > hx)&&(fy > hy)&&(dir == RIGHT))
input =3;
else
if((fx > hx)&&(fy > hy)&&(dir == UP))
input =3;
else
if((fx > hx)&&(fy < hy)&&(dir == RIGHT))
input =3;
else
if((fx > hx)&&(fy < hy)&&(dir == DOWN))
input =3;
else
if((fx > hx)&&(fy == hy)&&(dir == RIGHT))
input =3;
else
if((fx > hx)&&(fy == hy)&&(dir == UP))
input =3;
else
if((fx > hx)&&(fy == hy)&&(dir == DOWN))
input =3;
else
if((fx == hx)&&(fy < hy)&&dir == DOWN))
input =3;
else
input 4;
return input;
}
typedef struct snake
{
int headx;
int heady;
int headdir;
int snake_remainx[1000];
int snake_remainy[1000];
int length;
}SNAKEOBJ;
typedef struct food
{
int foodx;
int foody;
}FOODOBJ;
typedef struct board
{
int width=100;
int height=50;
SNAKEOBJ snake1;
SNAKEOBJ snake2;
FOODOBJ food;
}BOARDOBJ;
int get_move(BOARDOBJ *board);
player1
#include "snake.h"
int get_move(const BOARDOBJ *board)
{
int input;
/*Virtual declaration*/
int fx=board->food.foodx;
int fy=board->food.foody;
int hx=board->board->snake1.headx;
int hy=board->board->snake1.heady;
int dir=board->snake1.headdir;
/*moving possibilities*/
/*moving towards right direction if these are the possiblities*/
if((fx > hx)&&(fy < hy)&&(dir == LEFT))
input =0;
else
if((fx > hx)&&(fy < hy)&&(dir == UP))
input =0;
else
if((fx < hx)&&(fy < hy)&&(dir == RIGHT))
input =0;
else
if((fx < hx)&&(fy < hy)&&(dir == UP))
input =0;
else
if((fx > hx)&&(fy == hy)&&(dir == LEFT))
input =0;
else
if((fx == hx)&&(fy < hy)&&(dir == LEFT))
input =0;
else
if((fx == hx)&&(fy < hy)&&(dir == RIGHT))
input =0;
else
if((fx == hx)&&(fy < hy)&&(dir == UP))
input =0;
else
/*moving towards down direction if these are the possiblities*/
if((fx > hx)&&(fy > hy)&&(dir == LEFT))
input =1;
else
if((fx > hx)&&(fy > hy)&&(dir == DOWN))
input =1;
else
if((fx < hx)&&(fy > hy)&&(dir == RIGHT))
input =1;
else
if((fx < hx)&&(fy > hy)&&(dir == DOWN))
input =1;
else
if((fx == hx)&&(fy > hy)&&(dir == DOWN))
input =1;
else
if((fx == hx)&&(fy > hy)&&(dir == RIGHT))
input =1;
else
if((fx < hx)&&(fy == hy)&&(dir == RIGHT))
input =1;
else
if((fx == hx)&&(fy > hy)&&(dir == LEFT))
input =1;
else
/*moving towards left direction if these are the possiblities*/
if((fx < hx)&&(fy < hy)&&(dir == LEFT))
input =2;
else
if((fx < hx)&&(fy < hy)&&(dir == DOWN))
input =2;
else
if((fx == hx)&&(fy > hy)&&(dir == UP))
input =2;
else
if((fx < hx)&&(fy == hy)&&(dir == LEFT))
input =2;
else
if((fx < hx)&&(fy == hy)&&(dir == UP))
input =2;
else
if((fx < hx)&&(fy == hy)&&(dir == DOWN))
input =2;
else
if((fx < hx)&&(fy > hy)&&(dir == LEFT))
input =2;
else
if((fx < hx)&&(fy > hy)&&(dir == UP))
input =2;
else
/*moving towards right direction if these are the possiblities*/
if((fx > hx)&&(fy > hy)&&(dir == RIGHT))
input =3;
else
if((fx > hx)&&(fy > hy)&&(dir == UP))
input =3;
else
if((fx > hx)&&(fy < hy)&&(dir == RIGHT))
input =3;
else
if((fx > hx)&&(fy < hy)&&(dir == DOWN))
input =3;
else
if((fx > hx)&&(fy == hy)&&(dir == RIGHT))
input =3;
else
if((fx > hx)&&(fy == hy)&&(dir == UP))
input =3;
else
if((fx > hx)&&(fy == hy)&&(dir == DOWN))
input =3;
else
if((fx == hx)&&(fy < hy)&&dir == DOWN))
input =3;
else
input 4;
return input;
}