#include<bits/stdc++.h>
using namespace std;
int counter=0;
struct pokemon{
int pokedex=0;
int damage;
int health;
int level=1;
pokemon *next=nullptr;
pokemon *prev=nullptr;
};
void discard(pokemon *temp)
{
if(temp->pokedex==0)
return;
else
{
temp->prev->next=temp->next;
temp->next->prev=temp->prev;
counter-=1;
delete temp;
}
}
int main()
{
pokemon *head;
head = new pokemon;
pokemon *current=head;
pokemon *target=nullptr;
int number;
cin>>number;
for(int y=0;y<number;y++)
{
//current=head->prev;j
int pokedex,damage,health;
string command;
int length;
string state;
cin>>command;
if(command=="Insert")
{
cin>>pokedex>>damage>>health>>state;
pokemon *newpoke= new pokemon;
current->next=newpoke;
newpoke->prev=current;
newpoke->next=head;
head->prev=newpoke;
current=newpoke;
newpoke->pokedex=pokedex;
newpoke->damage=damage;
newpoke->health=health;
counter+=1;
if(target==nullptr)
{
target=newpoke;
//cout<<"this is target"<<endl;
}
if(state=="Evolve")
{
if(counter<3)
goto end;
if(newpoke->next->next->pokedex==newpoke->pokedex&&newpoke->prev->pokedex==newpoke->pokedex)
{
pokemon *left=newpoke->prev;
pokemon *right=newpoke->next->next;
if(left->level<3&&right->level<3)
{
int maxlevel=max(left->level,right->level);
int maxhp=max(left->health,right->health);
maxhp=max(maxhp,newpoke->health);
int maxdamage=max(left->damage,right->damage);
maxdamage=max(maxdamage,newpoke->damage);
target->health=maxhp;
target->damage=maxdamage;
target->level=(maxlevel+1);
//newpoke->prev->prev->next=head;
current=newpoke->prev->prev;
discard(newpoke->prev);
discard(newpoke);
}
else
goto end;
}
else
goto end;
}
else if(state=="Attack")
{
if(newpoke==target)
goto end;
if(counter<3)
{
newpoke->prev->health-=newpoke->damage;
if(newpoke->prev->health<1)
{
discard(newpoke->prev);
target=newpoke;
}
goto end;
}
newpoke->next->next->health-=newpoke->damage;
newpoke->prev->health-=newpoke->damage;
if(newpoke->prev->health<1)
discard(newpoke->prev);
if(newpoke->next->next->health<1)
{
target=target->next;
discard(target->prev);
current=head->prev;
}
goto end;
}
else
goto end;
}
else if(command=="Delete")
{
if (target==nullptr)
goto end;
else if(target->pokedex==0)
goto end;
else if(counter==1)
{
//cout<<"haha"<<endl;
//pokemon *temp=target;
target=nullptr;
//cout<<"it works!"<<endl;
//delete temp;
head->next=nullptr;
head->prev=nullptr;
counter--;
current=head;
goto end;
}
else
{
pokemon *temp=target->next;
if(target==current)
current=target->prev;
discard(target);
target=temp;
}
}
else if (command=="Shuffle")
{
string direction;
cin>>direction>>length;
length%=counter;
if(length==0)
length=counter;
if(direction=="c")
{
pokemon *temp=target;
if(target->pokedex==0||length==1)
goto end;
for(int i=0;i<length-1;i++)
{
if(temp->pokedex==0)
i-=1;
temp=temp->next;
}
int temppokedex,tempdamage,temphealth,templevel;
temppokedex=temp->pokedex;
templevel=temp->level;
tempdamage=temp->damage;
temphealth=temp->health;
temp->pokedex=target->pokedex;
temp->level=target->level;
temp->damage=target->damage;
temp->health=target->health;
target->pokedex=temppokedex;
target->level=templevel;
target->damage=tempdamage;
target->health=temphealth;
pokemon *temp2=temp;
target->prev=head->prev;
head->prev->next=target;
target=temp;
head->prev=target->prev;
target->prev->next=head;
target->prev=head;
head->next=target;
current=head->prev;
}
else if(direction=="a")
{
pokemon *temp=target;
if(target->pokedex==0||length==1)
goto end;
if(length==2)
temp=temp->prev->prev;
else
{
for(int i=0;i<length-1;i++)
{
if(temp->pokedex==0)
i-=1;
temp=temp->prev;
}
}
int temppokedex,tempdamage,temphealth,templevel;
temppokedex=temp->pokedex;
templevel=temp->level;
tempdamage=temp->damage;
temphealth=temp->health;
temp->pokedex=target->pokedex;
temp->level=target->level;
temp->damage=target->damage;
temp->health=target->health;
target->pokedex=temppokedex;
target->level=templevel;
target->damage=tempdamage;
target->health=temphealth;
pokemon *temp2=temp;
target->prev=head->prev;
head->prev->next=target;
target=temp;
head->prev=target->prev;
target->prev->next=head;
target->prev=head;
head->next=target;
current=head->prev;
}
}
else if(command=="Check")
{
cin>>length;
if(length<2)
goto end;
int count[101]={0};
pokemon *temp=target;
for(int i=0;i<length && temp->pokedex!=0;i++)
{
count[temp->pokedex]+=1;
temp=temp->next;
}
temp=target;
for(int i=0;i<length && temp->pokedex!=0;i++)
{
if(count[temp->pokedex]>1)
{
if(counter==1)
{
delete target;
target=nullptr;
head->next=nullptr;
head->prev=nullptr;
current=head;
counter--;
goto end;
}
if(temp==target)
target=temp->next;
if(temp==current)
current=temp->prev;
pokemon *temp2=temp->next;
discard(temp);
temp=temp2;
}
else
temp=temp->next;
}
}
else if (command == "Reverse")
{
cin >> length;
pokemon *front=target;
for(int i=counter;i>0;i-=length)
{
int round;
if(i>length)
round=length;
else
round=i;
vector<pokemon*>temps;
pokemon *temp=front;
for(int b=0;b<round;b++)
{
temps.emplace_back(temp);
temp=temp->next;
}
temps[round-1]->prev=temps[0]->prev;
temps[round-1]->prev->next=temps[round-1];
temps[0]->next=temps[round-1]->next;
temps[0]->next->prev=temps[0];
for(int b=round-1;b>0;b--)
{
temps[b]->next=temps[b-1];
temps[b-1]->prev=temps[b];
}
if(front==target)
{
target=temps[round-1];
}
if(temps[round-1]==current)
current=temps[0];
front=temps[0]->next;
}
}
end:
pokemon *temp=target;
if(temp==nullptr)
{
cout<<"no Poke Poke ;-;"<<endl;
continue;
}
while(temp->pokedex!=0)
{
cout<<"ID:"<<temp->pokedex<<" HP:"<<temp->health<<" LVL:"<<temp->level<<"->";
temp=temp->next;
}
cout<<endl;
}
if(target==nullptr)
cout<<"no Poke Poke ;-;"<<endl;
else
{
while(target->pokedex!=0)
{
cout<<"ID: "<<target->pokedex<<" HP: "<<target->health<<" LVL: "<<target->level;
target=target->next;
cout<<endl;
}
}
}