Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LIBS = -L $(LIBDIR)/lib
LDFLAGS = -lm -lcgs -lncurses -lpanel

# fichiers du projet
SRC = main.c gui.c mapping.c dumbMd.c manualMd.c
SRC = main.c gui.c mapping.c dumbMd.c manualMd.c randMd.c
OBJ = $(SRC:.c=.o)
EXEC = test

Expand All @@ -22,11 +22,12 @@ gui.o: gui.h struct.h mapping.h
mapping.o:gui.h struct.h mapping.h
mapping.o:gui.h struct.h dumbMd.h mapping.h
manualMd.o:gui.h struct.h manualMd.h mapping.h
randM.o:gui.h struct.h randMd.h mapping.h

# règles de compilation
%.o: %.c
$(CC) $(CCFLAGS) -o $@ -c $<

# règles d'édition de liens
$(EXEC): $(OBJ)
$(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
Expand Down
55 changes: 48 additions & 7 deletions mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ void getMap(Map *L)
{
case 0:
addStr(L->infoP1[0]," Aightech"," (DUMB)");
break;
case 1:
addStr(L->infoP1[0]," Aightech"," (MANUAL)");

break;
}

Expand All @@ -91,10 +89,7 @@ void getMap(Map *L)
case 0:
addStr(argMap,"DO_NOTHING"," timeout=10");
addStr(L->infoP2[0]," DO NOTHING"," (DUMB)");
break;
case 1:
addStr(argMap,"DO_NOTHING"," timeout=10");
addStr(L->infoP2[0]," DO NOTHING"," (DUMB)");

break;
}
/* wait for a game, and retrieve informations about it */
Expand Down Expand Up @@ -320,6 +315,52 @@ int moveP(Map *L, int P,t_move *move)
}


void MoveMap(Map *L,t_move move)
//apply changes generate by move to the current map L
{
int i;
char temp;
switch (move->type)
{
case ROTATE_LINE_LEFT;
temp=L->cases[move->value][0];
for (i=0;i<L->width-1;i++)
{
L->cases[move->value][i]=L->cases[move->value][i+1];
}
L->cases[move->value][width-1]=temp;
break;

case ROTATE_LINE_RIGHT;
temp=L->cases[move->value][width-1];
for (i=1;i<L->width;i++)
{
L->cases[move->value][width-i]=L->cases[move->value][width-1-i];
}
L->cases[move->value][0]=temp;
break;

case ROTATE_COLUMN_DOWN;
temp=L->cases[heigth-1][move->value];
for (i=1;i<L->heigth;i++)
{
L->cases[heigth-i][move->value]=L->cases[heigth-1-i][move->value];
}
L->cases[0][move->value]=temp;
break;

case ROTATE_COLUM_UP;
temp=L->cases[0][move->value];
for (i=0;i<L->heigth-1;i++)
{
L->cases[i][move->value]=L->cases[i+1][move->value];
}
L->cases[height-1][move->value]=temp;
break;
}
}


void addStr(char *target,char *add1,char *add2)
{
while(*add1)
Expand Down
23 changes: 17 additions & 6 deletions randMd.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ void gene_randmove(Map *L,t_move *move,Player *player)
// pointeur move, largeur et longueur du lab
// run until generate a possible move
{
inte type=0;
int type=0;
int t=-1;
srand(time(NULL));
while(t==-1)
{
type=rand()%9;
if (type==0 || type==1) //row line
{
convert_movetype(t,move);
move->value=rand()%L->width;
t=testMoveM(player,move);
}
else if (type==2 || type==3) //row column
{
convert_movetype(t,move);
move->value=rand()%L->height;
t=testMoveM(player,move);
}
Expand All @@ -34,6 +36,7 @@ void gene_randmove(Map *L,t_move *move,Player *player)
}

int testMoveM(Player *player,t_move *move,int type)
//return 0 if "move", which may be a rotation of the map, is possible for player and -1 otherwise
{
if (player->energy<5)
return -1;
Expand All @@ -45,6 +48,7 @@ int testMoveM(Player *player,t_move *move,int type)
}

void convert_movetype(int type, t_move *move)
//convert an int, for example generate by rand, to a t_move type
{
switch (type)
{
Expand Down Expand Up @@ -80,6 +84,7 @@ void convert_movetype(int type, t_move *move)


void MoveM(Map *L,t_move move)
//apply changes generate by move to the current map L
{
int i;
char temp;
Expand Down Expand Up @@ -124,6 +129,7 @@ void MoveM(Map *L,t_move move)
}

void randMode(Map *L)
//instructions of the random mode of the game
{
t_return_code ret = MOVE_OK; /* indicates the status of the previous move */
t_move* move=(t_move*) malloc(sizeof(t_move));
Expand All @@ -141,15 +147,20 @@ void randMode(Map *L)
{
ret = getMove( move);
moveP(L,1,move);
L->players[0]->turn=0; //*
L->players[1]->turn=1; //*
L->players[0]->energy++; //*

}
else
{
gene_randmove(L,move,L->players[1]);
if (move==ROTATE_LINE_UP || move==ROTATE_LINE_DOWN || move==ROTATE_COLUMN_LEFT || move==ROTATE_COLUM_RIGHT)
moveM(L,move);
else
moveP(L,2,move); //pas sûre du 2
ret = sendMove(move);
if (move->type==ROTATE_COLUMN_UP || move->type==ROTATE_COLUMN_DOWN || move->type==ROTATE_LINE_LEFT ||move->type==ROTATE_LINE_RIGHT)
moveM(L,move);
ret = sendMove(move);
L->players[1]->turn=0; //*
L->players[0]->turn=1; //*
L->players[1]->energy++; //*
}
//endwin();
//printLabyrinth();
Expand Down
14 changes: 14 additions & 0 deletions randMd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef MANUALMD_H
#define MANUALMD_H
#include "struct.h"
//#include "labyrinthAPI.h"

void gene_randmove(Map* L,t_move *move, Player *player);

int testMoveM(Player *player,t_move *move,int type);

void convert_movetype(int type, t_move *move);

void randMode(Map *L)

#endif