-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.c
68 lines (48 loc) · 1.47 KB
/
template.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// TEMPLATE
//
//
// Permet de jouer un seul tour (en ne faisant rien s'il commence ou en
// réceptionnant le coup de l'adversaire s'il ne commence pas)
// et termine le jeu.
// Ce programme vous sert de base pour construire votre propre programme
#include <stdio.h>
#include <stdlib.h>
#include "labyrinthAPI.h"
#include <unistd.h>
extern int debug; /* hack to enable debug messages */
int main()
{
char labName[50]; /* name of the labyrinth */
char* labData; /* data of the labyrinth */
t_return_code ret = MOVE_OK; /* indicates the status of the previous move */
t_move move; /* a move */
int player;
int sizeX,sizeY;
/* connection to the server */
connectToServer( "pc4023.polytech.upmc.fr", 1234, "prog_template");
/* wait for a game, and retrieve informations about it */
waitForLabyrinth( "DO_NOTHING timeout=10", labName, &sizeX, &sizeY);
labData = (char*) malloc( sizeX * sizeY );
player = getLabyrinth( labData);
/* display the labyrinth */
printLabyrinth();
if (player==1) /* The opponent plays */
{
ret = getMove( &move);
//playMove( &lab, move);
}
else
{
move.type = DO_NOTHING;
move.value = 0;
ret = sendMove(move);
}
if ((player ==1 && ret == MOVE_WIN) || (player==0 && ret == MOVE_LOSE))
printf("I lose the game\n");
/* we do not forget to free the allocated array */
free(labData);
/* end the connection, because we are polite */
closeConnection();
return EXIT_SUCCESS;
}