forked from Aisthetic/GoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.c
More file actions
75 lines (70 loc) · 2.09 KB
/
score.c
File metadata and controls
75 lines (70 loc) · 2.09 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include "game.h"
#include "logic.h"
#include "score.h"
int computeScore(){
flaggedLen=0;
territoryLen=0;
for(int x=0;x<9;x++){
for(int y=0;y<9;y++){
//Formation du territoire associé
if(!isFlagged(x,y)) compute(x,y);
char territorySide = ' ';
//Détermination du side
printf("territory : ");
for (int i=0;i<territoryLen;i++){
int xx = territoryX[i];
int yy = territoryY[i];
printf("(%d,%d) ",xx,yy);
if(grid[yy][xx]!=' '){
if(territorySide == ' ') territorySide = tGrid[xx][yy].side;
else if(territorySide != tGrid[xx][yy].side) break;
}
}
printf("\nBoucle (%d,%d) , territoire de longueur %d , side %c \n",x,y,territoryLen,territorySide);
//Ajout du score
if(territorySide == 'A')
AScore += territoryLen;
if(territorySide == 'B')
BScore += territoryLen;
//Reset
territoryLen = 0;
}
}
printf("scores : A = %d,B = %d",AScore+ACapturedTokens,BScore+BCapturedTokens);
}
/*
Description : fonction qui retourne le territoire associé à un token
Params : coordinates (x,y)
Returns : array of tokens
*/
void compute(int x,int y){
printf("computing score for (%d,%d) \n",x,y);
if(!SlotInGrid(x,y) || isFlagged(x,y)) return;
//put a flag on the slot
flaggedX[flaggedLen] = x;
flaggedY[flaggedLen] = y;
flaggedLen++;
//add it to the territory
territoryX[territoryLen]=x;
territoryY[territoryLen]=y;
territoryLen++;
//if it's a border stop
if(grid[y][x]!=' ')
return;
compute(x-1,y);
compute(x+1,y);
compute(x,y-1);
compute(x,y+1);
}
/*
Description : check if a slot is already flagged
Params : coordinates (x,y)
Returns : bool yes or no
*/
int isFlagged(int x,int y){
for(int i = 0; i < flaggedLen ; i++){
if((flaggedX[i]==x)&&(flaggedY[i]==y)) return 1;
}
return 0;
}