# assg2.pdf - CSCI1120 Introduction to Computing Using C Fall...

• Homework Help
• 6

This preview shows pages 1–3. Sign up to view the full content.

CSCI1120 Introduction to Computing Using C++, Fall 2016-2017 Department of Computer Science and Engineering, The Chinese University of Hong Kong Copyright © 2016 CSE, CUHK Page 1 of 6 Assignment 4: Dots and Boxes Due: 20:00, Wed 12 Oct 2016 Full marks: 100 Introduction In this assignment, you will implement a two-player paper-and-pencil game called Dots and Boxes . Starting with an empty grid of dots, two players take turns adding one horizontal or vertical line between two un-joined adjacent dots. A player who completes the fourth side of a 1 × 1 box earns one point and takes an extra turn. The game ends when the grid is full, and the player with more points wins. We shall assume that the game is played in a cruciform grid, so that there are five boxes when the grid is full. (Therefore, there will never be a draw game.) Figure 1 shows an example grid. We use the symbol o to denote dots, and the symbols -- and | to denote the lines of boxes. In the figure, the right-sided box is already formed (assumed to be by Player 1), and the left-sided box is one vertical line from being formed. o o | o--o o--o Player 1 score: 1 | | | o--o o--o Player 2 score: 0 | o--o Figure 1: An Example Dots and Boxes Configuration Program Specification This section describes the representation of a grid in a game, the necessary C++ functions, and the flow of your program. Grid Representation There are 16 possible positions that we can place a line in the cruciform grid. Therefore, we use integers 1 to 16 to denote these positions, as illustrated in Figure 2. The positions are basically ordered top-to-bottom, left-to-right. o o | o--o o--o Player 1 score: 1 | | | o--o o--o Player 2 score: 0 | o--o Figure 2: Numbers for Line Positions 1 2 3 5 4 6 8 7 9 10 11 12 13 14 15 16

This preview has intentionally blurred sections. Sign up to view the full version.

CSCI1120 Introduction to Computing Using C++, Fall 2016-2017 Department of Computer Science and Engineering, The Chinese University of Hong Kong Copyright © 2016 CSE, CUHK Page 2 of 6 To encode the whole grid and the players’ scores in a game, we use an 18-digit integer 𝑑 1 𝑑 2 𝑑 3 𝑑 4 𝑑 5 𝑑 6 𝑑 7 𝑑 8 𝑑 9 𝑑 10 𝑑 11 𝑑 12 𝑑 13 𝑑 14 𝑑 15 𝑑 16 𝑑 17 𝑑 18 . The first 16 digits 𝑑 1 … 𝑑 16 are either 0 or 1, denoting whether the corresponding positions 1 to 16 are empty or filled. The last two digits 𝑑 17 and 𝑑 18 are between 0 and 5 (inclusive) to denote the scores of Players 1 and 2 respectively. For example,
This is the end of the preview. Sign up to access the rest of the document.
• Fall '15

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern