” 辅导CSCI-UA.0101编程、 写作Java课程编程CSCI-UA.0101-005: Project 1Part 1: Warmup 40 pointsIn this first part you will extend the game of life code to support additional features.(1) (10 points) Refactor the method countAliveNeighs. Instead of having a loop to retrievethe x, y-coordinates of the 8 neighbors; add a new method int[][] getNeighs(boolean[][]alive, int i, int j) to retrieve them. This change should affect only the body of countAliveNeighs.(2) (20 points) Extend the code to support different rules. Change the update method to alsoreceive two arrays containing the numbers of required neighbors for a cell to survive or die.Example where a cell is born if it has exactly 3 neighbors, survives if it has 2 or 3 livingneighbors, and dies otherwise:int [ ] born = {3 };int [ ] s u r v i v i n g = {2 , 3 };while ( true ){p r i n t ( a l i v e ) ;update ( a l i v e , born , s u r v i v i n g ) ;. . .}(3) (10 points) Change the program to receive command line arguments to decide the size of thegrid and the rules for a cell to survive or die. For instance, java GOL 10 B3/S23 runs thegame of life on a 10 10 grid with the rule B3/S23. That is, a cell is born if it has exactly 3neighbors and survives if it has 2 or 3 living neighbors.1CSCI-UA.0101-005 Project 1 (Page 2 of 3)Figure 1: Example of an hexahedral grid.Figure 2: Example of a print of 20 20 grid.Part 2: Hexagonal game of life: 80 pointsIn this second part you will extend the game of life to run on a hexagonal grid. A hexagonal gridcan be stored as a normal grid where every row is shifted by half left and right (Figure 1). Formore information visit this page. To start, just copy your current game of life code.(1) (40 points) Change the print code to visualize a hexagonal grid. Use the characters /, \, and| to visualize the grid and use to illustrate if a cell is alive (Figure 2).(2) (30 points) Change the method int[][] getNeighs(boolean[][] alive, int i, int j)to retrieve the x, y-coordinates of the 6 neighbors of a cell at position i, j (instead of 8 as inthe square grid).(3) (10 points) Now your code supports input grid size and rules for both a hexagonal and squaregrid. Implement a new class to accept an optional user parameter hex to decide which grid torun, e.g., java GOL 30 B2/S2 hex will run on an hexagonal grid while java GOL 30 B2/S2on the square one. Important, the new class must call the main methods of the other twoclasses.CSCI-UA.0101-005 Project 1 (Page 3 of 3)Question Points Bonus Points ScoreWarmup 40 points 40 0Hexagonal game of life: 80 points 80 0Total: 120 0如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。