Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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 gameis pu into initial position by first allowing the cop to place berself at any vertex, followed by allowing the robber to place himself at any vertex. After the playens 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 umber of moves more than some user inpated number (for example 25 moves). Requirements: You must 1) create a class named CopRobGame, which will be described belkow, 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 umber of oves before the game is over (and the robber wins) (b) createVertex: Taks a singke string input as an argament 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 ot herwise (d) placePlayer: Takes 2 strings as input. The first string should be either Cor R",to indicate Cop or Robber, respectively. The second string should be the name of a vertex. The indicated player B placed at that vertex. (e) novePlayer: Takes 2 string inputs; the first should be either or R to indicate Cop or Robber, respectively. The second string should be the name of the vertex to move the ?layer to. The method should return True if the player was successfully moved there, and False if there was some problem (f) vinCheck: Takes no inputs and returns one of 3 stringsC if the cop and robber oceupy the same vertex:R" if the mamber of moves is past the limit; and "X" if neither player has won yet (R) diaplay: 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, cach 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." appeats. The 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 ollowed by a comma separated listing of the vertices ii. The string "Edges followed by a comma separated listing of the edges where each elge is of the form "( ivertex name, [vertex name) 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 gameis pu into initial position by first allowing the cop to place berself at any vertex, followed by allowing the robber to place himself at any vertex. After the playens 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 umber of moves more than some user inpated number (for example 25 moves). Requirements: You must 1) create a class named CopRobGame, which will be described belkow, 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 umber of oves before the game is over (and the robber wins) (b) createVertex: Taks a singke string input as an argament 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 ot herwise (d) placePlayer: Takes 2 strings as input. The first string should be either Cor R",to indicate Cop or Robber, respectively. The second string should be the name of a vertex. The indicated player B placed at that vertex. (e) novePlayer: Takes 2 string inputs; the first should be either or R to indicate Cop or Robber, respectively. The second string should be the name of the vertex to move the ?layer to. The method should return True if the player was successfully moved there, and False if there was some problem (f) vinCheck: Takes no inputs and returns one of 3 stringsC if the cop and robber oceupy the same vertex:R" if the mamber of moves is past the limit; and "X" if neither player has won yet (R) diaplay: 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, cach 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." appeats. The 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 ollowed by a comma separated listing of the vertices ii. The string "Edges followed by a comma separated listing of the edges where each elge is of the form "( ivertex name, [vertex name)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

1. Design an effective socialization program for employees.

Answered: 1 week ago