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的更多相关文章

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

  2. [转载] 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 ...

  3. Computer Science Theory for the Information Age-4: 一些机器学习算法的简介

    一些机器学习算法的简介 本节开始,介绍<Computer Science Theory for the Information Age>一书中第六章(这里先暂时跳过第三章),主要涉及学习以 ...

  4. Computer Science Theory for the Information Age-1: 高维空间中的球体

    高维空间中的球体 注:此系列随笔是我在阅读图灵奖获得者John Hopcroft的最新书籍<Computer Science Theory for the Information Age> ...

  5. Intro to Computer Science Class Online (CS101) - Udacity

    Intro to Computer Science Class Online (CS101) - Udacity Building a Search Engine

  6. MIT Introduction to Computer Science and Programming (Lesson one )

    MIT Introduction to Computer Science and Programming (Lesson one ) 这篇文是记载 MIT 计算机科学及编程导论 第一集 的笔记 Les ...

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

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

  9. Georgia Tech Online Master of Science in Computer Science 项目经验分享

    Georgia Tech Online Master of Science in Computer Science 项目经验分享 Posted on 2014/04/22 项目关键词:工科名校,计算机 ...

随机推荐

  1. 再说C模块的编写(2)

    [前言] 在<再说C模块的编写(1)>中主要总结了Lua调用C函数时,对数组和字符串的操作,而这篇文章将重点总结如何在C函数中保存状态. 什么叫做在C函数中保存状态?比如你现在使用Lua调 ...

  2. ECMAScript 6中数组新方法

    数组的方法 数组的的大部分方法都可以实现数组的遍历. foreach方法 实现数组的遍历 const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; arr.forEach(fu ...

  3. post 数据

    可参照:http://www.voidcn.com/blog/Vindra/article/p-4917667.html 一.get请求 curl "http://www.baidu.com ...

  4. IIS 支持 m3u8

    加上俩 MIME 类型就可以了 <mimeMap fileExtension=".m3u8" mimeType="application/x-mpegURL&quo ...

  5. celery使用

    1.常用命令 (1)启动后台职程 celery worker -A tasks --loglevel=info celery worker -A tasks --loglevel= -A 是指cele ...

  6. 配置ubuntu的超管账号密码

    1 在搭建ubuntu 之后 只有自己的账号 2 root 用户是没有配置好的 需要重新配置 3 passwd root 4 输入新密码即可

  7. UVA 10474 - Where is the Marble?--vector

    https://vjudge.net/problem/UVA-10474 https://blog.csdn.net/xiyaozhe/article/details/81081344 简单用法 so ...

  8. DDoS攻击与防御(3)

    3.攻击应用资源网络应用和服务在处理数据时,通常需要消耗一定的网络连接.计算和存储资源,这些资源是由应用程序向系统进行申请并自行管理和维护的.消耗应用资源的DDoS攻击就是通过向应用提交大量消耗资源的 ...

  9. Django 学习第十一天——中间键和上下文处理器

    一.中间键的引入: Django中间件(Middleware)是一个轻量级.底层的"插件"系统,可以介入Django的请求和响应处理过程,修改Django的输入或输出. djang ...

  10. bzoj3124: [Sdoi2013]直径 树形dp two points

    题目链接 bzoj3124: [Sdoi2013]直径 题解 发现所有直径都经过的边 一定在一条直径上,并且是连续的 在一条直径上找这段区间的两个就好了 代码 #include<map> ...