Question: Part 1 : Implementation You have several flasks, each with a capacity limit of 4 units. Alongside, you possess a collection of chemicals, where each
Part : Implementation
You have several flasks, each with a capacity limit of units. Alongside, you possess a collection of chemicals, where each chemical type is available in quantities of units. The file chemicals.txt is read and chemicals are queued into a bounded queue. From that bounded queue, the chemicals are distributed into flasks. Each flask should be implemented as a bounded stack. The first line of the file indicates the number of flasks and the number of chemicals respectively, separated by a space. After the first line, the text file contains two types of lines:
: Name of the chemical. For example AA or BB or CC Each chemical should be enqueued into a bounded queue.
: F This means to dequeue x chemicals from the queue, and add them to flask y one at a time.
Here is a sample text file to demonstrate.
BB
AA
BB
BB
AA
F
AA
AA
F
For your assignment, you may use this text file for flasks chemicals and this text file for flasks chemicals.
You must use a bounded queue of size to store the chemical once you have read it from the file. You must check if the queue is full when adding chemicals. If it is full and the text file tells you to add another chemical, discard that chemical and move on to the next line. For the input file given above your bounded queue should look like this:
here is two txt files
fctxt
BB
BB
BB
AA
AA
F
AA
AA
CC
CC
BB
F
DD
EE
EE
DD
F
EE
CC
FF
F
FF
DD
F
FF
F
fctxt
BB
BB
BB
AA
AA
F
AA
AA
CC
CC
BB
F
DD
EE
EE
DD
F
EE
CC
FF
F
FF
DD
F
FF
F
After reading the file, your flasks should now each contain mixed chemicals and should look like this:
AA
AA
AABB
BBBB
Take inputs from the user. The user can enter an int from to the number of flasks for the source and destination flasks, or can enter 'exit' for either at any time to terminate the program. If the user does not enter an int from to the number of flasks or exit print the error message Invalid input. Try again. If the source flask is empty or sealed, print the error message Cannot pour from that flask. Try again. If your destination flask is full or sealed, print the message Cannot pour into that flask. Try again. Lastly, if the user tries to pour into the same flask theyre pouring out of print the error message Cannot pour into the same flask. Try again. If all inputs are correct, then the topmost chemical from the source flask will be removed from the source flask, and added to the top of the destination flask. The flask seals after it contains only three of the same chemicals. Flask below should seal, flask should not. Flask two will seal once the top chemical BB is removed.After taking input, move the chemical as specified by the user, then display your flasks. The flasks should be displayed with at most in one line. If there are more than flasks, the remaining should be displayed in the next row of flasks. There should be spaces between each flask, and the number of the flask should be underneath the second dash of the flask. Should you need rows to display all the flasks, the rows should be separated by line of space. This is what your entire display with flasks should look like.
Magical Flask Game
Select source flask:
Select destination flask:
On each turn, ask the user to enter the source and destination flask numbers. Make the changes to the flasks based on the game rules and display the flasks at the end. Display sealed flasks as such. Continue taking input and displaying the flasks until the game ends. The game ends when the u
Part : Incorporating ANSI escape commands
In this phase of the implementation, you will be implementing ANSI escape commands.
First, when you start your program, clear the screen. The first line should say Magical Flask Game. The third line should say Select Source Flask: The fourth line should say Select Destination Flask: Starting from the sixth line the initial status of the flasks after the initial random distribution of the chemicals should be shown.
We will change how the inputs are displayed, this will be similar to Lab The prompts below should be displayed on lines and respectively. The inputs should be taken one space after the prompt for lines and For any of these lines, if the user gives an invalid input, the input should be cleared and the input should be taken repeatedly until the user gives a valid input. Your cursor should not move to the next line until valid input has been given. For each invalid input, print the error message Invalid Input. Try Again on line and clear the error message once valid input has been entered.
Assignment Deliverables
You are going to submit Python files: bstack.py bqueue.py and assignmentpy
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
