CSCI 1100 — Computer Science 1 Homework
CSCI 1100 — Computer Science 1 Homework 8
CS1 Multiverse: Classes
Overview
This homework is worth 100 points toward your overall homework grade, and is due Thursday,
April 25, 2019 at 11:59:59 pm. Please download hw08_files.zip. and unzip it into the directory
for your HW 8. You will find multiple data files to be used for tests.
The goal of this assignment is to work with classes. You will be asked to write a simulation engine
and use classes to encapsulate data and functionality. You will have a lot of design choices to make.
While we have done simulations before, this one will be more complex. It is especially important
that you start slowly, build a program that works for simple cases, test it and then add more
complexity. We will give lots of partial credit even if you do not get all the answers right. We will
provide test cases of increasing difficulty. Make sure you develop slowly and test thoroughly.
Submission Instructions
In this homework, for the first time, you will be submitting multiple files to Submitty that together
comprise a single program.
Please follow these instructions carefully.
You must submit three files. A file called Person.py that contains your Person class, a file called
Universe.py that contains your Universe class and a file called hw8.py that contains your main
program.
As always, make sure you follow the program structure guidelines. You will be graded on program
correctness as well as good program structure.
Remember as well that we will be continuing to test homework assignments for similarity. So,
follow our guidelines for the acceptable levels of collaboration. You can download the guidelines
from the Course Materials section of Submitty if you need a refresher. Note that guidelines also
forbid using someone else’s code from a previous semester. Make sure the code you submit is truly
your own.
Enter the multiverse: Universes
Many TV shows and movies make use of the theory of a multiverse. According to this theory many
universes very similar to ours exist at the same time. In fact, different versions of us may exist
in these universes as well. These alternate versions are very similar to us but may differ in very
fundamental ways. For example see regular and evil Spock from the original Star Trek (left), the
Council of Ricks from Rick and Morty (middle) and the recent Council of Wells from Flash (right).
Other examples include evil Willow and Xander. We can go on and on, but you get the point.
Same individual but with a few fundamental differences that arise because they are from a different
universe.
代做CSCI 1100作业、代写Python课程作业、代做data files作业、代写Python程序语言作业
In this homework, you will have multiple universes each identified by their name. Assume each
universe has the same dimensions, a rectangle between coordinates (0,0) at the upper left corner
and (1000,1000) at the lower right corner. Each universe has some attributes:
The name of the universe given by a string.
A list of rewards in that universe.
Each reward has the following information: x, y, points, and name,
where x,y is the location the reward is located in this universe, it has the point value (points)
and the (name) which describes the reward.
A list of portals, each can transport you to a different universe.
Each portal has the following information: from_x, from_y, to_name, to_x, to_y
which means that the portal is at location from_x,from_y in the current universe and it
transports you to location to_x,to_y in universe with name to_name.
In the early tests for the homework, we will assume that there is a single universe with rewards,
but no portals. As the plot thickens, we will add the portals and other universes.
You must implement a universe class to hold the above information and store it in a file called
Universe.py. At a minimum, your Universe class must have a constructor (__init__) function
and a string representation (__str__) function.
As you implement the main program, you may find other useful methods for this class that will
simplify your program.
Here is an example universe from a test case:
Universe: EasyCS1 (4 rewards and 0 portals)
Rewards:
at (40,60) for 10 points: instant set knowledge
at (100,200) for 40 points: bonus 5 points on one homework
at (200,400) for 30 points: instant knowledge of list comprehension
at (600,800) for 50 points: good variable name generation ability
Portals:
None
Multiverse: Individuals
In your simulation, you will track individuals moving along the universe. Each individual will have
the following attributes:
name, radius, home_universe, x, y, dx, dy, current_universe, rewards
Each individual is from a specific universe (though we only use this to print where they are from).
They are represented as a circle with a given radius. Their current location is given by x, y and
the current_universe they are on. Individuals have a speed given by their movement along x and
y axis, stored in (dx, dy). Eventually individuals may stop or slow down, we will see how later.
You will be given an initial location and speed for each individual. They will all start moving in
their current universe, but may move to other universes through portals. They may also pick up
rewards over time, which you want to store. Initially, rewards will be empty. We will be interested
in the awards the individual picked up as well as their total point value.
Implement a person class to hold the necessary data for each person. Store this in a file called
Person.py.
As in universes, you may find that implementing some methods for each person class may signifi-
cantly simplify your main code.
Here are some example individuals from one of our test cases.
Scientist of EasyCS1 in universe EasyCS1
at (20,30) speed (20,30) with 0 rewards and 0 points
Engineer of EasyCS1 in universe EasyCS1
at (600,800) speed (-40,-10) with 0 rewards and 0 points
CS1 Multiverse: The Main Idea
Here is the main idea of the simulation: In this simulation, you have (potentially) many universes
and many individuals. Each individual is initially in their own universe at a specified location.
At each step of the simulation, each individual moves one time (i.e., x += dx, y += dy). Then,
we check a number of conditions. Each condition is checked in the same order the individuals are
given from the input file:
1. If an individual passes near a location with treasure, she picks it up. As she carries more
items, her speed goes down under the weight. The speed change will impact either dx or dy
as they shift left to right.
If the magnitude (absolute value) of a person’s speed drops below 10 in either the x or y
directions, she stops moving. Stopped individuals will no longer move in later steps.
2. If an individual reaches the edge of the board, then she stops moving. Check for the center
of the individual being passed or at the border.
3. If two individuals hit each other while moving, they each drop the first reward they picked up
(if they have any). The reward returns to its original location. Note that dropping a reward
increases a person’s speed. After a collision, both individuals begin moving in the opposite
direction with their new speed.
4. If an individual comes near the location of a portal, then she moves to a different universe
that this portal points to. In the next simulation step, she will continue her journey in that
new universe.
The simulation ends either at 100 steps or when there is no individual left moving. At the end of
the simulation, the individual with the largest amount of collected treasure wins the game.
Whenever we are testing whether an individual is close to a reward, we check if the distance between
the individual’s location (x1, y1) and the reward’s location (rx,ry) is less than or equal to the
individual’s radius (radius1): sqrt((x1 - rx)**2 + (y1 - ry)**2) <= radius1
To check whether two individual collide, we will look at the distance between their location
(x1,y1 and x2, y2) being less than or equal to the sum of their radius radius1 and radius2:
sqrt((x1 - x2)**2 + (y1 - y2)**2) <= radius1 + radius2
Note that, you will be given multiple test cases that only include steps (1) and (2) above. First
implement these and test them. Then we will include test cases with collisions but no portals.
Finally, we will have test cases with portals with or without collisions as universe expands.
For simplicity, we will give you all the relevant information about the program in a single JSON
file. The file contains a single list, each item in the list is a universe.
Each universe is a dictionary with keys: universe_name, rewards, portals, and individuals as
shown below:
Universe Dictionary Field Data Type
universe_name String
rewards List of tuples with 4 values: x, y, points, description
portals List of tuples with 5 values: fromx, fromy, to_universe, to_x, to_y
individuals List of tuples with 6 values: name, radius, x, y, dx, dy
Individuals are listed for a specific universe only. This is their home universe. When the simulation
starts, the individual is also located in this universe in the initial x, y coordinates.
The details of the simulation are given below. We recommend you implement slowly, reading each
step and implementing it first. Think where the implementation should fall? A member function
for universe or person classes, a function in your main program or simple code? Give yourself plenty
of time to make changes to your program as needed.
Happy implementation!
CS1 Multiverse: Detailed Problem Description
Create the class files Universe.py and Person.py containing class descriptions as described above.
Write a program stored in file hw8.py and import both classes into this file:
from Person import *
from Universe import *
Then, ask the user a single file name to read all universe and individual information:
Input file => file1.txt
file1.txt
You can read the whole info using a single line of code as before:
data = json.loads(open(fname).read())
Using the data provided, create and store people and universe information in your program. Print
out the main information for each universe and each individual first.
All universes
----------------------------------------
Universe: EasyCS1 (4 rewards and 0 portals)
Rewards:
at (40,60) for 10 points: instant set knowledge
at (100,200) for 40 points: bonus 5 points on one homework
at (200,400) for 30 points: instant knowledge of list comprehension
at (600,800) for 50 points: good variable name generation ability
Portals:
None
All individuals
----------------------------------------
Scientist of EasyCS1 in universe EasyCS1
at (20,30) speed (20,30) with 0 rewards and 0 points
Engineer of EasyCS1 in universe EasyCS1
at (600,800) speed (-40,-10) with 0 rewards and 0 points
Note: There are 40 dashes in the underline and a 4 space indent when printing individuals.
Now, start simulation and repeat each step below until 100 steps are reached, or no individuals are
moving. At each step:
1. Increment the simulation counter.
2. Move all individuals in the order they are given in the input file by adding their dx, dy to
their current location.
3. If an individual stops because their center is at or past the edge of the board, print a message.
Archie stopped at simulation step 33 at location (1005.0,340.0)
4. For each individual, check if they are able to reach a reward (i.e., the distance between their
current location and the location of a reward in their current universe is less than or equal to
the radius of the individual).
If so, individual picks up the reward and the reward is no longer available to anyone else.
Furthermore, the speed of the individual decreases according to the formula:
dx = dx - (n % 2)* (n / 6) * dx
dy = dy - ((n + 1) % 2)* (n / 6) * dy
where n is the current number of rewards the individual has.
Finally, print a message to show the reward that is picked and the individual’s current info.
Scientist picked up "good variable name generation ability" at simulation step 33
Scientist of EasyCS1 in universe EasyCS1
at (596.7,563.3) speed (8.3,13.3) with 3 rewards and 90 points
Remember that if the magnitude (absolute value) of a person’s speed drops below 10 in either
the x or y directions, she stops moving.
5. If the distance between two individuals is less than or equal to the sum of their radii, then
they crash. In this case:
Each individual drops the first reward in their list (if they have any rewards). The reward
goes back to its original location in the universe in which it originated.
The speed of the individual dropping a reward increases because their load is reversed and
reverses direction, given by:
dx = -(dx + (n % 2) * (n / 6) * dx)
dy = -(dy + ((n + 1) % 2)* (n / 6) * dy)
where n is the total number of current rewards for the individual after dropping the reward.
Print a message indicating the event.
Scientist and Archie crashed at simulation step 5 in universe IntersectionalCS1
Scientist dropped "instant set knowledge", reward returned to IntersectionalCS1 at
(80,80)
Scientist of IntersectionalCS1 in universe IntersectionalCS1
at (126.7,180.0) speed (-16.7,-30.0) with 0 rewards and 0 points
Archie of IntersectionalCS1 in universe IntersectionalCS1
at (120.0,225.0) speed (-20.0,-15.0) with 0 rewards and 0 points
6. Finally, if an individual is able to reach a portal (i.e., the distance between the individual’s
current location and the location of a portal is less than or equal to their radius), then the
individual passes through the portal and moves to the universe pointed by the portal. Print
an appropriate message.
Scientist passed through a portal at simulation step 9
Scientist of MediumCS1 in universe EvilCS1
at (200.0,200.0) speed (16.7,30.0) with 1 rewards and 10 points
When the simulation ends, print the step the simulation ended, the number of individuals still
moving at the end of the simulation, who is still moving, and the individual(s) with the highest
number of points and the rewards that they have.
Simulation stopped at step 48
0 individuals still moving
Winners:
Scientist of MediumCS1 in universe EvilCS1
at (850.0,1000.0) speed (16.7,20.0) with 2 rewards and 40 points
Rewards:
instant set knowledge
ability to create black hole in Python
When you have fully tested your program, submit it as described above.
For this homework, we will be giving you both input files and the output created by them (instead
of posting in PDF) so that you can test your code. Happy hunting for rewards!
To match the output: any indentation is 4 spaces. The line of hyphens is 40 characters long. Note
that you must print your input file name as always.
因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
微信:codinghelp
CSCI 1100 — Computer Science 1 Homework的更多相关文章
- Discovering the Computer Science Behind Postgres Indexes
This is the last in a series of Postgres posts that Pat Shaughnessy wrote based on his presentation ...
- [转载] A set of top Computer Science blogs
This started out as a list of top Computer Science blogs, but it more closely resembles a set: the o ...
- Computer Science Theory for the Information Age-4: 一些机器学习算法的简介
一些机器学习算法的简介 本节开始,介绍<Computer Science Theory for the Information Age>一书中第六章(这里先暂时跳过第三章),主要涉及学习以 ...
- Computer Science Theory for the Information Age-1: 高维空间中的球体
高维空间中的球体 注:此系列随笔是我在阅读图灵奖获得者John Hopcroft的最新书籍<Computer Science Theory for the Information Age> ...
- Intro to Computer Science Class Online (CS101) - Udacity
Intro to Computer Science Class Online (CS101) - Udacity Building a Search Engine
- MIT Introduction to Computer Science and Programming (Lesson one )
MIT Introduction to Computer Science and Programming (Lesson one ) 这篇文是记载 MIT 计算机科学及编程导论 第一集 的笔记 Les ...
- How do you explain Machine Learning and Data Mining to non Computer Science people?
How do you explain Machine Learning and Data Mining to non Computer Science people? Pararth Shah, ...
- Mathematics for Computer Science (Eric Lehman / F Thomson Leighton / Albert R Meyer 著)
I Proofs1 What is a Proof?2 The Well Ordering Principle3 Logical Formulas4 Mathematical Data Types5 ...
- Georgia Tech Online Master of Science in Computer Science 项目经验分享
Georgia Tech Online Master of Science in Computer Science 项目经验分享 Posted on 2014/04/22 项目关键词:工科名校,计算机 ...
随机推荐
- vue 报错总结
关闭vue-cli 默认eslint规则: 找到 build -> webpack.base.config.js ,删除箭头指向代码 1.Newline required at end of f ...
- 网络流24题——试题库问题 luogu 2763
题目描述看:这里 这是我们遇到的第一个要求输出方案的问题 考虑建图然后用最大流思想: 首先由源点向每一道试题连边,容量为1 然后由每一种试题类型向汇点连边,容量为需求量 最后由每一道试题向可能属于的试 ...
- C# .Net List<T>中Remove()、RemoveAt()、RemoveRange()、RemoveAll()的区别,List<T>删除汇总
在List<T>中删除主要有Remove().RemoveAt().RemoveRange().RemoveAll()这几个方法.下面一一介绍使用方法和注意点. 我们以List<st ...
- tensorflow建造神经网络-【老鱼学tensorflow】
上次我们添加了一个add_layer函数,这次就要创建一个神经网络来预测/拟合相应的数据. 下面我们先来创建一下虚拟的数据,这个数据为二次曲线数据,但同时增加了一些噪点,其图像为: 相应的创建这些伪造 ...
- Linux安装Tomcat-Nginx-FastDFS-Redis-Solr-集群——【第九集-补充-之安装mariadb】
由于也是第一次安装,再此不必献丑了,贴上参考链接: 1,指导我为什么使用mariadb而不是用mysql:https://blog.csdn.net/liumiaocn/article/details ...
- Yarn集群的搭建、Yarn的架构和WordCount程序在集群提交方式
一.Yarn集群概述及搭建 1.Mapreduce程序运行在多台机器的集群上,而且在运行是要使用很多maptask和reducertask,这个过程中需要一个自动化任务调度平台来调度任务,分配资源,这 ...
- Java中在实例化一个类时,这个类中没有初始值的int类型成员变量i,i的值是不是0?
java中有两种类型一种是数值性,另一种是类变量数值性变量的初始值为0,类变量的初始化为null没做初始化成员变量int性变量是0, 在java中有这么一条规则,声明在方法中的变量在使用时必须要初始化 ...
- Synergy简单使用小记
需求: 两台笔记本用两套键盘鼠标,那体验,糟透了. 怎样才能使得两个主机公用一套鼠标和键盘呢?上网搜索到Synergy这款软件 参考: 具体使用方法参考了这篇博文 基本使用: 这款软件分为服务端和客户 ...
- 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)
A. Alien Sunset 暴力枚举答案即可. #include<cstdio> int n,i,mx; struct P{ int h,r,t; bool night(int x){ ...
- Petrozavodsk Summer-2016. Ural FU Dandelion Contest
A. Square Function 留坑. B. Guess by Remainder 询问$lcm(1,2,3,...,n)-1$即可一步猜出数. 计算$lcm$采用分治FFT即可,时间复杂度$O ...