Presentation is loading. Please wait.

Presentation is loading. Please wait.

L09 - Pokémon.

Similar presentations


Presentation on theme: "L09 - Pokémon."— Presentation transcript:

1 L09 - Pokémon

2 MapInterface.h Sort //**** YOU MAY NOT MODIFY THIS DOCUMENT ****/
#ifndef MAP_INTERFACE_H #define MAP_INTERFACE_H #include <string> template <typename K, typename V> class MapInterface { public: static const int HashTableSize = 31; static const int BonusHashTableSize = 7; MapInterface() {} virtual ~MapInterface() {} /** Random read/write access operator. */ virtual V& operator[](const K& key) = 0; the number of elements removed from the Map. */ virtual size_t erase(const K& key) = 0; /** Removes all items from the Map. */ virtual void clear() = 0; number of Key-Value pairs stored in the Map. */ virtual size_t size() const = 0; maximum number of Key-Value pairs that the Map can hold. */ virtual size_t max_size() const = 0; string representation of Key-Value pairs in Map. */ virtual std::string toString() const = 0; }; #endif // MAP_INTERFACE_H

3 SetInterface.h Sort //**** YOU MAY NOT MODIFY THIS DOCUMENT ****/
#ifndef SET_INTERFACE_H #define SET_INTERFACE_H #include <string> template<typename T> class SetInterface { public: SetInterface() {} virtual ~SetInterface() {} /** Inserts item into the set. */ virtual bool insert(const T& item) = 0; the number of elements removed from the Set. */ virtual size_t erase(const T& item) = 0; /** Removes all items from the set. */ virtual void clear() = 0; the number of elements contained by the Set. */ virtual size_t size() const = 0; return 1 if contains element equivalent to item, else 0. */ virtual size_t count(const T& item) const = 0; string representation of items in Set. */ virtual std::string toString() const = 0; }; #endif // SET_INTERFACE_H

4 Pokémon Maps and Sets  Sort Map<string,string> pokemon;
pair<string,string> Charmander:fire Bulbasaur:grass Squirtle:water . . . Snorlax:normal key Map<string,string> moves; pair<string,string> flamethrower:fire brick_break:fighting razor_lear:grass . . . body_slam:normal key Pokemon: Charmander fire Bulbasaur grass Squirtle water . . . Snorlax normal Moves: flamethrower fire brick_break fighting razor_leaf grass . . . body_slam normal fighting:rock,ice,normal flying:fighting,grass ground:rock,fire,electric . . . Map<string,Set<string>> effectivities; key pair<string,set<string>> normal: Effectivities: fighting: rock ice normal flying: fighting grass ground: rock fire electric . . . normal: fighting:flying flying:rock,electric ground:flying,grass . . . Map<string,Set<string>> ineffectivities; key pair<string,set<string>> normal:rock Ineffectivities: fighting: flying flying: rock electric ground: flying grass . . . normal: rock

5 pokemon.cpp pokemon: Map<K, string> moves: Map<K, string>
Sort #include <iostream> #include <string> using namespace std; #include "Set.h" #include "Map.h" int main(int argc, char* argv[]) { Map<string, string> pokemon; Map<string, string> moves; Map<string, Set<string>> effectivities; Map<string, Set<string>> ineffectivities; pokemon["Charmander"] = "fire"; ineffectivities["fire"].insert("fire"); int action = ineffectivities["fire"].count("fire"); cout << endl << "pokemon: " << pokemon; cout << endl << "moves: " << moves; cout << endl << "effectivities: " << effectivities; cout << endl << "ineffectivities: " << ineffectivities; return 0; } pokemon: Map<K, string> moves: Map<K, string> effectivities: Map<K, Set<string>> ineffectivities: Map<K, Set<string>>

6 Battles Sort Battles will be much simpler than they are in the actual games. Each Pokémon has a single type (fire, water, rock). Each move (attack) is a single type. The pokemon map specifies the Pokémon type. The move map specifies the attack type. (For example "flamethrower" is attack type "fire" and Charmander uses "fire", hence Charmander can attack using a "flamethrower".) The effectivities map specifies which attack types are more effective. (For example, water is super effective against fire.) The ineffectivities map specifies which attack types are less effective. (For example, fire is not very effective against water.) Any move type that is neither strong nor weak against a Pokémon of a certain type is considered effective. (For example, rock is regularly effective against water because it has no advantage or disadvantage against it.) In a single battle, two Pokémon are chosen and each Pokémon chooses one move to attack the other one with. Whichever Pokémon attacks with the more effective move wins the battle. If the two moves have equal effectiveness, then the battle ends in a tie.

7 Charmander: flamethrower Squirtle: water_gun
Sort Charmander is a Pokémon of type fire. pokemon map (Charmander -> fire) Squirtle a Pokémon of type water. pokemon map (Squirtle -> water) In the battle, Charmander uses flamethrower (fire) and Squirtle uses water_gun (water). moves map (flamethrower -> fire) Fire type moves are effective against grass and ice, but are ineffective against rock, fire, and water. effectivities map (fire -> grass,ice) ineffectivities map (fire -> rock,fire,water) Hence, Charmander (of type fire) using a flamethrower (fire) is ineffective against Squirtle (of type water) using a water_gun (water) Water type moves are effective against ground, rock, and fire, but are ineffective against water and grass. effectivities map (water-> ground,rock,fire) ineffectivities map (water-> water,grass) Hence, Squirtle (of type water) using a water_gun (water) is effective against Charmander (of type fire). Because Charmander's move was ineffective and Squirtle's move was effective, Squirtle wins the battle.

8


Download ppt "L09 - Pokémon."

Similar presentations


Ads by Google