L09 - Pokémon.

Slides:



Advertisements
Similar presentations
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Advertisements

Esempio Polimorfismo1 // Definition of abstract base class Shape #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double area() const { return.
Week 5 - Associative Containers: sets and maps. 2 2 Main Index Main Index Content s Content s Container Types Sequence Containers Adapter Containers Associative.
. The Standard C++ Library. 2 Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface.
Binary Search Trees II Morse Code.
ITEC 320 C++ Examples.
STL multimap Container. STL multimaps multimaps are associative containers –Link a key to a value –AKA: Hashtables, Associative Arrays –A multimap allows.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Command Line Arguments.
Lecture 6 : Template Acknowledgement : courtesy of Prof. Dekai Wu lecture slides.
Lin Chen 09/06/2011. Global variables const int maxCandidates = 10; // Names of the candidates participating in this state's primary string candidate[maxCandidates];
CSE 232: C++ memory management Overview of Arrays Arrays are the simplest kind of data structure –One item right after another in memory (“contiguous range”
CS415 C++ Programming Takamitsu Kawai x4212 G11 CERC building WV Virtual Environments Lab West Virginia University.
1 More Operator Overloading Chapter Objectives You will be able to: Define and use an overloaded operator to output objects of your own classes.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
Associative Containers Sets Maps Section 4.8. Associative Containers.
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
Data Abstraction: The Walls
CSCE 210 Data Structures and Algorithms
CSCE 210 Data Structures and Algorithms
#define #include<iostream> using namespace std; #define GO
Mark Redekopp David Kempe
Generic Algorithms (TIC++V2:C6)
Template Classes and Functions
Lecture 6 : Template Acknowledgement : courtesy of Prof. Dekai Wu lecture slides.
Command Line Arguments
Arrays Part-1 Armen Keshishian.
Multi-dimensional Array
Monday, March 19, 2018 Announcements… For Today… For Next Time…
Monday, April 2, 2018 Announcements… For Today… For Next Time…
9.5 Implementation Considerations for the hash_map
Reserved Words.
Chapter 9 – Sets and Maps 9.1 Associative Container
Lecture 7-3 : STL Algorithms
C++ Templates L03 - Iterator 10 – Iterator.
10 – Iterators C++ Templates 4.6 The Iterator pgs
Programming -2 برمجة -2 المحاضرة-5 Lecture-5.
Lab 04 – Linked List.
5.1 The Stack Abstract Data Type
Associative Structures
C++ Functions, Classes, and Templates
3.3 Abstract Classes, Assignment, and Casting in a Hierarchy
Lab 03 - Iterator.
C++ Templates CSE 333 Spring 2018
Lab 05 – Expressions.
L09 - Pokémon.
Creation and Use of Namespaces
Pointers & Functions.
Code::Block vs Visual C++
Stat Balancing of 1st Generation PokemonGo!
Iterators and STL Containers
C++ Templates L03 - Iterator 10 – Iterator.
C++ Templates CSE 333 Summer 2018
C++ Templates L03 - Iterator 10 – Iterator.
foo.h #ifndef _FOO #define _FOO template <class T> class foo{
C++ Templates CSE 333 Autumn 2018
Lab4 problems More about templates Some STL
Array-Based Lists & Pointers
Pointers and dynamic objects
Pointers & Functions.
CMSC 341 C++ and OOP.
C++ Templates CSE 333 Winter 2019
CMSC 341 C++ and OOP.
An Introduction to STL.
Recitation Outline Hash tables in C++ STL Examples Recursive example
Lab 03 – Linked List.
16 – Sequential Containers
Chapter 9 – Sets and Maps 9.1 Associative Container
5.1 The Stack Abstract Data Type
10.3 Bubble Sort Chapter 10 - Sorting.
Data Structures & Programming
Presentation transcript:

L09 - Pokémon

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; /** @return: 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; /** @return: number of Key-Value pairs stored in the Map. */ virtual size_t size() const = 0; /** @return: maximum number of Key-Value pairs that the Map can hold. */ virtual size_t max_size() const = 0; /** @return: string representation of Key-Value pairs in Map. */ virtual std::string toString() const = 0; }; #endif // MAP_INTERFACE_H

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; /** @return: 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; /** @return: the number of elements contained by the Set. */ virtual size_t size() const = 0; /** @return: return 1 if contains element equivalent to item, else 0. */ virtual size_t count(const T& item) const = 0; /** @return: string representation of items in Set. */ virtual std::string toString() const = 0; }; #endif // SET_INTERFACE_H

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

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>>

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.

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.