#include <bits/stdc++.h>
using namespace std;
map<int, string> c1;
const int N = 8, M = 2, O = 4;
//↓请联系 @tanbozhi2024 或 @zhaomaguo2024(他不会system("color XX");) 来修改此值
string color = "f0";
long long a[10][10] = {{0}}, maxn = 0, P = 0, score = 0;
void init()
{
c1[0] = " ", c1[1] = "@_@", c1[2] = " CE", c1[4] = " JU", c1[8] = " RE", c1[16] = "TLE", c1[32] = "MLE";
c1[64] = "ILE", c1[128] = "OLE", c1[256] = "UKE", c1[512] = " WA", c1[1024] = " PC";
c1[2048] = " AC", c1[4096] = " PE", c1[8192] = "WIN", c1[16384] = ">.<", c1[32768] = "/.\\", c1[65536] = "luo", c1[131072] = " gu";
c1[-2] = " O2", c1[-4] = " O3", c1[-8] = " O4";
}
void init2()
{
c1[0] = " ", c1[1] = "@_@", c1[2] = "*.*", c1[4] = "^.^", c1[8] = "'.'", c1[16] = "+.+", c1[32] = "0.0";
c1[64] = "U.U", c1[128] = "I.I", c1[256] = "o.-", c1[512] = "-.-", c1[1024] = "8.8";
c1[2048] = "$.$", c1[4096] = "~.~", c1[8192] = "WIN", c1[16384] = ">.<", c1[32768] = "!v!", c1[65536] = "yan", c1[131072] = " wz";
c1[-2] = "`_`", c1[-4] = "=_=", c1[-8] = ":_:";
}
void init3()
{
c1[0] = " ", c1[1] = "TAB", c1[2] = "ESC", c1[4] = "SHI", c1[8] = "CAP", c1[16] = "PTS", c1[32] = "PGU";
c1[64] = "PGD", c1[128] = "BKS", c1[256] = "DEL", c1[512] = "ENT", c1[1024] = "ALT";
c1[2048] = "LOD", c1[4096] = "QUI", c1[8192] = "LI+", c1[16384] = "LI-", c1[32768] = "W11", c1[65536] = "WIN", c1[131072] = "Fj ";
c1[-2] = " F1", c1[-4] = " F2", c1[-8] = " F3";
}
void init4()
{
c1[0] = " ", c1[1] = " R1", c1[2] = " R2", c1[4] = " R3", c1[8] = " R4", c1[16] = " R5", c1[32] = "SR1";
c1[64] = "SR2", c1[128] = "SR3", c1[256] = "SR4", c1[512] = "SR5", c1[1024] = "S21";
c1[2048] = "S22", c1[4096] = "S23", c1[8192] = "S24", c1[16384] = "S25", c1[32768] = "TR1", c1[65536] = "TR2", c1[131072] = "TR3";
c1[-2] = "JKL", c1[-4] = "SHL", c1[-8] = "HLL";
}
void left(int i, int j, int step){
if (a[i][j - 1] == 0 && j != 1){
swap(a[i][j - 1], a[i][j]);
left(i, j - 1, step+1);
} else if (a[i][j - 1] == a[i][j]){
a[i][j - 1] *= 2, a[i][j] = 0;
score += a[i][j-1];
maxn = max(maxn, a[i][j - 1]);
}else if(a[i][j] < 0 && step == 1 || a[i][j-1] < 0) {
a[i][j-1] = max(a[i][j], a[i][j-1]) * (0 - min(a[i][j], a[i][j-1]));
a[i][j] = 0;
maxn = max(maxn, a[i][j - 1]);
}
return ;
}
void right(int i, int j, int step){
if (a[i][j + 1] == 0 && j != N){
swap(a[i][j + 1], a[i][j]);
right(i, j + 1, step+1);
} else if (a[i][j + 1] == a[i][j]){
a[i][j + 1] *= 2, a[i][j] = 0;
maxn = max(maxn, a[i][j + 1]);
score += a[i][j+1];
}else if(a[i][j] < 0 && step == 1 || a[i][j+1] < 0) {
a[i][j+1] = max(a[i][j], a[i][j+1]) * (0 - min(a[i][j], a[i][j+1]));
a[i][j] = 0;
score += a[i][j+1];
}
return ;
}
void up(int i, int j, int step){
if (a[i - 1][j] == 0 && i != 1){
swap(a[i - 1][j], a[i][j]);
up(i - 1, j, step+1);
} else if (a[i - 1][j] == a[i][j]){
a[i - 1][j] *= 2, a[i][j] = 0;
maxn = max(maxn, a[i - 1][j]);
score += a[i-1][j];
}else if(a[i][j] < 0 && step == 1 || a[i-1][j] < 0) {
a[i-1][j] = max(a[i][j], a[i-1][j]) * (0 - min(a[i][j], a[i-1][j]));
a[i][j] = 0;
maxn = max(maxn, a[i - 1][j]);
}
return ;
}
void down(int i, int j, int step){
if (a[i + 1][j] == 0 && i != N){
swap(a[i + 1][j], a[i][j]);
down(i + 1, j, step+1);
} else if (a[i + 1][j] == a[i][j]){
a[i + 1][j] *= 2, a[i][j] = 0;
maxn = max(maxn, a[i + 1][j]);
score += a[i+1][j];
}else if(a[i][j] < 0 && step == 1 || a[i+1][j] < 0) {
a[i+1][j] = max(a[i][j], a[i+1][j]) * (0 - min(a[i][j], a[i+1][j]));
a[i][j] = 0;
score += a[i+1][j];
}
return ;
}
void wow(){
int o;
if (P) o = 3;
else o = O;
for (int i = 1; i <= N * (o + 1) + 1; i ++)
cout << "-";
cout << endl;
return ;
}
// mozu1 suoha
void sheng(){
srand(time(0));
int ni, nj, ncnt = 0;
do {
ni = rand() % N + 1;
nj = rand() % N + 1;
ncnt ++;
} while (a[ni][nj] != 0 && ncnt < 512);
if (ncnt >= 512) return ;
a[ni][nj] = M;
}
void suoha1(){
srand(time(0));
int ni, nj, ncnt = 0;
do {
ni = rand() % N + 1;
nj = rand() % N + 1;
ncnt ++;
} while (a[ni][nj] != 0 && ncnt < 512);
if (ncnt >= 512) return ;
a[ni][nj] = M;
suoha1();
}
int sh1 = 0;
void suoha2(){
for (int i = 2; i <= N; i ++)
for (int j = 1; j <= N; j ++)
if (a[i][j] != 0) up(i, j, 1);
sheng();
for (int i = 1; i <= N; i ++)
for (int j = 2; j <= N; j ++)
if (a[i][j] != 0) left(i, j, 1);
sheng();
for (int i = N - 1; i >= 1; i --)
for (int j = 1; j <= N; j ++)
if (a[i][j] != 0) down(i, j, 1);
sheng();
for (int i = 1; i <= N; i ++)
for (int j = N - 1; j >= 1; j --)
if (a[i][j] != 0) right(i, j, 1);
return ;
}
// mozu1 suoha
//mozu2 kill
void kill()
{
suoha1();
sheng();
return ;
}
int wei(int tmp){
int ans = 0;
do {
ans ++;
tmp /= 10;
} while (tmp);
return ans;
}
int main(){
system("color f0");
cin>>P;
system("cls");
if (P == 1) init();
else if(P == 2) init2();
else if(P == 3) init3();
else if(P == 4) init4();
while (true){
srand(time(0));
if (sh1 == 0){
int ni, nj, ncnt = 0;
do {
ni = rand() % N + 1;
nj = rand() % N + 1;
ncnt ++;
} while (a[ni][nj] != 0 && ncnt < 188);
if (ncnt >= 188) {
system("cls");
cout << "你失败了 分数:"<<score<<" "<< "最佳:"<<maxn<<endl;
return 0;
}
int ism = rand() % 8 + 1;
if (ism == 1) a[ni][nj] = -2;
else a[ni][nj] = M;
}
sh1 = 0;
cout << "分数:"<<score;
for (int i = 0; i < max(1, 21 - wei(score) - wei(maxn)); i ++) cout << " ";
cout<<"最佳:"<<maxn<<endl;
wow();
for (int i = 1; i <= N; i ++){
cout << "|";
for (int j = 1; j <= N; j ++){
if (P)
{
cout<<c1[a[i][j]] <<"|";
}
else
{
if (a[i][j] == 0) {
for (int i = 0; i < O; i ++) cout << " ";
cout << "|";
}
else cout << setw(O) << a[i][j] << "|";
}
}
cout << endl;
wow();
}
char jian;
cin >> jian;
if (jian == 'a'){
for (int i = 1; i <= N; i ++)
for (int j = 2; j <= N; j ++)
if (a[i][j] != 0) left(i, j, 1);
}
if (jian == 'd'){
for (int i = 1; i <= N; i ++)
for (int j = N - 1; j >= 1; j --)
if (a[i][j] != 0) right(i, j, 1);
}
if (jian == 'w'){
for (int i = 2; i <= N; i ++)
for (int j = 1; j <= N; j ++)
if (a[i][j] != 0) up(i, j, 1);
}
if (jian == 's'){
for (int i = N - 1; i >= 1; i --)
for (int j = 1; j <= N; j ++)
if (a[i][j] != 0) down(i, j, 1);
}
//mozu2 kill
if (jian == 'x'){
kill();
}
// mozu1 suoha
if (jian == 'e'){
suoha1();
sh1 = 1;
}
if (jian == 'q'){
suoha2();
}
// mozu1 suoha
system("cls");
}
return 0;
}