forked from Aisthetic/GoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic.c
More file actions
59 lines (52 loc) · 2.8 KB
/
Copy pathlogic.c
File metadata and controls
59 lines (52 loc) · 2.8 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "game.h"
#include "logic.h"
void addMember(Team *self, Token member){
self->Members[self->MembersCount] = member;
self->MembersCount++;
printf("Ajout du token(%d,%d,%c) à la team members count %d \n",member.X,member.Y,member.side,self->MembersCount);
}
Team ConstructTeam(){
Team team;
team.MembersCount=0;
team.Members = (Token*)(malloc(100*sizeof(Token)));
team.addMember = addMember;
return team;
}
int SlotInGrid(int x,int y){
//printf("checking if slot (%d,%d) is in grid",x,y);
if( ((x>=0)&&(x<=8)) && ((y>=0)&&(y<=8)) ){
//printf(" YES \n");
return 1; //yes
}
//printf(" no \n");
return 0; //no
}
int SlotFree(int x,int y){
return grid[y][x] == ' ' ? 1 : 0;
}
int sameTeam(Token token1,Token token2){
printf("same team check (%d,%d) vs (%d,%d) = %d \n",token1.X,token1.Y,token2.X,token2.Y,token1.side == token2.side?1:0);
return token1.side == token2.side?1:0;
}
Team surroundingAllies(Token* pToken){//petite team de surrounding allies
printf("Checking surrounding allies for (%d,%d) \n",pToken->X,pToken->Y);
Token token = *pToken;
Team allies = ConstructTeam();
if(SlotInGrid(token.X+1,token.Y)==1 && SlotFree(token.X+1,token.Y) != 1 && sameTeam(token,tGrid[token.X+1][token.Y])) allies.addMember(&allies,tGrid[token.X+1][token.Y]);
if(SlotInGrid(token.X,token.Y+1)==1 && SlotFree(token.X,token.Y+1) != 1 && sameTeam(token,tGrid[token.X][token.Y+1])) allies.addMember(&allies,tGrid[token.X][token.Y+1]);
if(SlotInGrid(token.X-1,token.Y)==1 && SlotFree(token.X-1,token.Y) != 1 && sameTeam(token,tGrid[token.X-1][token.Y])) allies.addMember(&allies,tGrid[token.X-1][token.Y]);
if(SlotInGrid(token.X,token.Y-1)==1 && SlotFree(token.X,token.Y-1) != 1 && sameTeam(token,tGrid[token.X][token.Y-1])) allies.addMember(&allies,tGrid[token.X][token.Y-1]);
return allies;
}
Team surroundingEnnemies(Token* pToken){//petite team de surrounding ennemies
Token token = *pToken;
Team allies = ConstructTeam();//allies==ennemies flemme de tout réecrire
if(SlotInGrid(token.X+1,token.Y)==1 && SlotFree(token.X+1,token.Y) != 1 && !sameTeam(token,tGrid[token.X+1][token.Y])) allies.addMember(&allies,tGrid[token.X+1][token.Y]);
if(SlotInGrid(token.X,token.Y+1)==1 && SlotFree(token.X,token.Y+1) != 1 && !sameTeam(token,tGrid[token.X][token.Y+1])) allies.addMember(&allies,tGrid[token.X][token.Y+1]);
if(SlotInGrid(token.X-1,token.Y)==1 && SlotFree(token.X-1,token.Y) != 1 && !sameTeam(token,tGrid[token.X-1][token.Y])) allies.addMember(&allies,tGrid[token.X-1][token.Y]);
if(SlotInGrid(token.X,token.Y-1)==1 && SlotFree(token.X,token.Y-1) != 1 && !sameTeam(token,tGrid[token.X][token.Y-1])) allies.addMember(&allies,tGrid[token.X][token.Y-1]);
return allies;
}