Language: C++

#include <iostream>
#define MAX 8

using namespace std;

struct Field{
	int base[MAX*2][MAX*2],*tmp[MAX*2],**val;
};

int	die[3][4]={{2,4,5,3},{1,3,6,4},{1,5,6,2}};
Field	rank,top;

void cvt(Field*);
void fall(int,int,int,int);
void rot(int []);

int main(void){
	int	n,t,f,nums[6];

	cvt(&rank);
	cvt(&top);

	do{
		cin >> n;

		if(n!=0){
			memset(rank.base,0,sizeof(rank.base));
			memset(top.base,0,sizeof(top.base));
			memset(nums,0,sizeof(nums));

			for(int i=0;i<n;i++){
				cin >> t >> f;
				fall(0,0,t,f);
			}

			for(int i=0;i<MAX*2;i++)
				for(int j=0;j<MAX*2;j++)
					if(top.base[i][j])
						nums[top.base[i][j]-1]++;

			for(int i=0;i<5;i++)
				cout << nums[i] << " ";
			cout << nums[5] << endl;
		}
	}while(n>0);
}

void cvt(Field *fld){
	for(int i=0;i<MAX*2;i++)
		(*fld).tmp[i]=&(*fld).base[i][MAX];
	(*fld).val=&(*fld).tmp[MAX];
}

void fall(int x,int y,int t,int f){
	int	sel,cur[5],nxt=4;
	bool	torb,dr[4];

	sel=(t<4?t:7-t)-1;
	torb=t<4;
	cur[4]=0;

	while(die[sel][torb?0:3]!=f)
		rot(die[sel]);
	for(int i=0;i<4;i++){
		cur[i]=die[sel][torb?i:3-i];
		dr[i]=cur[i]>3&&rank.val[x][y]>(i%2==0?rank.val[x][y+i-1]:rank.val[x+i-2][y]);
	}

	for(int i=0;i<4;i++)
		if(dr[i]&&cur[i]>cur[nxt])
			nxt=i;

	if(nxt==4){
		rank.val[x][y]++;
		top.val[x][y]=t;
	}
	else
		fall(nxt%2==0?x:x+nxt-2,nxt%2==0?y+nxt-1:y,7-cur[nxt],(nxt%2!=0?f:(nxt==0?t:7-t)));
}

void rot(int dice[]){
	int tmp=dice[0];
	for(int i=0;i<3;i++)
		dice[i]=dice[i+1];
	dice[3]=tmp;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:14: error: reference to 'rank' is ambiguous
   20 |         cvt(&rank);
      |              ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:9: note:                 'Field rank'
   11 | Field   rank,top;
      |         ^~~~
a.cc:27:32: error: reference to 'rank' is ambiguous
   27 |                         memset(rank.base,0,sizeof(rank.base));
      |                                ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:9: note:                 'Field rank'
   11 | Field   rank,top;
      |         ^~~~
a.cc:27:51: error: reference to 'rank' is ambiguous
   27 |                         memset(rank.base,0,sizeof(rank.base));
      |                                                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:9: note:                 'Field rank'
   11 | Field   rank,top;
      |         ^~~~
a.cc:27:25: error: 'memset' was not declared in this scope
   27 |                         memset(rank.base,0,sizeof(rank.base));
      |                         ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    1 | #include <iostream>
  +++ |+#include <cstring>
    2 | #define MAX 8
a.cc: In function 'void fall(int, int, int, int)':
a.cc:66:33: error: reference to 'rank' is ambiguous
   66 |                 dr[i]=cur[i]>3&&rank.val[x][y]>(i%2==0?rank.val[x][y+i-1]:rank.val[x+i-2][y]);
      |                                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:9: note:                 'Field rank'
   11 | Field   rank,top;
      |         ^~~~
a.cc:66:56: error: reference to 'rank' is ambiguous
   66 |                 dr[i]=cur[i]>3&&rank.val[x][y]>(i%2==0?rank.val[x][y+i-1]:rank.val[x+i-2][y]);
      |                                                        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:9: note:                 'Field rank'
   11 | Field   rank,top;
      |         ^~~~
a.cc:66:75: error: reference to 'rank' is ambiguous
   66 |                 dr[i]=cur[i]>3&&rank.val[x][y]>(i%2==0?rank.val[x][y+i-1]:rank.val[x+i-2][y]);
      |                                                                           ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:9: note:                 'Field rank'
   11 | Field   rank,top;
      |         ^~~~
a.cc:74:17: error: reference to 'rank' is ambiguous
   74 |                 rank.val[x][y]++;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:9: note:                 'Field rank'
   11 | Field   rank,top;
      |         ^~~~