Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can You help Gary get home?? FAIL GAKS REMEMBER? ca HAVE YOU SEEN GARY HG I'I SOR Missing Gary Gary the snail is lost and

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Can You help Gary get home?? FAIL GAKS REMEMBER? ca HAVE YOU SEEN GARY HG I'I SOR Missing Gary Gary the snail is lost and scared in Bikini Bottom. Can you help Gary get home?? Project 1 Background: Project 1 will see students impliment a solution to "Langton's Ant", a cellular automata existing on a 2 Dimensinal N by N grid where each grid cell is colored white or black and the "ant' cell can be described as one of eight states (cell color + ant orientaiton). Rules of Langton's Ant Note that the rules are slightly modified for our purposes Initialize an N by N squre grid (note that N must be an odd integer) of cell types that are either white or black. Start the "Ant" (or Gary the snail in our case) at the center of the grid. Start Gary in an "up" orientation. Perform K steps where each step follows a simple rule: 1. If Gary is on a white squre turn 90 deg clockwise, flip the color of the squre, and move forward one unit 2. If Gary is on a black squre turn 90 deg counterclockwise, flip the color of the squre, and move forward one unit. Links/References to Langton's Ant Below you will find links for more informatin on Langton's Ant. Note that there are many solutions to this problem available on the internet but we will design to a specific set of criteria and it will be impossible to copy-paste a solution Langton's Ant Wikipedia Langton's Ant WolteamMathworld Coding Challenge Video: Langton's Ant in Pythan) Below you will find examples of Langton's Ant in various programming languages (since y'all wil Google this anyways). Note that these will probably not be very helpful... Langton's Antimplimentation in Python Langton's Ant implimentation in C++ Langton's Ant Rosetta Code Langton's Ant solution in C++ Langton's Ant Ctt solution in REPL The above links might be helpful conceptually but do not impliment Langton's Ant in accordance with the design guidelines for Project 1. Cell Class: This class will be used to define the Nby Nboard in the final solution (there will be 2 cell objects which define the board). You are to program the cell class according to the following design critela: CellColor The Cell class shall store the cell's color as a private member variable named color of type Cellcolor where Cellcolor is an enumaration data type defined as enum class Cellcolor {white, black}; Constructor The Cell class shall be construced using the default constructor, i.e., will not accept any arguments. The constructor shall set color to white upon construction Cell Color Mutator The cell class shall contain a public member function named change_color to toggle the color member. I.e., if color is currently set to white , calling change_color() will change color to black . The member function change_color will return type void and will accept no input parameters. Cell Color Accessors The cell class shall contain two "getter" functions to access color (1) shall be named get_color, shall return type Cellcolor , and shall accept no input parameters. get_color shall return the value of cell 's color member. (2) shall be named get_color_string , shall return type std::string, and shall accept no input. get_color_string shall return "1" it color is black and shall return "O" if color is white. Board Class: The Board class has the following requirements: 1. The Board class shall be constructed given an unsigned integer parameter that defines the number of rows and columns, i.e., 'N' in the N by N board. Note that N must be odd. If N is given as even, students shall display a message stating "Board dimension must be an odd number!! Got {N} and adding 1 to equal {N+1}" (note that parameters within { } must be printed as their values) and shall add 1 to N to satisfy the requirement that N must be odd. Note that this message must be printed only to the console, i.e., should not be printed to the output file. 2. Gary shall move around the board when the Gary::move_gary (unsigned int steps ) function is called. Each step shall be one step of Langton's ant as defined above, i.e., change Gary's orientation based on the Cell input, change the cell color, and move Gary forward one unit. The board class shall print the state of the board at every step. See the below example with a board Size input of 5 for 10 steps: (Gary Location (2, 2) (Gary Orientation) up (ROU O OOO O O [Row 1) O OOO (Row 2] 0 0 0 0 (Row 3) 0 0 0 0 0 (Row 4) 0 0 0 0 0 (Gary Location (2, 3) (Gary Orientation right (Row OJ 0 0 0 0 0 (Row 1] 0 0 00 O [Row 2) 00100 [Row 3) O O O O O [Row 4) OOOOO (Gary Location) (3, 3) (Gary Orientation down (Row O O O O O O [Row 1) 0 0 0 0 0 (ROU 2) 0 0 1 1 0 [Row 3] 0 0 0 0 0 (Row 4) 0 0 0 0 0 (Gary Location) (3, 2) (Gary Orientation) left (Row O] 0 0 0 0 0 (Row 1) 0 0 0 0 [Row 2) 0011 0 [Row 3] 0 0 0 1 0 [Row 4) 0 0 0 0 0 (Gary Location (2, 2) (Gary Orientation up ( Bow O OOOOO [Row 1] O O O O [Row 2) 0011 0 ( Row 3) 0 0 1 1 0 [Row 4) 0 0 0 0 0 (Gary Location (2, 1) (Gary Orientation) left (Row OJ OD 0 0 0 Row 1) O O O 0 0 (ROU 2) 0 0 0 1 0 [Row 3] 0 0 1 1 0 [Row 4) 0 0 0 0 0 (Gary Location (1, 1) (Gary Orientation up ( Bow O OOOOO [Row 1] O O O O [Row 2] 0101 0 (Row 3] 0 0 1 1 0 [Row 4) 0 0 0 0 0 (Gary Location (1, 2) (Gary Orientation right (Row OJ 0 0 0 0 0 (Row 1] 0 1 0 0 0 (Row 2] 01010 [Row 3) 0 0 1 1 0 [Row 4) 0 0 0 0 0 (Gary Location) (2, 2) (Gary Orientation) down (ROW O] 0 0 0 0 0 (Row 1] 0 11 0 [Row 2) 0 1 0 1 0 [Row 3] 0 0 1 1 0 [Row 4) 0 0 0 0 0 (Gary Location (2, 1) (Gary Orientation left (Row O O O O O O (Row 1] 0 11 0 0 (Row 2) 0 1110 [Row 3) 0 0 1 1 0 [Row 4) 0 0 0 0 0 (Gary Location) (3, 1) (Gary Orientation down (Row OJ OD 0 0 0 Row 1) 0 1 1 0 0 (Row 2) 0 0 1 1 0 [Row 3) 0 0 1 1 0 [Row 4) 0 0 0 0 0 the format is givn by [Gary Location] (from), (col)) (orientation) [Row] (colo color) (col 1 color) ... (col N-1 color) [Row 1] ... [ROW (N-1)] ... (col N-1 color) where values within () are to be filled in with program values. (col i color) shall be either "O" for "White" or "1" for "black". Note that students may want to call cell::get_color_string() to print this value. This output will either be to standard output, i.e., std::cout, if a filename command line argument is not provided or will be printed to the filename given in the argument (students should use the ofstream object for file output. Note that C's fprintf will also be okay). The filename shall be set with the setOutputFilename member function. Students are free to impliment the remaining functionality of the Board class as desired. The class should store a representation of the actual grid of cells which define the environment for Langon's antie., the Cell class (Hint: utilized a vector of vectors where each element of the outer vector stores a "row" or the grid represented by a vector of class Cell). The board class must also store a variable of type Gary that "walks about the board. (More information on Gary is given below) At each step in the Gary::move_gary(Cell) function the Board must pass a pointer to the cell that Gary currently occupies so that Gary can alter his orientaiton, flip the color of that cell, i.e., call the change_color member function, and change his position, i.e., "walk" (find a tutorial for pointers to objects here) Gary Class: Note that the Gary class is subject to C++ unit testing and therefore has stricter requirements for composition. Each required member function will be denoted. 1. Gary shall be constructed with a parameterized constructor accepting an unsigned integer input parameter representing the size of the board (denote here as BoardSize). Assume that BoardSize is odd! Gary shall initialize his position to be the middle cell of the board, e.g., in the BoardSize is given as 5 Gary would be initialized at index (2.2). 2. Gary shall contain public member functions which return an unsigned integer type and accept no input named Gary: get_row() and Gary!! get_colo) which return Gary's row and column position on the board respectively. 3. Gary shall contain a public member function which returns type void and accepts a Cell pointer called Gary!! nove(cello) which shall (a) alter Gary's orientation based on the Cell's color (D) change the Cell's color (c) move Gary one unit forward in the new orientation 4. Gary shall contain a public member function which returns type orientation (defined in definitions.hpp as an enumeration enum class orientation (up, right, down, left); ) and accepts no input parameters called Gary: get_orientation() Additional Classes: Feel free to impliment additional structs/classes/ methods in your solution. These must be compilable, i.e., fit into how I'm compiling with CMake so you may add things to src/lib/definitions.hpp or within, eg., src/cell/Cell.hpp , but you may not add additional files. Please see the instructor for any compiler errors with adding additinal material. Main Program: The main function will be compiled into an executable named Find Gary. The main function shall accept two (2) or three (3) command line arguments and will be called either as ./FindGary Boardsize Steps or ./FindGary Boardsize Steps OutputFilename where Boardsize and Steps will be unsigned integer values and OutputFilename will be a char array. The main program should construct a Board object optionally shall set the output filename it given as a command line argument, and shall execute Gary's movement through Board's member function. Main Program's grading: Student's main program will be used to generate output files. These output files will be compared to the solution output files and also to output files generated through instructor code, i.e., C++ code that will call the appropriate members of the Board class with the appropriate command line arguments. Students are free to impliment their main program however they like but the output must be correct according to the solution) and must match the output using student's Board class. Pseudocode for generating the output files from the instructor's end is shown below #include "Cell.hpp" #include "Board. hpp" #include "Gary.hpp int main(int arge, char** argv) { unsigned int boardSize = (fron command line arguments) unsigned int numberSteps = (from command line arguments) std::string output Filename = (from optional command line argument) Board Biboardsize); if (an output filename is given) B.setOutputFilename (output Filename); ) B.move_gary (numberSteps); return 0; and student code must be capable of generating the correct output in the correct location when calling these member functions of the Board class. Please note that the only "pseudo" above is the parsing of command line arguments and the it statement - the member functions and construction of variable B of type Board is valid Ch+ syntax that is used during testing. Testing Framework: Project Requirements Overview: Firsly the cell class will be tested for correct composition (i.e., color is a private member) and functionality default construction, change color) The Cary class will be tested independantly via another unit testing executable. This wil test Gary's functionality by "placing" him on an infinate "board" and performing random movement operations. The behavior will be tested against the expected behavior. Project 1 will also be tested via output-comparison tests as in previous homework assignments The output comparison will be run against output produces from your FindGary.cpp file and against a solution file which impliments the correct main function (I.e., is the implimented pseudocode above)

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

2. What potential barriers would you encourage Samuel to avoid?

Answered: 1 week ago

Question

6. How would you design your ideal position?

Answered: 1 week ago