Programming challenge: Connect ZJun 06, 2018CONTENTS:1 Programming Challenge - Connect Z 11.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Challenge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Program specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.4 Input file specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.5 Impossible games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.6 Output specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.7 Assessment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.8 Submission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Appendix - Sample Test Cases 52.1 Draw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 Win for player 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.3 Win for player 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.4 Incomplete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.5 Illegal continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.6 Illegal row . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.7 Illegal column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.8 Illegal game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.9 Invalid file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8iiiCHAPTERONEPROGRAMMING CHALLENGE - CONNECT Z1.1 BackgroundThis programming challenge is based on the classic game of Connect Four. In a game of Connect Four, two playerstake turns to drop coloured counters into a vertical frame. The first player to achieve a horizontal, vertical or diagonalline of four or more counters of their own colour wins the game. Games can also result in a draw if the frame fills upwith counters before either player can complete a line of four or more counters.The following resources provide more detailed background information on how Connect Four works: http://www.wikihow.com/Play-Connect-4 https://en.wikipedia.org/wiki/Connect_Four1.2 ChallengeYour goal is to implement a game checker program for Connect Z. In Connect Z the concept of the traditional gameof Connect Four is generalized to include playing frames of any size and a target lines of any length. When providedwith a data file that describes a game of Connect Z your checker program should determine if that game was won,drawn or contains an error of some kind. The format of the data files and expected output is described in detail below.1.3 Program specification This challenge should be written in Python 3. The reference implementation that will be used to assess thesubmission is Python 3.6. Third party libraries are not allowed. The challenge should be completed using only features provided by thestandard libraries. https://docs.python.org/3/library/index.html The game checker should be submitted as a Python script called ‘connectz.py’. The script will read input from a datafile which is a pain ASCII textfile. This script takes a single argument ‘inputfilename’ which is the name of the data file containing game informationto be checked. The script will be called as:python connectz.py inputfilename If the game is run with no arguments or more than one argument it should print the following message as asingle line to standard out.1Programming challenge: Connect Zconnectz.py: Provide one input file1.4 Input file specificationYour program will be supplied data files that describe games of Connect Z. The data file includes both the dimensionsof the game being played and the moves that were made. The specifics are as follows: The input should be a plain text file consisting of one or more lines of ASCII characters. The first line of the file is required and describes the dimensions of the game in the format:X Y Z X, Y and Z are each positive integers separated by whitespace:X represents the width of the frame in columns;Y represents the height of the frame in rows;Z represents the minimum number of counters in a straight line required to win the game.For example the classic game of Connect 4 is played on a 7 by 6 frame with 4 counters in a line required to win. Thiswould be represented in the inProgramming留学生作业代写、代做Python程序语言作业、代写Python实验作业、Illegal contiput format as:7 6 4After the game dimensions line, each subsequent line of the file represents a single move in the game. Starting withplayer one, lines alternate between player one and player two indicating the moves that they made. A move is describedby a single positive integer which represents the column the player chose to drop their counter in. The file should endafter the game is won or drawn. Additional moves should be detected as an invalid game.For example in a classic Connect 4 game, if the first player has a strategy to always select column one and the secondplayer always selects column two, the the first player will win on the seventh move, with a vertical line in column one.The complete game file would be as follows:�1.5 Impossible gamesNote that using the input format it is easy to describe games that would be impossible to win. For example:2 4 6represents a game that can never be won, since a line of length 6 on a 2 by 4 frame could never be achieved. Situationslike this should be detected as invalid game. See the output specification.2 Chapter 1. Programming Challenge - Connect ZProgramming challenge: Connect Z1.6. Output specification 31.6 Output specification The output of the program should be a single integer printed to standard out. The integer is a code which describes the input. Output codes 0 - 3 are for valid game files. Output codes 4 - 9 represent errors.The codes are defined as follows:Code Reason Description0 Draw This happens when every possible space in the frame was filled witha counter, but neither player achieved a line of the required length.1 Win for player 1 The first player achieved a line of the required length.2 Win for player 2 The second player achieved a line of the required length.3 Incomplete The file conforms to the format and contains only legal moves, butthe game is neither won nor drawn by either player and there areremaining available moves in the frame. Note that a file with only adimensions line constitues an incomplete game.4 Illegal continue All moves are valid in all other respects but the game has alreadybeen won on a previous turn so continued play is considered anillegal move.5 Illegal row The file conforms to the format and all moves are for legal columnsbut the move is for a column that is already full due to previousmoves.6 Illegal column The file conforms to the format but contains a move for a columnthat is out side the dimensions of the board. i.e. the column selectedis greater than X7 Illegal game The file conforms to the format but the dimensions describe a gamethat can never be won.8 Invalid file The file is opened but does not conform the format.9 File error The file can not be found, opened or read for some reason.1.7 AssessmentWe will judge your submission on a number of criteria. Firstly we will run your program against our set of test inputcases. These will test all of the output conditions we have defined. Note that also some of our input files may be verylarge so we will be looking at the efficiency and optimisations made in your solutions. Finally we will also look atyour coding style. We pay particular attention to clear and sensible naming of variables and functions. Bonus pointsfor well commented code!Programming challenge: Connect ZYou may additionally submit a readme.txt file containing a summary of your solution, how you approached the problem,what you found challenging / easy. What you would like to improve and any other part of your solution youwould like to draw our attention too.If you create an additional files as part of implementing your solution feel free to include these as well and explainwhat they are for in your readme.txt4 Chapter 1. Programming Challenge - Connect ZCHAPTERTWOAPPENDIX - SAMPLE TEST CASESThis appendix contains sample test cases that you can use as a starting point to check your program is logically correct.Please note that these test cases are not exhaustive and we will run your program additional test cases to those describedhere.We strongly recommend supplementing the test cases provided here with some of your own.2.1 Draw2.1.1 input�2.1.2 output2.2 Win for player 12.2.1 input�5Programming challenge: Connect Z2.2.2 output2.3 Win for player 22.3.1 input�2.3.2 output2.4 Incomplete2.4.1 input2.4.2 output�2.5 Illegal continue2.5.1 input�(continues on next page)6 Chapter 2. Appendix - Sample Test CasesProgramming challenge: Connect Z(continued from previous page)2.5.2 output�2.6 Illegal row2.6.1 input�2.6.2 output�2.7 Illegal column2.7.1 input�2.7.2 output�2.6. Illegal row 7Programming challenge: Connect Z2.8 Illegal game2.8.1 input�2.8.2 output2.9 Invalid file2.9.1 input banana2.9.2 output8 Chapter 2. Appendix - Sample Test Cases转自:http://www.7daixie.com/2019051221714041.html