Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Introduction For this assignment, we are asking you to implement a mini Pokédex in C. The task is split into 5 sections; each section is not weighted the same. What is a Pokémon? What is a Pokédex?...

1 answer below »
Introduction
For this assignment, we are asking you to implement a mini Pokédex in C. The task is split into 5 sections; each section is not weighted the same.
What is a Pokémon? What is a Pokédex?
Hello there! Welcome to the world of Pokémon! My name is Oak! People call me the Pokémon Prof! This world is inhabited by creatures called Pokémon! For some people, Pokémon are pets. Others use them for fights. Myself ... I study Pokémon as a profession. — Professor Oak
Pokémon are fictional creatures from the Pokémon franchise, most famously from the Pokémon games. The game revolves around the (questionably ethical) capturing of these creatures. Within the fiction of this universe, a device called the Pokédex is used to catalogue all the creatures a player finds and captures.
Where can we learn more about Pokédexes?
You can play the one of the original Pokémon games here. Quite early in the game you get introduced to the Pokédex.
There's some more information on the Pokémon Wikia.
In addition, Google will be a great resource, as the topic has been extensively written up about.
Supplied Code
This zip file contains the files that you need to get started with the assignment. It contains the following files:
pokedex.h
contains declarations for all functions you need to implement for this assignment. Don't change pokedex.h
pokedex.c
contains stubs for all the functions you need to implement for this assignment. Put all your Pokédex code in pokedex.c.
pokemon.h
contains declarations for all functions you must call to create and manipulate Pokémon. Don't change pokemon.h
pokemon.c
contains the functions you must call to create and manipulate Pokémon. Don't change pokemon.c
main.c
contains a main function and other functions that allow you to interactively test the functions you implement in pokedex.c Don't change main.c
test_pokedex.c
contains a main function and other functions which are your starting point for a test framework to automatically test the functions you implement in pokedex.c. As you implement functions in pokedex.c you should add tests to test_pokedex.c. Only put testing code in test_pokedex.c.
Reference implementation
A reference implementation 1511 pokedex_reference is available to help you understand the assignment.
1511 pokedex_reference
===========================[ Pokédex ]==========================
XXXXXXXXXXWelcome to the Pokédex! How can I help?
================================================================
Enter command: ?
a [pokemon_id] [name] [height] [weight] [type1] [type2]
Add a Pokemon to the Pokedex
p
Print all of the Pokemon in the Pokedex (in the order they were added)
d
Display details of the cu
ently selected Pokemon

Move the cursor to the next Pokemon in the Pokedex

Move the cursor to the previous Pokemon in the Pokedex
m [pokemon_id]
Move the cursor to the Pokemon with the specified pokemon_id

Remove the cu
ent Pokemon from the Pokedex
x [seed] [factor] [how_many]
Go exploring for Pokemon
f
Set the cu
ent Pokemon to be found
c
Print out the count of Pokemon who have been found
t
Print out the total count of Pokemon in the Pokedex
e [pokemon_A] [pokemon_B]
Add an evolution from Pokemon A to Pokemon B
s
Show evolutions of the cu
ently selected Pokemon
q
Quit
?
Show help
Enter command: a 1 Bulbasaur XXXXXXXXXXpoison grass
Added Bulbasaur to the Pokedex!
Your pokedex.c (compiled with the supplied pokemon.c and main.c) should match the behaviour of the reference implementation.
Provision of a reference implementation is a common method to provide an operational specification, and it's something you will likely need to do outside UNSW.
If you discover what you believe to be a bug in the reference implementation, report it in the class forum. We may fix the bug or indicate that you do not need to match the reference implementation's behaviour in this case.
Stage 1: Adding and Printing
When you compile and run the given code, you will get the following message if you try to add a Pokemon:
dcc -o pokedex main.c pokedex.c pokemon.c
./pokedex
===========================[ Pokédex ]==========================
XXXXXXXXXXWelcome to the Pokédex! How can I help?
================================================================
Enter command: a 1 Bulbasaur XXXXXXXXXXpoison grass
exiting because you have not implemented the add_pokemon function in pokedex.c
When you run the a command, this function in pokedex.c is called:
void add_pokemon(Pokedex pokedex, Pokemon pokemon) {
fprintf(stde
, "exiting because you have not implemented the add_pokemon function in pokedex.c\n");
exit(1);
}
Your first task is to implement add_pokemon. All the functions you have to implement in pokedex.c have descriptions in pokedex.h:
Add a new Pokemon to the Pokedex.
Note: just adding the Pokemon to the Pokedex does not mean it has
been 'found'.
The new Pokemon should be added to the end of the Pokedex (i.e.
directly after the Pokemon that was added when add_pokemon was last
called).
When the first Pokemon is added to the Pokédex, the cu
ently
selected Pokemon becomes this Pokemon.
The cu
ently selected Pokemon remains the first Pokemon that was
inserted into the Pokedex, until the `change_cu
ent_pokemon`,
`next_pokemon`, or `prev_pokemon` functions are called.
If there is already a Pokemon in the Pokedex with the same pokemon_id
as this Pokemon, the function should print an appropriate e
o
message and exit the program.
Pokedex Order:
--------------
The Pokemon in the Pokedex are stored in the order in which they were
added, i.e. the first Pokemon in the Pokedex will be the first
Pokemon that was added, the second Pokemon in the Pokedex will be the
second Pokemon that was added etc, and the last Pokemon in the
Pokedex will be the Pokemon that was added most recently.
For example, if Pikachu (#025) was added into an empty Pokedex, the
Pokedex would now contain Pikachu at the start of the list, and
Pikachu would be the cu
ently selected Pokemon.
[Start of Pokedex]
#025: Pikachu <-- cu
ently selected Pokemon
[End of Pokedex]
If Squirtle (#007) was then added, it would be the second Pokemon in
the Pokedex, after Pikachu. The cu
ently selected Pokemon would
remain Pikachu.
[Start of Pokedex]
#025: Pikachu <-- cu
ently selected Pokemon
#003: Squirtle
[End of Pokedex]
If Diglett (#050) was then added, it would be the third Pokemon in the
Pokedex, after Squirtle.
[Start of Pokedex]
#025: Pikachu <-- cu
ently selected Pokemon
#003: Squirtle
#050: Diglett
[End of Pokedex]
void add_pokemon(Pokedex pokedex, Pokemon pokemon);
You need to put code in the add_pokemon function to store the pokemon it is given into the pokedex it is given.
You don't need to know any details about what the Pokemon type is (i.e. the type of the Pokemon pokemon argument passed to add_pokemon) to implement add_pokemon or any other function in pokedex.c.
Pokemon Tip #0: Pokemon IDs
In the Pokemon game franchise, Pokemon IDs start at 1 and go up to 809 (at the time of writing this). The first Pokemon is Bulbasaur, who has a Pokemon ID of 1. This assignment, however, allows any Pokemon ID from 0 upwards (because programmers love counting from 0).
Throughout this spec we'll be making use of Bulbasaur (as well as some of the other official Pokemon) in our examples, but do note that you can make your own Pokemon with any ID from 0 to the maximum number that can be stored in an integer.
Hint: your code should also operate under the assumption that a pokemon_id of 0 is valid.
If you look in pokedex.h you will discover this definition: typedef struct pokedex *Pokedex
In other words the type Pokedex is the same as struct pokedex *.
struct pokedex is defined at the top of pokedex.c.
It already has one field: a pointer to struct pokenode which can be used to store a linked list.
Put in code in add_pokemon to add the pokemon it is given to the linked list whose head is in the pokedex it is given.
Hint: allocate a struct pokenode with malloc.
When you run your code you should see this:
dcc -o pokedex main.c pokedex.c pokemon.c
./pokedex
===========================[ Pokédex ]==========================
XXXXXXXXXXWelcome to the Pokédex! How can I help?
================================================================
Enter command: a 1 Bulbasaur XXXXXXXXXXpoison grass
Added Bulbasaur to the Pokedex!
You'll need to implement 4 more functions to find out if add_pokemon really works:
void detail_pokemon(Pokedex pokedex);
Pokemon get_cu
ent_pokemon(Pokedex pokedex);
void find_cu
ent_pokemon(Pokedex pokedex);
void print_pokemon(Pokedex pokedex);
See pokedex.h for information on each function.
detail_pokemon and print_pokemon need to call functions defined in pokemon.h to get the information about a Pokemon they need to print.
Note the information detail_pokemon and print_pokemon print about a Pokemon depends on whether it has been found.
Hint: add a field to struct pokenode to indicate if a Pokemon has been found.
Pokemon Tip #1: finding Pokemon.
Your Pokedex is like an encyclopedia that stores information about Pokemon.
But unlike a normal encyclopaedia, some of the information in your Pokedex is hidden until you've discovered a Pokemon of that kind.
Once you have "found" a certain kind of Pokemon, its details will become visible to you in your Pokedex.
You will need to keep track of whether a Pokemon has been found in your Pokedex implementation.
Hint: add a field to struct pokenode to indicate if a Pokemon has been found.
Pokemon Tip #2: the cu
ently selected Pokemon.
Your Pokedex allows you to scroll through the Pokemon stored within, allowing you to see the details of a specific Pokemon of your choice. This means that there will always be one Pokemon that is cu
ently selected by the Pokedex.
When you add the first Pokemon to the Pokedex, that Pokemon becomes the cu
ently selected Pokemon. When you add additional Pokemon, the cu
ently selected Pokemon does not change.
In Stage 2, you will implement functions to allow you to scroll back and forth between Pokemon. But for now, you won't need to change the
Answered Same Day Apr 30, 2021

Solution

Aditi answered on May 01 2021
150 Votes
pokedex.c
Version 1.0.0: Assignment released.
Version 1.0.1: Minor clarifications about `struct pokenode`.
Version 1.1.0: Moved destroy_pokedex function to co
ect location.
Version 1.1.1: Renamed "pokemon_id" to "id" in change_cu
ent_pokemon.
#include #include #include Add any extra #includes your code needs here.
But note you are not permitted to use functions from string.h
so do not #include #include "pokedex.h"
#include
ool.h
Add your own #defines here.
Note you are not permitted to use a
ays in struct pokedex,
you must use a linked list.
You are also not permitted to use a
ays in any of the functions
below.
The only exception is that char a
ays are permitted fo
search_pokemon and functions it may call, as well as the string
returned by pokemon_name (from pokemon.h).
You will need to add fields to struct pokedex.
You may change or delete the head field.
struct pokedex {
struct pokenode *head;
struct pokenode *tail;
struct pokenode *cu
ent;
};
You don't have to use the provided struct pokenode, you are free to
make your own struct instead.
If you use the provided struct pokenode, you will need to add fields
to it to store other information.
struct pokenode {
struct pokenode *next;
Pokemon pokemon;
bool found;
int evolveFrom;
int evolveTo;
};
Add any other structs you define here.
Add prototypes for any extra functions you create here.
struct pokenode* new_pokenode(Pokemon pokemon){
    struct pokenode* new_pokenode = (struct pokenode*)malloc(sizeof(struct pokenode));
    new_pokenode->pokemon = pokemon;
    new_pokenode->next = NULL;
    new_pokenode->found = false;
    new_pokenode->evolveFrom = -;
    new_pokenode->evolveTo = -1;
    return new_pokenode;
}
You need to implement the following 20 functions.
In other words, replace the lines calling fprintf & exit with your code.
You can find descriptions of what each function should do in pokedex.h
Pokedex new_pokedex(void) {
Pokedex new_pokedex = (struct pokedex*)malloc(sizeof (struct pokedex));
assert(new_pokedex != NULL);

new_pokedex->cu
ent = NULL;
new_pokedex->tail = NULL;
new_pokedex->head = NULL;

return new_pokedex;
}
Stage 1 Functions
void add_pokemon(Pokedex pokedex, Pokemon pokemon) {
    
    struct pokenode* temp = new_pokenode(pokemon);
    
    if(pokedex->head == NULL){
        pokedex->head = temp;
        pokedex->tail = temp;
        pokedex->cu
ent = temp;
    }
    else{
        pokedex->tail->next = temp;
        pokedex->tail = pokedex->tail->next;
    }
}
void detail_pokemon(Pokedex pokedex) {
    Pokemon pokemon = pokedex->cu
ent->pokemon;
    
if(pokedex->found){
    printf("Id: %d",...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here