From 6cc7e46ebbfe7eedbffff09c3057ac13a0688265 Mon Sep 17 00:00:00 2001 From: BarbeBleue Date: Tue, 13 Dec 2016 14:25:35 +0100 Subject: [PATCH 1/3] updates add moveMap to mapping create randMd.h update randMd.c --- mapping.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- randMd.c | 21 ++++++++++++++++----- randMd.h | 14 ++++++++++++++ 3 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 randMd.h diff --git a/mapping.c b/mapping.c index 999913c..d9b5582 100644 --- a/mapping.c +++ b/mapping.c @@ -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; } @@ -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 */ @@ -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;iwidth-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;iwidth;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;iheigth;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;iheigth-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) diff --git a/randMd.c b/randMd.c index d62e469..1a5d461 100644 --- a/randMd.c +++ b/randMd.c @@ -18,11 +18,13 @@ void gene_randmove(Map *L,t_move *move,Player *player) 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); } @@ -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; @@ -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) { @@ -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; @@ -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)); @@ -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(); diff --git a/randMd.h b/randMd.h new file mode 100644 index 0000000..3110a51 --- /dev/null +++ b/randMd.h @@ -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 From 6703fe524280e16199fa2ab3fcd5df6ea61ed080 Mon Sep 17 00:00:00 2001 From: BarbeBleue Date: Tue, 13 Dec 2016 14:35:28 +0100 Subject: [PATCH 2/3] Update randMd.c correction --- randMd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/randMd.c b/randMd.c index 1a5d461..db548c9 100644 --- a/randMd.c +++ b/randMd.c @@ -10,7 +10,7 @@ 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) From 9c171ceabd529c43bc52dea59362aa4b57f709e9 Mon Sep 17 00:00:00 2001 From: BarbeBleue Date: Tue, 13 Dec 2016 14:39:33 +0100 Subject: [PATCH 3/3] update makefile add randMd --- makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/makefile b/makefile index f6f67eb..e424688 100644 --- a/makefile +++ b/makefile @@ -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 @@ -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)