#include<cstring>
#include<bits/stdc++.h>
#include"printcolor.h"
using namespace std;
int xx,yy,zz,h_max=499,x_max=499,y_max=499,HP=20;
const int pp=500,kk=8;
bool world[pp][pp][pp],can_tp;
bool can_go[pp][pp][pp];
int player_time=1;
int ttime[10000];
bool can_stand(int x,int y,int z){
	if(x<=0 or y<=0 or x>=x_max or y>=y_max or z+1>=h_max or z-1<=0)return false;
	return !world[x][y][z] and !world[x][y][z+1] and world[x][y][z-1];
}
int search_down(int x,int y,int z){
	if(x<=0 or y<=0 or x>=x_max or y>=y_max)return h_max*2;
	for(int sz=0;sz<=15;sz++){
		if(z-sz>0 and can_stand(x,y,z-sz))return z-sz;
	}
	return h_max*2;
}
void print_jump(int x,int y,int z){
	if(xx==x and yy==y and zz==z){
		setTextColor("blue");
		cout<<"n";
		return ;
	} 
	if(abs(xx-x)+abs(yy-y)<=3 and abs(xx-x)+abs(yy-y)>=2){
		if(zz-z<=4){
			bool chk=true;
			for(int kx=min(x,xx);kx<=max(x,xx);kx++){
				for(int ky=min(y,yy);ky<=max(y,yy);ky++){
					if((kx!=xx or ky!=yy) and (kx!=x or ky!=y)){
						if(z-search_down(kx,ky,z)<=1)chk=false;
					}
				}
			}
			if(chk){
				setTextColor("white");
				cout<<"j";
				can_go[x][y][z]=true;
				return ;
			}
		}
	}
	cout<<" ";
}
int search(int x,int y,int z){
	if(x<=0 or y<=0 or x>=x_max or y>=y_max)return h_max*2;
	for(int sz=0;sz<=15;sz++){
		if(z-sz>0 and can_stand(x,y,z-sz))return z-sz;
		if(z+sz<h_max and can_stand(x,y,z+sz))return z+sz;
	}
	return h_max*2;
}
void out(){
	system("cls");
	memset(can_go,0,sizeof(can_go));
	for(int sy=-kk;sy<=kk;sy++){
		for(int sx=-kk;sx<=kk;sx++){
			int zn=search(xx+sx,yy+sy,zz-1),zno=search(xx+sx,yy+sy-1,zz-1);
			if(zn-4>zno){
				setTextColor("red");
				cout<<" - ";
			}
			else if(zn<zno-1){
				setTextColor("green");
				cout<<" - ";
			}
			else{
				setTextColor("white");
				cout<<" - ";
			}
			if(sy==0 and sx==0 and zn>=zno-1)can_go[sx+xx][sy+yy-1][zno]=true;
		}
		cout<<endl;
		for(int sx=-kk;sx<=kk;sx++){
			int zn=search(xx+sx,yy+sy,zz-1),zno=search(xx+sx-1,yy+sy,zz-1),znp=search(xx+sx+1,yy+sy,zz-1);
			if(zn-4>zno){
				setTextColor("red");
				cout<<"|";
			}
			else if(zn<zno-1){
				setTextColor("green");
				cout<<"|";
			}
			else{
				setTextColor("white");
				cout<<"|";
			}
			print_jump(xx+sx,yy+sy,search_down(xx+sx,yy+sy,zz));
			if(zn-4>znp){
				setTextColor("red");
				cout<<"|";
			}
			else if(zn<znp-1){
				setTextColor("green");
				cout<<"|";
			}
			else{
				setTextColor("white");
				cout<<"|";
			}
			if(sy==0 and sx==0 and zn>=zno-1)can_go[sx+xx-1][sy+yy][zno]=true;
			if(sy==0 and sx==0 and zn>=znp-1)can_go[sx+xx+1][sy+yy][znp]=true;
		}
		cout<<endl;
		for(int sx=-kk;sx<=kk;sx++){
			int zn=search(xx+sx,yy+sy,zz-1),zno=search(xx+sx,yy+sy+1,zz-1);
			if(zn-4>zno){
				setTextColor("red");
				cout<<" - ";
			}
			else if(zn<zno-1){
				setTextColor("green");
				cout<<" - ";
			}
			else{
				setTextColor("white");
				cout<<" - ";
			}
			if(sy==0 and sx==0 and zn>=zno-1)can_go[sx+xx][sy+yy+1][zno]=true;
		}
		cout<<endl;
	}
	setTextColor("white");
	cout<<"x:"<<xx<<" y:"<<yy<<" z:"<<zz<<" HP:"<<HP<<endl;
}
int main(){
	for(int i=0;i<pp;i++){
		for(int j=0;j<pp;j++){
			world[i][j][1]=true;
		}
	}
	world[25][25][3]=true;
	world[253][252][7]=true;
	world[253][253][8]=true;
	world[253][254][9]=true;
	world[252][254][10]=true;
	world[249][253][11]=true;
	world[249][252][8]=true;
	world[249][251][9]=true;
	world[249][250][8]=true;
	world[250][254][8]=true;
	world[249][254][8]=true;
	world[251][254][8]=true;
	world[251][254][8]=true;
	world[252][252][6]=true;
	world[251][251][6]=true;
	world[249][251][5]=world[249][251][6]=true;
	world[249][250][2]=world[249][250][3]=world[249][250][4]=world[249][250][5]=true;
	world[249][249][2]=world[249][249][3]=world[249][249][4]=true;
	world[249][248][3]=true;
	world[248][248][2]=true;
	xx=250;
	yy=250;
	zz=2;
	can_tp=true;
	out();
	int t=1;
	ttime[1]=1;
	while(1>0){
		if(ttime[t]==1){
			string op;
			int xo=0,yo=0;
			cin>>op;
			if(op.length()==2){
				if(op[0]=='t' and op[1]=='o'){
					cin>>xo>>yo;
					if(x_max>30*ceil(xo/30.0) and 30*ceil(xo/30.0)>0 and y_max>30*ceil(yo/30.0) and 30*ceil(yo/30.0)>0){	
						yo=30*ceil(yo/30.0);
						xo=30*ceil(xo/30.0);
						xx=xo;
						yy=yo;
						zz=2;
					}
				}
				out();
				ttime[t]=0;
				ttime[(t+player_time)%10000]=1;
			}
			if(op.length()!=2 or op[0]!='t' and op[1]!='o'){
				xo=0,yo=0;
				for(int i=0;i<op.length();i++){
					if(op[i]=='w'){
						yo--;
					}
					if(op[i]=='a'){
						xo--;
					}
					if(op[i]=='s'){
						yo++;
					}
					if(op[i]=='d'){
						xo++;
					}
				}
				for(int zo=0;zo<h_max;zo++){
					if(can_go[xx+xo][yy+yo][zo]){
						xx=xo+xx;
						yy=yy+yo;
						if(zz-zo>=5){
							HP-=(zz-zo-4)*(zz-zo-4);
						}
						if(HP<=0){
							zz=zo;
							out();
							return 0;
						}
						zz=zo;
						break;
					}
				}
				out();
				ttime[t]=0;
				ttime[(t+player_time)%10000]=1;
			}
		}
		t++;
		t=t%10000;
	}
}