联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2019-05-12 09:52

COMP 2011 Programming with C++

Assignment 3 Let's play Gomoku!

Introduction

In this assignment you will write a Gomoku game, which is also called Five in a Row, for 2 players. Gomoku actually has

many variations, and we are only going to implement a simplified version of it. Essentially, it is a Tic-Tac-Toe but a player

can only win with 5 (instead of 3) connected pieces.

Here is the background story:

Since the board is 2D, it is natural to use a 2D array to represent the board. A simple and easy approach would be to use a

static 2D array for that. However, to make your game flexible and efficient with memory usage at the same time, a dynamic

2D array seems to be a better choice. As you think about it more, it doesn't feel good. You realize, as you have almost

finished taking COMP2011, you are almost an expert in (basic) C++, you despise such an easy solution.

Therefore, as you want to show off what you have learned (or just to have a good practice on a challenging topic, or just to

get your knowledge in this particular topic assessed), you have decided to write this game with linked lists.

We value academic integrity very highly. Please read the Honor Code section on our course webpage to make sure you

understand what is considered as plagiarism and what the penalties are. The following are some of the highlights:

Do NOT try your "luck" - we use some sophisticated plagiarism detection software to find cheaters. It is much better

than most students think. It has been proven times and times again tricks don't work. We also review codes for potential

cases manually.

The penalty (for BOTH the copier and the copiee) is not just getting a zero in your assignment - it is much more than

that. It is simply not worth to cheat at all. You would hurt your friend and yourself by doing that. It is obvious that a real

friend won't ask you to get involved in a plagiarism act in any way due to the consequences. Read the Honor Code

again before you even try to think about cheating.

Serious offenders will fail the course immediately and there may be additional disciplinary actions from the department

and university.

Overview

Your solution to this assignment must be based on the given skeleton code provided in the Download section.

Your task is to complete the gomoku_to_submit.cpp, and that's the only file you need to submit to Canvas.

The header file has the detailed requirements. The description below is only a supplement and aims to help you understand

the assignment. You need to read both the source/header files and the webpage description carefully to get the whole

picture.

Read the FAQ page for some common clarifications. You should check that a day before the deadline to make sure you don't

miss any clarification, even if you have already submitted your work then.

Submission details are in the Submission and Deadline section.

Description

Please read the skeleton code alongside with the following description. You may also play with the demo provided in the

download section to try the examples.

The board size is customizable as you can see in the main(). The following assumes a 6x5 board, i.e., height is 6 and width

is 5.

Each row is a linked list of Cells. For the definition of the Cell structure, please see gomoku.h.

Therefore, in our example, we will have 6 linked lists, and their heads will be pointed by cellRowHeads[0], cellRowHeads[1],

..., cellRowHeads[5].

cellRowHeads[0] is the head Cell of the linked list for the first row (row 1), and that Cell itself is at the first column (column 1)

of that row.

The next pointer of cellRowHeads[0] points to the second Cell in the same row, and hence that cell is at the second column

(column 2) of the first row (row 1). And so on.

Similarly, cellRowHeads[5] is the head Cell of the linked list for the last row (row 6), and it is at the first column (column 1).

It follows, then, there would be 5 Cells in each of the 6 linked lists as the board width is 5 and the height is 6. In total, there

are exactly 30 Cells. There are no dummy/placeholder Cell objects.

If the given drawBoard function is called, the following should be printed, at the start of the game. You may read the code of

the given drawBoard to help yourself understand the linked list structure and how you may use it.

The numbers at the top and left are just labels for columns and rows, respectively.

The dot '.' denotes an empty space at which either of the 2 players can place their moves.

Let's say, player 1 chooses (row 2, column 3), then the board becomes:

The 'X' represents player 1.

And if player 2, which is represented by 'O', chooses (2, 2), then the board becomes:

The game goes on, with each player takes turns to place his/her move, the board becomes:

As it is player 1's turn, he/she decides to win the game with a move at (6, 3).

Player 1 has won vertically !!!

As a result, the game finishes with a congratulation message.

It is also possible to win a game horizontally:

Player 1 has won horizontally !!!

Or diagonally (both ways should be checked in checkDiagonal, as shown below):

Player 2 has won diagonally !!!

Player 2 has won diagonally !!!

In some rare occasions, it is also possible for a player to win in several ways at the same time:

Player 1 has won vertically diagonally !!!

You may check the main() to see how both checkings are applied.

When the board is full without any player winning the game first, the game is considered as a "draw game":

Download

Skeleton code: skeleton.zip

Demo: pa3demo.exe *

Create a standard Eclipse C++ project (MinGW gcc compiler on Windows) and add all files from the zip package to it.

It is required that your program can be compiled and run successfully in the pre-installed Eclipse environment on

our lab machines. If you use other IDE/compiler/OS to work out your solution, you should test your program in the

aforementioned official environment before submission. Since this is already your third assignment, we will be strict with the

rules.

Using our Windows Eclipse zipped package downloaded from the "Using Eclipse at home (Windows) " section here on a

standard Windows machine (e.g., HKUST virtual barn) is also good enough to verify that your program can be compiled by

us. The Desktop on a virtual barn machine has limited space, so you may use C:\temp there to unzip the Eclipse package.

Don't leave your source code there as you logout.

* The demo program is compiled for Windows. Mac/Linux/Android/whatever OS users may use any of the many Windows

PCs on campus or remotely via virtual barn (usable on a Mac/Android) to run the demo if you want.

Sample Output

Your finished program should produce the exact same output as follows. Please note that sample output, naturally, does not

show all possible cases. It is part of the assessment for you to design your own test cases to test your program. Be reminded

to remove any debugging message that you might have added before submitting your code.

Also, after testing, make sure your submitted code can compile with the unmodified main.cpp and header file. Put in

dummy/empty implementation whenever needed.

Let's play Gomoku! :)

Please enter the size of the board.

Player X, your turn! What's your move?

Enter row and column. [1-6] [1-5]

Player O, your turn! What's your move?

Enter row and column. [1-6] [1-5]

Player X, your turn! What's your move?

Enter row and column. [1-6] [1-5]

Player O, your turn! What's your move?

Enter row and column. [1-6] [1-5]Player X, your turn! What's your move?

Enter row and column. [1-6] [1-5]

Player O, your turn! What's your move?

Enter row and column. [1-6] [1-5]

Player X, your turn! What's your move?

Enter row and column. [1-6] [1-5]

Player O, your turn! What's your move?

Enter row and column. [1-6] [1-5]

Player X, your turn! What's your move?

Enter row and column. [1-6] [1-5]

Player 1 has won horizontally !!!

Program should terminate without any memory leak.

You may also play with the demo program in the download section.

Bonus

For this last assignment, to make sure the bonus works are evaluated consistently, we will have only 1 TA to manually

assess your bonus work. To enable that, we will only award bonus points to worthy bonus works that meet a certain

minimum requirement.

On the other hand, while bonus work assessment is by nature subjective, if you meet the minimum requirement, you are

guaranteed to have at least 1 bonus point. We want to motivate and reward the hard-workers in a more well-defined way.

Your bonus work must be in either one of the two categories:

Non-trivial game features. Your code for those features must be of at least 200 meaningful lines of C++ code statements

of your own. Empty lines, comments, and redundant/irrelevant statements are excluded. Don't intentionally lengthen

your implementation - we may shorten it for you whenever possible as we verify the line count ourselves.

GUI interface (not just colored consoles). For example, use a GUI C++ framework such as QT or wxWidgets. It is

definitely not easy, but that means 2 points are likely to be awarded for your hard work.

We have deliberately made it challenging as we don't want students to think the bonus part is "easy points" and feel

compelled to do or else they are missing out.

With all this said, note that bonus part is optional, but please feel free to take up the challenge if you are motivated to learn

extra stuff and have the resources.

Copying some ready-to-use feature (e.g. certain public AI code) from the internet is not allowed. In fact, it can be considered

as plagiarism. Therefore, instead of bonus, the offenders may receive penalty. Be creative to create your own features, and

don't just copy.

Submission and Deadline

Deadline: 23:59:00 on May 11, 2019

Canvas Submission

You should submit only the gomoku_to_submit.cpp through the Canvas Assignment 3 Submission Page.

Make sure your source file can be successfully compiled. It is required that your program can be compiled and run

successfully in the pre-installed Eclipse environment on our lab machines. If we cannot even compile your source files,

your work will not be graded. Therefore, you should at least put in dummy implementations to the parts that you cannot finish

so that there will be no compilation error.

Make sure you actually upload the correct version of your source files - we only grade what you upload. Some

students in the past submitted an empty file or a wrong file or an exe file which is worth zero mark. So you must download

and double-check the file you have submitted. You can find the download link on the right-hand side of the same Canvas

assignment page after your submission.

You may submit your file multiple times, but only the latest version will be graded.

Submit early to avoid any last-minute problem. Only canvas submissions will be accepted.

Bonus submission

You still need to submit the regular version, and then submit an additional bonus version. Follow the same procedure

as the submission for the regular submission on Canvas except that you should submit a single zip file named pa3-

bonus.zip to "Bonus - Assignment 3" instead HERE. The single zip file should contain the following.

1. All the source files needed to compile your work.

2. A text file named "README.txt" or a PDF file "README.pdf" which should tell us:

How to compile and run your program?

For non-GUI bonus, how many c++ meaningful statements/lines you have written for the bonus? See the bonus

section for more information.

What are the new functionalities that you have implemented? Be clear and sell them to us.

What are some sample input/output that your bonus program can produce, to show off its features?

Anything else? Help us evaluate your work favorably.

3. If you did the GUI bonus, you need to also provide screenshots or videos. you can put all screenshots in the

README.pdf document. You can also provide the screenshots in a common image file format such as jpg, gif, or png.

Alternatively, Videos that can be played on a lab machine, and online videos (just give us a link), are also accepted.

Note:

1. We may invite selected students to demo the PA3 bonus work.

2. Wrong submission or missing information will disqualify your work from being assessed.

Late submission policy

There will be a penalty of -1 point (out of a maximum 100 points) for every minute you are late. For instance, since the

deadline of the assignment is 23:59:00 on May 11th, if you submit your solution at 1:00:00 on May 12th, there will be a

penalty of -61 points for your assignment. However, the lowest grade you may get from an assignment is zero: any negative

score after the deduction due to late penalty (and any other penalties) will be reset to zero.

FAQ

Frequently Asked Questions

Q: My code doesn't work / there is an error, here is the code, can you help me fix it?

A: As the assignment is a major course assessment, to be fair, you are supposed to work on it on your own and we should

not finish the tasks for you. We might provide some very general hints to you, but we shall not fix the problem or debug for

you.

Q: Can I add extra helper functions?

A: You may do so in the file that you are allowed to modify and submit.

Q: Can I include additional libraries?

A: No. Everything you need is already included - there is no need for you to add any include statement (under our official

environment).

Q: Can I create global variables?

A: No, as already instructed in a source file comment.

Q: Can I declare/define arrays for the bonus part?

A: For bonus submission, yes you can. For your regular submission of PA3, you still need to follow the no-new-array-allowed

rule for functions other than createBoard.

Q: Can I use the cellRowHeads as a 2D array, or any 2D array?

A: No, as announced in the email. array[i][j] (for whatever array, i, and j are) shouldn't appear in your code.

Q: How about using cellRowHeads with syntax like (cellRowHeads + (i*width + j))?

A: No, as you are using cellRowHeads like a 2D array in this way. A linked list would never support such operation since the

memory allocated for the linked list elements are not guaranteed to be consecutive like an array. Again, you need to use

cellRowHeads like a linked list. To reiterate what has been announced in the email, "If you need to access a Cell on the

board, you need to use cellRowHeads[i] as the head Cell node of the linked list, and iterate through that linked list (by the

"next" pointers) to locate the Cell. You may see how it is done in the given drawBoard function.".

Q: The program crashes with a message "terminate called recursively" after I input the width and height when I run it on

Eclipse, any tips?

A: It is likely because of a wrong implementation of your createBoard. The drawBoard function will crash if it is fed with a

wrongly initialized cellHeadRows. A few tips: 1. For a board of size height*width, you need to have exactly height*width "new

Cell". Do you have that many cell objects created? Count it carefully. (not just array of pointers "new Cell*[N]", but dynamic

Cell objects "new Cell") 2. Are the Cells linked by the next pointers correctly? 3. Is the next pointer of the last cell in every row

pointing to nullptr? Again, we won't check or debug your code for you, but hopefully these general tips help.

Menu

Introduction

Overview

Description

Download

Sample Output

Bonus

Submission & Deadline

FAQ

Page maintained by

Wallace Mak

Email: wallacem@cse.ust.hk

Last Modified: 05/11/2019 02:55:01

Homepage

Course Homepage

Maintained by COMP 2011 Teaching Team ? 2018 HKUST Computer Science and Engineering


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp