ENGGEN 131 – Semester Two – 2024 C Programming

Java Python ENGGEN  131  Semester Two  2024

C Programming Project

BOXED IN

Deadline:  11:59pm, Saturday  19th   October

Worth:  12% of your final grade

A little background

Who knew that pushing boxes around could be so much fun!

Sokoban (which means “warehouse keeper” in Japanese) is a classic puzzle game that was

originally developed as a video game in 1982 by Hiroyuki Imabayashi.  The game became an instant hit, and it has captivated players around the world with its blend of simple mechanics  (literally pushing boxes) and deep strategy.

In this project, you are going to develop a version of the Sokoban game called “Boxed In” .

The gameplay involves the player controlling a person in a warehouse depicted as a 2-dimensional grid of

floor (i.e. empty space) and wall (i.e. immovable

barrier) squares. Some floor squares contain boxes,

while others are marked as storage locations (i.e.

targets). The goal is pretty straightforward: move all of  the boxes onto the targets.  Sounds simple, right?  Well, the challenge lies in the player’s ability to only push

boxes – and never pull boxes!   This means care must be taken to avoid trapping boxes in corners or blocking a    crucial path and creating unwinnable scenarios.

Sokoban puzzles aren’tjust fun – they’ve also been

studied in computer science. The problem of solving Sokoban has been proven to be “NP-hard”, which

means the problems are difficult to solve because there is no known quick or efficient way to find a solution.

These problems get much harder as they get bigger, with the number of required moves growing exponentially.

In this project, you will be implementing – step by step – the required functionality for the “Boxed In” game.

Once you have completed the game, you can spend hours and hours playing it, all throughout the summer holidays.

Have fun!

An important note before we begin 

Welcome to the C Programming project for ENGGEN 131 2024!

This project is organized as a series of related tasks.  When combined, the tasks will complete

the implementation for the game.  For each task there is a problem description, and you must

implement one required function to solve that problem.  In addition to the required function, you may define other optional functions which the required function calls upon (i.e. so-called helper  functions).  Using helper functions is often a useful way to organize your code, as several simpler functions can be easier to read and understand than one complex function.

Do your very best, but don’t worry if you cannot complete every task.   You will get credit for each task that you do solve.

IMPORTANT - Read carefully

This project is an assessment for the ENGGEN  131 course.  It is an individual project.  You do not need to complete all of the tasks, but the tasks you do complete should be an accurate

reflection of your capability and effort.  You may discuss ideas in general with other students,

but writing code must be done by yourself.  No exceptions.   You must not give any other student a copy of your code in any form. – and you must not receive code from any other source (friends, students, AI language models, etc.) in any form.  There are absolutely NO EXCEPTIONS to this rule.

Please follow this advice while working on the project – the penalties for academic misconduct (which include your name being recorded on the misconduct register for the duration of your     degree, and/or a period of suspension from Engineering or expulsion from the University) are    simply not worth the risk.

Task One: “Let’s design a box!”                                                                                           (10 marks)

Before we start developing the “Boxed In” game, let’s design a simple text-version of a box.   A box should be rectangular, and it should have some marking at the exact center position, so that the person pushing the box knows where to push!

For this task, you must define a function called MakeBox() which takes three inputs: a string     into which the characters will be stored, the width of the box (an integer), and the height of the  box (also an integer).   The MakeBox() function should generate a string representing the box.  A box will simply be represented as a rectangle where the hash character (‘#’) is used to denote

the edges.  In addition, the exact center of the box must be denoted using the character  ‘X’ (to help the person push the box in the correct place).

If the width and height of the box are both odd numbers, then there will be a single center

position which can be denoted with a single ‘X’ .  If the width and the height are both even

numbers, then the center position will have to be denoted with a small square of four  ‘X’

characters.  If only one of the width or height is an odd number, and the other is an even number, then two ‘X’ characters will be needed to denote the center position.   The examples below illustrate these three possibilities:

Note: the length of the output string will be exactly (width + 1) * height characters.  This is

because there is a single new line character appearing at the end of each line (including the last line).

For Task One, you must define a function called MakeBox():

void MakeBox(char *design, int width, int height)

You can assume that both width and height will be at least  1.  Note, the smallest box size for

which you will need to include the center position is 3 (if the width or height is 2 or less, it is not possible to include the center position so there will be no ‘X’ characters in the string in that case).

To illustrate how this function should work, consider the examples below: Example:

char box1[1000] = {0}; char box2[1000] = {0}; char box3[1000] = {0};

MakeBox(box1, 12, 5);  MakeBox(box2, 15, 15); MakeBox(box3, 4, 4);

printf("Box 1 = \n%s\n", box1); printf("Box 2 = \n%s\n", box2); printf("Box 3 = \n%s\n", box3);

printf("Checking string lengths = %d %d %d\n", strlen(box1),

strlen(box2), strlen(box3));

Expected output:

Box 1 =

############ #            # #    XX    # #            # ############

Box 2 =

############### #             # #             # #             # #             # #             # #             # #      X       # #             # #             # #             # #             # #             # #             # ###############

Box 3 = ####

#XX# #XX# ####

Checking string lengths = 65 240 20

Note: the string lengths are exactly (width + 1) * height

Task Two: “Let’s see the warehouse!”                                                                                 (10 marks)

Let’s now move on to the “Boxed In” game.  The first thing we need to do is display the

warehouse.  The locations of the walls, the empty spaces on the floor, the person pushing the boxes, the targets, and the boxes will be represented using a two-dimensional array (of type   int). Two pre-defined constants are provided which specify the size of this array:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值