当前位置:天才代写 > C++/C代写,c语言代写代考-100%安全,包过 > C 语言编程代写 Programming in C代写

C 语言编程代写 Programming in C代写

2021-12-24 11:59 星期五 所属: C++/C代写,c语言代写代考-100%安全,包过 浏览:482

COSC2138 (CPT220) – Programming in C 

Assignment 2 – Word Puzzle Game Part 1

C 语言编程代写 In this assignment you need to implement a interactive menu system that implements some functionality through which you can

In this assignment you need to implement a interactive menu system that implements some functionality through which you can show off your uber skills. Do not leave this assignment to the last minute as you are likely to be faced with bugs that are not so easy to resolve when you are in a rush.

The concepts covered in this assignment include:

  • All concepts covered in assignment 1
  • Dynamic memory allocation and freeing such memory
  • File reading and writing
  • Use of dynamic arrays

Please ensure that you ask questions early to resolve problems so that you are not wasting time as this assignment for many of you will involve substantial effort although I have tried to make this assignment as simple as possible while still meeting the learning outcome requirements.

Please also note that the discussion board is required reading. The discussions there have an impact upon your marks so if you are not reading then you will miss out on that information.

 

Plagiarism  C 语言编程代写

Plagiarism is the act of copying another’ s work and representing it as your own. As part of all submissions you make in this course you agree that all work contained therein – other than the start-up code – is your work. Any code included from others must be properly referenced – for the purposes of this course this means providing a comment in your code that outlines what code you have copied, from where (author, url or textbook), and date that it was accessed if it is an online resource. Failure to follow this guideline can result in facing school discipline hearings. We will run automated software to check for plagiarism / similarity. This includes code you have copied from the provided courseware.

 

Note:

This assignment specification has a lot of detail. This specification is both an assignment specification and documentation of the codebase that I have provided to you. You’ll probably need to read through this a couple of times and ask questions on Canvas to understand the assignment completely. A large part of being a software developer is reading and interpreting documentation. The first thing that course staff will ask is if you have read the specifications, relevant lecture slides and relevant posts from other students and clarifications made by the instructor. If you have not done this, this is the first thing we will ask you to do. Reading is an important part of being a software developer!

 

Part A: Debugging Assessment (10 marks)  C 语言编程代写

Please see the separate document about the debugging assessment.

Compilation Requirements

The programs you submit for this course must compile without errors or warnings on the provided servers (jupiter, titan or saturn) using the following command:

gcc -ansi -Wall -pedantic board.c game.c players.c rules-2.c [any additional .c files you create] -o wuzzle-b

Finding the startup code

You may find the startup code on the servers (titan, jupiter, saturn) in ~e70949/shared/prog_in_c/assignments/a2b

Please note that on top of the ones provided you will need to create some of your own. In particular you will need to use the clear_buffer() function provided in assignment 1. We have provided much more freedom in this assignment but that will require you to take more responsibility for the design of your program.

 

Part B: Basic game implementation.  C 语言编程代写

You are to implement a dynamic game board and game play for a game called “wuzzle”. Wuzzle is a game played on a 2-dimensional grid of letters which starts off blank and as each player has their turn, they can either lay a word on the table or quit the game (with ctrl-d / enter). At the beginning of the game, each player gets five tokens they can play (letters). Each word placed on the board other than the first word placed must use at least one letter that is already on the board.

That letter becomes claimed by the player that made that move and its colour on the board should change accordingly. At the end of each move the new score for the players will be calculated and displayed. The player pointers will be swapped (see more about this later) for the next move. The game ends when one of the players quits and the player with the highest score at that point wins.

Data structures

For this game, the following data structures have been provided:

struct game {

struct player players[NUM_PLAYERS];

int curr_player_num; /* the index of the players array that holds the current player */

struct board * the_board;

struct letter_list * score_list;

};

Which holds the data about the game in play. At the start of the game you will prompt for the player information and construct a board of the size requested. The board may be any width or height greater than or equal to 5 characters wide / high.  C 语言编程代写

Here is the board structure: 

struct cell {
  struct player* owner;
  int letter;
};

A ‘cell’ represents the the contents of each entry of the board matrix where the owner pointer will be set to NULL for an empty cell and otherwise to the address of the owning player for a cell that contains a letter. Please note that letter here is an integer as it is common to represent letters using an int to allow for the EOF value to be set. A blank cell should also therefore have the ‘letter’ set to EOF. You can use either of these to check for a blank cell.

The board itself is represented using the following structure:

struct board {
  struct cell** matrix;
  int width;
  int height;
};

where matrix is a dynamic array where you need to malloc once for the height and then malloc each row. This means the first dimension of the array will be the row index and the second dimension will be the column index.

As per the previous assignment, we have provided the BOOLEAN type enumeration as follows:

typedef enum {FALSE, TRUE} BOOLEAN;

Finally, there is the score list. This is defined in the file score_list.h as follows:

struct score {
  int letter, score, count;
};

struct score_list {
  struct score scores[NUM_SCORES];
  int num_scores;
  int total_count;
};

So, a score has the letter that it represents and the score as a numeric integer. A reminder here seems appropriate that chars are just small integers and so we are using integers here for the letters and this is a common approach in C.  C 语言编程代写

These are pulled together into an array list of scores in the score_list structure. The maximum number of scores is 26 as that’s the letters in the alphabet. You will load these scores up from a file and deal the letters out from this list to each player’s hand that is also represented as a list of this type.

We’ve also provided the move_result enumeration in the player module so you can indicate from player_turn() the desire of the player to skip the current turn or exit the program.

It is defined as:

enum move_result {
  MOVE_QUIT,
  MOVE_SKIP,
  MOVE_SUCCESS,
  MOVE_BOARD_FULL
};

For validation of moves, the following two data structures have been provided:

struct coord {

   int x,y;

};

and

enum orientation {
  HORIZ,
  VERT
};

which you can parse the string inputs from the player turn so these can be more convenient for validation.

 

Part B Implementation Requirements – 70 Marks  C 语言编程代写

Please note that while I may specify a function that needs to be implemented, you can (and should) break down the function into smaller parts and put those parts in their own function. Please consider when writing your own functions where a suitable location for such functions might be. There may be small deductions for not doing this. Also note we are not going to be as hard about not modifying the startup code as we were in assignment 1.

In assignment 2, there are marks provided as part of this submission for design justifications for any additional files you create and any modifications you make to the provided files. These must be provided in terms of good software design – a justification that you did not understand the startup code will not be accepted as you can always ask for explanation. This means that not all required files are provided as part of the startup code. That’s known and it’s expected that you will create those additional files.

Please also note that most requirements are marked according to a 5 point scale:

  • Excellent: full marks. You have implemented this requirement as we haverequired.
  • Good: 75% of marks: There are minor issues such not doing propervalidation or minor memory problems but it’s still reasonably good. There is often queries from students as to why they have lost 25% of marks for such minor issues. The reason is that these issues matter and by using this same scale for everyone it increases the chance that marking is consistent.
  • OK/Fair: 50% of marks. There are major problems but it does the basic job. So examples of this might be that it sometimes runs correctly but mostly not.
  • Poor: You gave this a try but your solution is very far from what we wanted. Examples of this might be compiler errors or crashing every time or the program freezing.
  • No effort: You did not attempt this requirement or it is the judgement of your marker that no significant effort has been made. Eg: just declaring some variables but not doing any of the work on the required algorithm.

In all cases if you do not get full marks, feedback should be provided explaining what you did wrong and if that is not the case, you are encouraged to email your marker (reply to the results email) to ask follow-up questions.

 

Part B Requirement 1: Command Line Arguments (3 marks)  C 语言编程代写

You are to handle a single command line argument to be passed into your program. This is the name of the file to load the score list from. You should not validate its “file type” but just that it exists. Eg: do not reject a file because it does not end in .txt or is not in the current directory. You should however check that only one arg is provided to the program. This arg is to be passed into the play_game function so that the scores list can be loaded.

Part B Requirement 2: initialize the game (8 marks)

Implement the init_game() function in game.c to call the appropriate functions to start the game.

Please note that for much of this game you will need to do random number generation. You are expected to use rand/srand to do this.

You should prompt for each player’s name and select a random colour from the list of provided colours and then call the function to initialize each player; prompt for the size of the board to be played on and call the function to create the board. You should then “flip a coin” to decide which player will go first (don’t forget the seed the random number generator first) and set that player as the first player to have a move. Call the load_scores() function in file “score_list.c” to load in the letter scores that will be used in score_list.c. Finally deal the starting 5 letters to each of the players so they have sufficient letters to start the game. Please ensure any values returned are checked for validity and assigned to the appropriate member of the game structure.

Part B Requirement 3: create the board (4 marks)  C 语言编程代写

Create a board structure using using malloc and create the board with the width and height that have been passed into the function. Ensure that everything is initialized correctly. This should be implemented in the function new_board() implemented in the file board.c.

Part B Requirement 4: initialize a player (5 marks)

In the function player_init() , copy in the player’s name, set the player’s colour and assign the game pointer to the player. The assigning of the game pointer simplifies the later calls to player_turn() so it now only needs a player pointer argument.

Part B Requirement 5: Load Scores (6 marks)

This function will return a list of the letters in the game. It will accept a filename that containes a series of lines where each line is comma separated. It is of the format of letter,score,count

For example, the line:

A,1,9

Means that there are 9 copies of ‘A’ in the starting deck and each ‘A’ that is played is worth one point.

You should validate that each line is formatted correctly with 2 commas and that the second and third elements are integers and the first element is a single letter in the range A-Z. Each letter should be unique and all letters must appear so by the end of the function your score list should have 26 elements.

Please note we will test your program with invalid files as well as with valid files. You cannot presume that the file to be loaded is in the same directory or has some file extension. If you overvalidate the file to the point we cannot get your program to work then there will be a substantial reduction as we can only mark you on what we can test.

Part B Requirement 6: deal letters (4 marks)  C 语言编程代写

This function takes in two score lists. The first one is the total score list and the second one is the one contained in the player’s hand. Letters will be selected randomly from the score list and copied to the player’s hand until the player’s hand contains 5 letters. Each letter copied to the player’s hand should have its count in the full score list reduced by 1. Please note that if there are insufficient letters left to be dealt, deal as many as you can. The total_count should help you here and therefore you should reduce this total_count by 1 after each card is dealt.

The function prototype for performing this is:

void deal_letters(struct score_list * full_score_list, struct score_list* players_hand);

Part B Requirement 7: the play_game() function (6 marks)

This function manages the initialisation of the game and the game loop. You should call the

game_init() function to do the game initialisation and then have a loop allowing each player to have their turn until a player quits or there is no more space on the board. After each turn you should call scores_update() on each player to update their scores.

Part B Requirement 8: game move (6 marks)  

This is to be implemented in the function player_move(). You should start by displaying the current board, eg:

 

C 语言编程代写
C 语言编程代写

 

Please note that the above layout is suggested only as you are designing the application – we are providing you some guidance however.

If [enter] is pressed on a new line for any of these prompts, the current turn will be skipped and it will become the other player’s turn.

If ctrl-d is pressed at any prompt, this will indicate the intention of the current player to quit the game and thus the game loop back in play_game() will be jumped out of.

In order to print the characters in coloured output, I have provided the color_strings array. You can use this as follows:

printf("%s%c%s", color_strings[COL_RED], 'h', color_strings[COL_RESET]);

This would print out the letter ‘h’ in the colour red.

Please note that after each move, the letters a player is holding should be replenished to 5, if there are any left to be dealt.

Part B Requirement 9: validate and apply move (6 marks)  

Once the move has been entered, it must be checked to see that it fits on the board.

A valid move other than the first move must use at least one letter from another word on the board and when it does that, it claims that letter as its own so in the above example, r should now be coloured blue as it now belongs to Paul.

The validation and applying of the move should be implemented in the function:

BOOLEAN validate_move(struct player * theplayer, const char * word, const struct coord * coords, enum orientation orient)

which is in the module rules-b.c

Back in the player_move() function you should handle the return from this function such as:

Well done. That move was successful! Paul’s new score is 6.

However if validate_move() returns FALSE, you should display:

Error: that was not a valid move. Please try again.

Part B Requirement 10: calculate scores (7 marks)  C 语言编程代写

As you can see from above, at the end of each move the scores will need to be recalculated. You will implement the logic for calculating a player’s new score in the function:

int calculate_score(struct player * theplayer);

which will return the new score but also update the player’s score in the player struct. This will involve iterating through the board and adding up the score for each letter belonging to the player in question. calculate_score() is also in the file rules-b.c.

Part B Requirement 11: Quit Game (5 marks)

Back in play_game() at the end of each turn you should check if the intention of the player to quit the game has been registered and in that case, declare a winner (the player with the highest score), invoke the code to cleanup memory, and exit the program.

Part B Requirement 12: Free memory (5 marks)  C 语言编程代写

When the game is quit, all memory must be freed such that if I run your program with valgrind such

as:

valgrind –track-origins=yes –leak-check=full –show-leak-kinds=all ./wuzzle scoreslistCPT220

no leaks or blocks in use should be reported. Please note for any invalid memory accesses, these will be deducted under the section where that particular requirement is assessed. Memory errors in one section may impact upon the marks in other sections that are dependent upon it.

Part B Requirement 13: Readme file (5 marks)  

In the readme file you need to outline how to use your program and what design choices you made along the way. We will mark you on those decisions so what you say here may impact upon marks in other sections of the assignment. For this reason, we won’t deduct marks for not using all the startup code UNLESS you provide no justifications or those justifications are not acceptable from a programmer’s perspective – that is the choices you have made need to be defensible. This is common in the software development world that you need to defend your decisions to your peers.

Eg: employees at google need to do this all the time.

 

General Requirements  C 语言编程代写

These are general requirements that are applicable for all assignments.

General Requirement #1 – Functional Abstraction (6 Marks)

This requirement relates to good program design.

We encourage the use of functional abstraction throughout your code. It is considered to be a good practice when developing software with many benefits. Abstracting code into separate functions reduces the possibility of bugs in your project, simplifies programming logic and eases the process of debugging. We are looking for some evidence of functional abstraction throughout your code.

General Requirement #2 – Buffer handling (5 Marks)

This requirement relates to how well your programs handle “extra input”. As there is no user input required for this assignment, you nevertheless still need to check for buffer overflow and all appropriate code to clear the input buffer when reading from a file. We have provided a modified version of clear_buffer() in io.c to help with this. Please note that if you detect buffer overflow in this case you should treat it as an error and display an error and reprompt for input.

Marks will be deducted for the following buffer-related issues:

Prompts being printed multiple times or your program “skipping” over prompts because leftover input was accepted automatically. These problems are a symptom of not using buffer overflow code often enough.

General Requirement #3 – Input validation  C 语言编程代写

For functionality that we ask you to implement that relies upon the user entering input, you will need to check the length, range and type of all inputs where applicable.

For example, you will be expected to check the length of strings (e.g., 1-20 characters), the ranges of numeric inputs (e.g., an integer with value 1-7) and the type of data (e.g., is this input numeric?).

Also, some data types can only be allowed to have a limited set of values, for example days of the week or months of the year.

For any detected invalid inputs, you are asked to re-prompt for this input – don’t truncate extra data or abort the function.

Further, you are required to demonstrate correct use of the standard library function:

char *strtok(const char *restrict s1, const char *restrict s2);

where appropriate in your code. The use of alternate methods to achieve similar functionality (such as the use of the scanf family of functions) will result in a deduction. Please note that “correct use” includes appropriate error handling. For example, your error messages displayed to the user should be self-explanatory.

General Requirement #4 – Coding conventions/practices  C 语言编程代写

Marks are awarded for good coding conventions/practices such as:

  • Avoiding global variables.
  • Avoiding goto statements.
  • Consistent use of spaces or tabs for indentation. We recommend 4 spaces for every level of indentation. Be careful to not mix tabs and spaces. Each “block” of code should be indented one level.
  • Keeping line lengths of code to a reasonable maximum such that they fit in the default terminal screen width (80 characters wide).
  • Commenting (including function header comments).
  • Complete author identification on all files.
  • Appropriate identifier names.
  • Avoiding magic numbers.
  • Avoiding platform specific code such as the use of system() and the avoidance of system specific header files.
  • Checking the return values of important functions such as fopen(), malloc() and so on.
  • General code readability.

 

What to submit  C 语言编程代写

Submit only the files needed to build your program – that is the files we have provided and any additional files you create. Do not submit for example the provided data files.

You must submit the files either in a zip file or a tar.gz file. No other formats will be accepted. Do not rename an archive compressed by another program as such a corrupt file will not be marked. You must use valid programs to do this compression. Please test your archives on titan prior to submission.

You will lose 10% of available marks for each day late that you submit. This means that if we mark your assignment and you get 55/100 and you submit 2 days late, you will receive 35/100. A day late is simply submitting after the deadline for that day. So submitting one hour late will result in a whole day’s deduction if you have not organised an extension with us.

Penalties  C 语言编程代写

Marks will be deducted for the following:

  • Compile errors and warnings.
  • Fatal run-time errors such as segmentation faults, bus errors, infinite loops, etc.
  • Files submitted in PC format (instead of Unix format). This can occur when transferring your files from home (PC) to saturn or jupiter (coreteaching01 or coreteaching02) (Unix). You can remove extra end-of-line characters from PC formatted files using the dos2unix command or tr. Please see the UNIX Survival Guide for details on how to do this.
  • Missing files (affected components get zero marks).
  • Files incorrectly named, or whole directories submitted.
  • Not using startup code or not filling-in the readme file.
  • Not identifying yourself in all files submitted
  • Failure to remove default return values provided in the startup code when you implement the function.
  • Programs with compile errors that cannot be easily corrected by the marker will result in a maximum possible score of 40% of the total available marks for the assignment.
  • Outputting errors to stdout rather than stderr.

Any sections of the assignment that cause the program to terminate unexpectedly (i.e., segmentation fault, bus error, infinite loop, etc) will result in a maximum possible score of 40% of the total available marks for those sections. Any sections that cannot be tested as a result of problems in other sections will also receive a maximum possible score of 40%.

It is not possible to resubmit your assignment after the deadline due to mistakes.

 

General Submission Information  C 语言编程代写

Canvas is used for submission of all assignments. Assignments are not accepted by any other means (any attempts to submit via email will specifically be ignored).

You will be informed via the Canvas discussion board when Canvas submissions are opened. If you are unsure how to use Canvas for submissions, please ask your instructor – not knowing how to submit is no grounds for consideration. Don’t panic and leave it to the last minute!

 

Extensions of Time

You may apply for an extension of time by emailing the instructor at least one week before the due date but please note that I will only give extensions for extenuating circumstances.

Common requests for extensions such as “My hard disk crashed and I lost all my work.” won’t be accepted and we advise you to keep an up to date backup of all relevant source files. Likewise, applications for extensions based on working overtime or having a heavy study load will not be granted.

 

When/how do I get my marks?

Assignment marks will be made available within 10 working days of the final submission deadline. An announcement will be made on Canvas when marks are available. An announcement will also be made with regards to what you need to do if there are any mistakes in your marks. You will also receive an email to your student email address explaining what you did well and how you could improve.

 

Help!  C 语言编程代写

Please utilise the following with regards to getting help for your assignments:

  • For general assignment questions, please use the Canvas discussion board. That way all students can see all questions once.
  • Please do not post large pieces of code to the Canvas discussion board for plagiarism reasons. Show your code to your lab assistant / tutor instead.
  • You are generally welcome to bring assignment-related questions to class.
  • If you are having problems that may prevent you from completing your assignment on time, please talk to someone as early as possible. If you find any problems with the assignment specifications, please post your queries to the Canvas discussion board.

 

 

 

 

更多代写:计算机assessment代写  多邻国代考  英国Accountant会计学网课代修  essay写作代写  Australia英语论文  MPA论文开题代写

合作平台:随笔代写 论文代写 写手招聘 英国留学生代写

 

天才代写-代写联系方式