Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP19911 - Introduction to Programming - 22T2

NOTE

This assignment requires you to understand and use structs

structs will be covered in the weekOS lectures

Before then you should still read the assignment and the starter code thoroughly.

And start to understand the general concepts of the assignment.

When the fire nation started attacking the CSE Land, citizens were forced to go back to basics.

They began farming to meet their daily needs.

As an aspiring developer in COMP1911 Land, your first task is to create a simulation called cse.vailey , which mimics everyone's environment.

Overview

The World!

cse_vaiiey is a simple world, basically a grid and everything must occur here.

Your job is to act as a farmer to seed, grow, harvest, and trade plants for your wellbeing.

The success of your career depends on how you navigate this challenging world.

The image below visualises what this world looks like where you, the farmery begin your journey!

Provided Structs

You have been provided with 3 existing struct data types to help you with your implementation of this simulation. These structs and their purposes are shown below.

• struct land

o Purpose: lb store the state of an individial block of land.

o Contains:

■ int is_watered - represents if this particular block of land is currently watered.

■ char seed_name - stores the single letter name of the seed currently planted in this block of land. 。Hint: You should not need to use this struct until Stage 2.

I 3 be」I

Se我一力〃必e

• struct seeds

o Purpose: To store information about a single type of seed.

o Contains:

■ char name - stores the single letter name of this type of seed.

■ int amount - stores the number of available seeds to plant of this type (not including the amount currently planted).

o Note: name is initialised to no_seed and seed can only have lowercase letters (i.e. between 'a1 and 'z' inclusive) as its name.

S丄術巾皿」5

char I 1

〃刀* I I

• struct farmer

o Purpose: To store the current state of a farmer.

o Contains:

■ int curr_coi - stores the current column coordinate of the farmer.

■ int curr_row - stores the current row coordinate of the farmer.

■ int cum_dir - stores a character representing the direction the farmer is currently facing.

o Note: curr_dir can only have values of > , < , v , and A , representing facing right, left, up, and down respectively.

斗也+ 顷me”

__ _ ― >

]泌+ //。| 匚二I

"EC"「」
char [侦仃_灯|

HINT

For the first two stages, you will not need to modify any of the structs we have given you. However; in the later stages, you may need to make changes to the structs we have given you (or specifically, what is inside them).

The Commands

As part of running the simulation, you as the aspiring developer of COMP1911 Land need to allow for commands to be given to your program. These commands are how you will interact with the game. The simulation runs through 2 modes, setup and game.

1. Setup: This is where the user sets the number of and type of seeds initially available to the farmer. This is further explained in Stage 1.1

2. Game: This is the main game mode. Commands are read in indefinitely, until EOE

o Each command given to the program will be a combination of char and integers.

o There could be a large number of lines of input, so you must not store all the commands in an array — you should scan them in individually.

o Depending on the initial command argument character; you will have to scan in a differing number of additional variables (called "arguments"). For example, in Stage 1.2, the ''Printing One Seed" command requires a command argument s , followed by an additional argument that specifies the name of the seed to be printed.

o The specifics of the commands are detailed in a series of stages below.

NOTE:

You can assume that your program will never be given a non-existent command or command arguments that are not of the right type.

Allowed C Features

In this assignment, there are no restrictions on C Features, except for those in the Style Guide (http://cgi.cse.unsw.edu.au/2Csl911/22T2/style-guide/index.html).

We strongly encourage you to complete the assessment using only features taught in lectures up to and including Week 4. The only C features you will need to get full marks in the assignment are:

• int variables

• char variables

• if statements, including relational and logical operators ( == , < , && , etc.)

• while lOOpS

• printf and scanf

• structs

• arrays , including two dimensional arrays

• Your own helper functions

Using any other features will not increase your marks (and will make it more likely you make style mistakes that cost you marks).

If you choose to disregard this advice, you must still follow the Style Guide (http://cgi.cse.unsw.edu.au/~csl911/22T2/style- guide/index.html). You also may be unable to get help from course staff if you use features not taught in COMP1911.

Features that the Style Guide strongly discourages or bans will be penalised during marking.

Reference Implementation

lb help you understand the proper behaviour of CSE Valley, we have provided a reference implementation. If you have any questions about the behaviour of CSE Valley, you can check them against this reference implementation.

To access the reference Implementation

$ 1911 cse_valley

How To Get Started

There are a few steps to getting started with CSE Valley.

1. Create a new folder for your assignment work and move into it.

$ mkdlr ass2

$ cd ass2

2. Download the starter code (cse_valley.c) here (cse_valley.c)

or use this command on your CSE account to copy the file into your current directory:

$ cp -n /web/csl911/22T2/assignments/ass2/cse_valley.c .

3. Spend a few minutes playing with the reference solution — get a feel for how the assignment works.

$ 1911 cse_valley

4. Read through Stage 1, which is below.

5. Think about your solution, draw a diagram of the farm_iand to help you get started

6. Start coding!

About the Starter Code

The provided starter code has done some setup for you. This is explained below.

Before the main function, the starter code has:

1. Imported libraries, defined some initial #define 's, and defined the structs described above

2. Declared some functions, which are used to setup the game. You do not need to use these functions!

3. Declared a print_iand function which you will have to use in stage 2.

In the main function, the starter code has:

1. Declared and initialised an instance of a struct farmer called cse_farmer .

o This sets farmer's cum_coi and cum_row to be。and curr_dir to be > .

2. Declared and initialised a 2D array of struct land called farm_iand .

o This will set every is_watered to be false and every seed_name to be no_seed for all elements on the 2D array.

3. Declared and initialised a regular ID array of struct seeds called seed_coiiection .

© This will set every amount to be 0 and every name to be no_seed for all elements in the array.

4. This is where you write your code!

Your Tasks

This assignment consists of four stages. Each stage builds on the work of the previous stage, and each stage has a higher complexity than its predecessor; You should complete the stages in order.

Stage 1 Stage 2 Stage 3 Stage 4

Stage 1

RATIONALE:

Why does this stage exist? This stage tests your ability to scan user input, create while loops, access values in an array, and traverse a one dimensional array. These are core skills in COMP1911 and also specifically in this assignment. You must display a basic understanding of how these work and how they can be applied in your own problem solving. Arrays are a common data structure used to store data on a computer and to help solve problems, which is the reason they form such a vital portion of the course.

Who do we expect to complete this stage? We hope that all students will be able to complete this stage.

What help will tutors provide to students? Tutors can give you a theoretical explanation, and give lots of help with the lab exercises that lead to this assignment. Tutors will be happy to help you debug any issues with your code.

How many marks will I get? Completing this stage, with good style, is worth around a 30% mark.

In this stage, you will implement:

1. The ability to choose what seed types you would like to start with,

2. The ability to print out the number of the different seed types that a farmer has,

3. The ability to print out a specific type of seed and its amount.

1.1: Scanning Different Seed Names

To get everyone started with their farms, all farmers will receive 6。seeds each. As a farmer; you will be able to say how many different seeds you wish to have (from 1 to 5 inclusive) and what their different names are. The 60 seeds will be then split equally amongst the different seed names you have specified.

Invalid Inputs and Clarifications

• We can assume that the farmer will only enter a number between 1 and 5 (inclusive) as the number of different seeds that they wish to have.

• We can assume that the farmer will not put in the same seed names.

• We can assume that the farmer will only put in a lowercase alphabet character for each different seed name.

HINT:

To ignore possible whitespaces such as a newline, make sure to put a space before the %c when using the scanf function.

HINT:

Currently we have defined seed_coiiection to be an array of struct seeds . Your job is to modify the array to accommodate the seeds that were given to each farmer. Make sure that the order is right! For example, the first seed name to be scanned in should appear as seed_coiiection[0] and so on and so forth.

NOTE

This is the only task that you have to implement on the setup component of the simulation. From this moment on, you will be dealing with the game component.

+ Example 1.1.1: Scanning in Seeds

1.2: Printing All Seeds

A farmer should be able to find out their seeds inventory. This is done in the simulation using the Printing All Seeds command. This command will print all the current seeds that a farmer has at their disposal, in the order the seeds were initialised.

The Printing All Seeds command is specified by the command argument a . The output should be given in the following format:

Seeds at your disposal:

-m seed(s) with the name 'n*

where m is the amount of seeds with the name n for all seeds that the farmer currently has.

HINT

Make sure that you do not print struct seeds that has no_seed as their name!

HINT:

You may have to loop through the array seed_coiiection to access all the different seeds.

+ Example 1.2.1: Printing All Seeds

1.3: Printing One Seed

In order to be able to plan their day of seed planting, a farmer needs to be able to find out the amount of seeds of a particular type. This is done through the Printing One Seed command. The command is specified by the character s , followed by the seed_name the farmer wish to find out. The output should be given in the format:

There are m seeds with the name 'n'

where m is the number of seeds and n is the name of the seed.

Invalid Inputs and Clarifications

• If the farmer puts in an invalid seed name (i.e. something other than a lowercase letter), your program should give an output of:

Seed name has to be a lowercase letter

• If the farmer asks you to print out a valid seed name that you do not have in your collection, your program should give an output of:

There is no seed with the name 'n'

where n is the seed name .

+ Example 1.3.1: Printing One Seed

Table of Commands

Summary of All Commands

Stage

Command Name

Command Argument

Additional Arguments

1.2

Printing All Seeds

a

 

1.3

Printing One Seed

s

seed_name

2.1

Printing Land

1

 

2.2a

Moving Upwards

A

 

2.2b

Moving Right

>

 

2.2c

Moving Downwards

V

 

2.2d

Moving Left

<

 

2.3a

Watering an Adjacent Land

0 w

 

2.3b

Planting on an Adjacent Land

0 P

seed_name

2.4

Scattering Seeds

p

seed_name

3.1

Watering a Square

w

square_size

3.2a

Advancing to the Next Day

n

 

3.2b

Harvesting an Adjacent Plant

h

 

3.3

Trading Seeds

t

src_name src_amt dst_name

4.1

Expriencing Droughts

d d

min_num_plants_to_die

4.2

Experiencing Wind Storms

d w

min_num_plants_to_survive

C Standard Library

The following C standard library headers may be used in your assignment. If you want to use others, please make a post on the course forum.

• stdio.h

• stdlib.h

• math.h

• ctype.h

• string.h

Assessment

This assignment will contribute 20% to your final mark.

The assessment for the assignment recognizes the difficulty of the task, the importance of style, and the importance of appropriate use of programming methods (e.g. using while loops instead of a dozen if statements).

70% Correctness

The correctness of your program will be determined automatically by tests that we will run against your program. When using "autotesf your program will be tested against a small number of tests. However; the tests that will determine your marks are from a much larger sample and are also unknown to you. Your mark for this section will be a result of how many tests your program passes.

20% Style

Strict adherence to the style guide. Tutors will hand mark the readability of the C you have written. These marks will be awarded on the basis of clarity, commenting, elegance and style. This will include using suitable variable names, using consistent layout and indentation.

10% Design

Appropriate use of programming techniques (if/else, while loops, arrays, functions) in your program. These marks are extremely easy to get assuming that you utilise functions, arrays, and loops in your program. It is to discourage students "brute-force solving" the problem without any arrays/loops.

The following actions will result in a 0/100 mark for Assignment 1, and in some cases a 0 for COMP1911:

• Knowingly providing your work to anyone and it is subsequently submitted (by anyone).

• Submitting any other person's work. This includes joint work.

• Submitting another person's work without their consent.

The lecturer may vary the assessment scheme after inspecting the assignment submissions but it will remain broadly similar to the description above.

Originality of Work

The work you submit must be your own work. Submission of work partially or completely derived from any other person or jointly written with any other person is not permitted. The penalties for such an offence may include negative marks, automatic failure of the course and possibly other academic discipline. Assignment submissions will be examined both automatically and manually for such submissions.

Relevant scholarship authorities will be informed if students holding scholarships are involved in an incident of plagiarism or other misconduct.

Do not provide or show your assignment work to any other person - apart from the teaching staff of COMP1911. If you knowingly provide or show your assignment work to another person for any reason, and work derived from it is submitted you may be penalized, even if the work was submitted without your knowledge or consent. This may apply even if your work is submitted by a third party unknown to you.

Note, you will not be penalized if your work has the potential to be taken without your consent or knowledge.

Autotest

To run the provided autotest use the following command

$ 1911 ass2_autotest

Submission

This assignment is due on Friday 5th August 19:59:59 (WeeklO)

Submit the assignment using this give command:

$ give csl911 ass2 cse_valley.c

Late Submission Policy

If your assignment is submitted after this date, each hour it is late reduces the raw mark by 0.2%.

After 5 days submissions will no longer be accepted.

For example if an assignment worth 76% was submitted 5 hours late, the late submission would be worth 75%.

If the same assignment was submitted 30 hours late it would be awarded 70%.

If the same assignment was submitted 120 hours late (5 days) it would be awarded 0%.