-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2048.c
35 lines (34 loc) · 909 Bytes
/
2048.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
int UpdatData(unsigned char *arr)
{
int i,m,next;
/* Try to find a NON-0 number for next block */
for(i = 0; i < 4; i++)
{
next =-1;
for(m = i+1; m < 4; m++)
{
if(0 != arr[m])
{ /* We find it */
next = m;
break;
}
}
/* If we find one */
if(-1 != next)
{ /* If the current one is 0 */
if(0 == arr[i])
{ /* Switch the number with next one */
arr[i] = arr[next];
arr[next] = 0;
i = i - 1;
}
/* If the current one and next one are the same */
else if(arr[i] == arr[next])
{ /* Meger the two number and clear the next one */
arr[i] = arr[i]*2;
arr[next] = 0;
}
}
}
return 0;
}