怎么办我创建这个程序 [英] How to do I create this program

查看:86
本文介绍了怎么办我创建这个程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PYTHON

• Design and program must be object-oriented.

• For each project there is a requirements section. You must follow the requirements section exactly! By follow exactly, I mean follow exactly, i.e. the names of the methods must be exactly as named in the requirements section (case included!), the order of the arguments to a method must be exactly as in the requirements section, etc.

• There must be NO graphics. These are all console applications.

• They should all be user-friendly and robust, being able to deal with user input errors; however, don’t go overboard, get it working first!

Project Descriptions

1. Cop and Robber.

Overview: We describe the 2-player game called "Cop and Robber". There are two players: one is the cop and the other is the robber. The game can be played on any graph (i.e. a set of vertices, and edges that connect them to make a network). The game is put into initial position by first allowing the cop to place herself at any vertex, followed by allowing the robber to place himself at any vertex. After the players have both placed themselves, the players alternate taking turns, with the cop starting. On a turn, a player can move from a vertex to an adjacent vertex, or remain at the same vertex. The cop wins if she ever occupies the same vertex as the robber. The robber wins if the cop gives up, or the number of moves more than some user inputed number (for example 25 moves).

Requirements: You must 1) create a class named CopRobGame, which will be described below, 2) create other classes as needed, which will all be known by the top level class CopRobGame, 3) write a simple console game (no graphics!) for the game using the class CopRobGame and a few simple calls to it. The class CopRobGame, must have at least the following methods (it may have more methods):

(a) The initializer takes one positive integer argument, which is the limit on the number of moves before the game is over (and the robber wins).

(b) createVertex: Takes a single string input as an argument and adds this vertex to the graph, attaching it to no other vertices.

(c) createEdge: Takes 2 strings as input, and creates an edge between the 2 vertices with those string names. If the 2 strings are the same, or one of the strings is not the name of a vertex, then no edge is created. If the edge already exists, nothing new is created. Returns the boolean True if a new edge was created, and False otherwise.

(d) placePlayer: Takes 2 strings as input. The first string should be either "C" or "R", to indicate Cop or Robber, respectively. The second string should be the name of a vertex. The indicated player is placed at that vertex.

(e) movePlayer: Takes 2 string inputs; the first should be either "C" or "R", to indicate Cop or Robber, respectively. The second string should be the name of the vertex to move the player to. The method should return True if the player was successfully moved there, and False if there was some problem.

(f) winCheck: Takes no inputs and returns one of 3 strings: "C" if the cop and robber occupy the same vertex; "R" if the number of moves is past the limit; and "X" if neither player has won yet.

(g) display: This creates a text output of the current state of the graph and the positions of the players (if they are placed), in a the following series of lines, each separated by a single newline character.

i. The string "Cop: " followed by the name of the vertex where the cop is; if the Cop has not been placed, then the string "Cop not placed." appears. Then there are some spaces, and an analogous printout for the Robber: "Robber: " followed by the name of the vertex where the robber is; if the Robber has not been placed, then the string "Robber not placed." ii. The string "Vertices: " followed by a comma separated listing of the vertices.

iii. The string "Edges: " followed by a comma separated listing of the edges, where each edge is of the form "( [vertex name], [vertex name])".

Example: The following code should print or return what is in the comments.

G = CopRobGame(10)

G.createVertex(’a’)

G.createVertex(’b’)

G.createVertex(’c’)

G.createVertex(’d’)

G.createEdge(’a’, ’b’)

G.createEdge(’b’, ’c’)

G.createEdge(’c’, ’a’)

G.createEdge(’c’, ’d’) # Returns True

G.createEdge(’d’, ’c’) # Returns False

G.placePlayer(’C’, ’c’)

G.placePlayer(’R’, ’a’)

print(G.winCheck()) # Prints ’X’

G.movePlayer(’C’, ’a’)

print(G.winCheck()) # Prints ’C’

G.display() # PRINTS WHAT FOLLOWS ...

Cop: a Robber: a

Vertices: a, b, c, d

Edges: (a,b) (b,c) (c,a) (a,d)





我的尝试:



i不知道怎么做..请帮我解决



What I have tried:

i dont know how to do it.. pleace help me out

推荐答案

Python教程 - Python 3.4.9文档 [ ^ ]


我们不做你的作业:它是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是像你想的那么难!坐下来,想一想这个问题,手动在纸上试试,直到你的想法在脑海中排序。然后考虑一下您需要存储哪些数据,它来自何处,以及您需要使用它做什么。如果你想几分钟,这不是一个难题!



如果你遇到一个具体的问题,那么请问一下这个问题我们会做我们最好的帮助。但是我们不打算为你做这一切!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think! Sit down, and think about the question, try it on paper manually, until you have the idea sorted in your mind. Then think about what data you need to store, where it comes from, and what you need to do with it. This isn't a difficult problem, if you think about it for a few minutes!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


引用:

我不知道如何要做到这一点。

i dont know how to do it.



它开始是一个相当先进的项目(对于学校来说),但对于专业程序员来说仍然很简单。你不能只是不知道该怎么做或混淆,或者你所遵循的课程有问题,你可能需要和你的老师谈谈。



编程不仅仅是用一种语言编写代码,在此之前,你的工作是分析需求,并推导出组织,数据结构和算法。

学习一些分析方法是一个好主意,EW Djikstra / N. Wirth Stepwize Refinement / top-Down方法是一个良好的开端。

Structured Programming.pdf [ ^ ]

https://en.wikipedia。 org / wiki / Top-down_and_bottom-up_design [ ^ ]

https://en.wikipedia.org/wiki/Structured_programming [ ^ ]

https://en.wikipedia.org/wiki/Edsger_W._Dijkstra [ ^ ]

https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF [ ^ ]

- 学习算法和数据结构。


It start to be a rather advanced project (for school), but still simple for a professional programmer. You can't just "don't know how to do it" or be confused, or there is a problem in the course you follow, you may have to speak with your teacher.

Programming is not just writing some code in a language, before this, your job is to analyze the requirements, and deduce organization, data structures and algorithms.
learning some analyze methods is a good idea, E.W. Djikstra/N. Wirth Stepwize Refinement/top-Down method is a good start.
Structured Programming.pdf[^]
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]
- Learn Algorithms and Data-Structures.


这篇关于怎么办我创建这个程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆