13787 - Pokemon Battle Manager   

Description

A long long time ago, the sky was dark and gloomy, the ocean was deep and mysterious, and the continent was covered by lava and sandstorm. The mad wild world was dominated by what’s called Pokémon today. It’s a prehistoric era, where the ancient monsters were both arrogant and noble. But it will only last until the human–or whatever is the so-called trainer–comes.

These beautiful creatures are now puppets of a bunch of goddamn ten years old kids. They travel across countries to collect different species of Pokémon for their fetishism, for they are addicted to control, to dominate lives that cannot defy them. Thousands of thousands of innocent Pokémons got caught, imprisoned, and traded as goods.

And yet it’s not the worst. Like any civilization did to the slaves, trainers love to have their Pokémon battle against other trainers’ Pokémon. They compete with each other in their Pokémon battles and consider it glorious if they win, although all they do is sit and watch the poor Pokémons bleeding, burning to death.

Now as a Pokémon battle field manager, you are asked to report the battle process between two given Pokémons. We’ll dig into the details in the following.

 

In this problem, you are asked to implement 2 functions:

  1. Upgrade a Pokémon
  2. Simulate a battle

The following is “function.h”. It is guaranteed that the given Pokémon would only be one of the following 5 types: "Geodude", "Raichu", "Golbat", "Magnemite", and "Exeggutor", indexed from 0 to 4.
For the function “level_up”, you are going to upgrade a Pokémon. Here are the details:

  1. If the level is less than 5, increase level by 1 and increase attackdefensemaxHpmaxMp by lvup_atklvup_dfnlvup_maxHplvup_maxMp, respectively. Otherwise do nothing.
  2. Set HpMp to maxHpmaxMp, respectively.

For the function “battle”, you are going to simulate a battle process. Here are the details:

  1. The two Pokémon take turns to move. Pokémons can choose to attack or rest on their turns. Pokémon A would move first.
  2. The Pokémon’s Mp would increase by T at its turn every time before its action.
  3. When Pokémon P1 attacks, it causes damage to the other Pokémon P2, i.e. the Hp of P2 would decrease by the damage. Each attack consumes Mp. After the attack, P1’s  Mp will be reduced by its costMp. The damage is calculated by the formula below:
    damag× P1.leve× max(P1.attac− P2.defense0100 
    After the damage is applied to P2, if P2’s HP is less than 0P2’s HP should be set to 0.
  4. Pokémon would always choose to attack if there is enough Mp for it to attack. Otherwise, the Pokémon chooses to rest and recovers an extra T Mp.
  5. If a Pokémon P1 attacks Pokémon P2 on its turns, print the following two sentences: “{P1.name} used Headbutt!”, “{P2.name} now has {P2.Hp} HP.”, each end with a newline character.
  6. If a Pokémon P1 rests in its turn, print the following two sentences: “{P1.name} used Rest!”, “{P1.name} now has {P1.Mp} MP.”, each end with a newline character.
  7. Whenever any Pokémon has its Hp equal to 0, the battle ends directly, and you have to report the battle result. In the case that the two of them both got 0 Hp in the end, you have to print “Draw.” ends with a newline character. Otherwise, suppose that the winner is P, the loser is L, print “{P.name} is the winner! {L.name} died in vain…” ends with a newline character, too. After that, print a blank line for mourning one more be gone spirit.

 

#include <stdio.h>
#define lvup_atk 200
#define lvup_dfn 100
#define lvup_maxHp 20
#define lvup_maxMp 15
#define T 2

typedef struct pokemon{
    int id;
    char name[10];
    int level;
    int attack;
    int defense;
    int Hp;
    int Mp;
    int maxHp;
    int maxMp;
    int costMp;
}Pokemon;

// TODO: upgrade and recover the Pokémon
void level_up(Pokemon *P);

// TODO: simulate and print the process of the battle
void battle(Pokemon *A, Pokemon *B);

Input

The first line contains an integer n, representing the number of Pokémons.
The second line contains integers xi, representing the type of each Pokémon.
The third line contains an integer t, representing the number of operations.
Then, t lines follow, each representing an operation.

Each operation is in the following forms:
1 id:
The id th Pokémon level up.
2 a b:
Please print the battle process of the a th Pokémon and the b th Pokémon.

Output

Execute each operation described in the statement above.
Check the sample output for more details.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

13787.c

Partial Judge Header

13787.h

Tags

LoseLightLight FlyHighHigh



Discuss