91精品国产91久久久久久_国产精品二区一区二区aⅴ污介绍_一本久久a久久精品vr综合_亚洲视频一区二区三区

合肥生活安徽新聞合肥交通合肥房產生活服務合肥教育合肥招聘合肥旅游文化藝術合肥美食合肥地圖合肥社保合肥醫院企業服務合肥法律

CSCI1540代做、代寫C++設計編程

時間:2023-12-12  來源:合肥網hfw.cc  作者:hfw.cc 我要糾錯



CSCI1540 Fundamental Computing Using C++, Fall 2023/24
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Copyright © 2023 CSE, CUHK Page 1 of 7
Assignment 6: Rush Hour
Due: 23:59, Sat 9 Dec 2023 File names: RushHour.cpp
playgame.cpp
Full marks: 100
Introduction
The objective of this assignment is to practice object-oriented programming. You will write a class
and a client program to play a sliding block puzzle game called Rush Houra
.
The game is played on a grid of size 8 × 8 with at most 10 cars on it. The cars are aligned either
vertically or horizontally in the grid and occupy two or three tiles. There is an exit hole on the right
side of the grid. The goal of the puzzle is to move the cars forward or backward (but not change
direction) so that a designated car (called Car 0) moves to the exit hole. Figure 1(a) shows an
example puzzle configuration, in which Cars 0, 1, 6, and 7 are horizontal and can move left or right,
and Cars 2, 3, 4, and 5 are vertical and can move up or down. Moving Car 1 to the right by one tile
yields the state in Figure 1(b). Continuing to move the cars carefully, you can yield the solved state as
in Figure 1(c) where Car 0 reaches the exit hole on the right.
########
#11...2#
#3..4.2#
#3004.2.
#3..4..#
#5...66#
#5.777.#
########

########
#.11..2#
#3..4.2#
#3004.2.
#3..4..#
#5...66#
#5.777.#
########
→ … →
########
#311...#
#3.....#
#3....00
#5..4.2#
#5664.2#
#7774.2#
########
(a) Initial (b) Move Car 1 (c) Solved
Figure 1: An Example Rush Hour Configuration and its Solved State
Program Specification
You shall write your program in two source files RushHour.cpp and playgame.cpp. The former is
the implementation of the class RushHour, while the latter is a client program of class RushHour
which performs the program flow. You are recommended to finish the RushHour class first before
writing the client program. When you write the RushHour class, implement the member functions
and test them individually one by one. Your two files will be graded separately, so you should not mix
the functionalities of the two files.
Class RushHour (RushHour.cpp)
You are given the interface of the RushHour class in the header file RushHour.h. You shall not
modify the contents of this header file. Descriptions of the class are given below.
a You may play Rush Hour online at: https://www.mahjongfun.com/rush-hour/
CSCI1540 Fundamental Computing Using C++, Fall 2023/24
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Copyright © 2023 CSE, CUHK Page 2 of 7
class RushHour {
public:
 RushHour(const string g[]);
 bool locateCar(int car, int &row, int &col);
 int moveCar(int car, int step);
 bool isSolved();
 int getTotalSteps();
 void print();
private:
 string grid[8];
 int totalSteps;
};
Private Data Members
string grid[8];
The Rush Hour puzzle is represented by an array of string. Each element grid[𝑖] stores the
contents in row 𝑖 of the grid. E.g., for the configuration in Figure 1(a), grid[0] is “########”,
grid[1] is “#11...2#”, grid[2] is “#3..4.2#”, etc. All characters in the strings are either ‘#’
(border), ‘.’ (empty), or digits ‘0’–‘9’ (cars). All the strings are of length 8.
int totalSteps;
The total number of steps that a player has moved during puzzle play. Note that moving a car by, say,
two tiles, is counted as two steps.
Public Constructor and Member Functions
RushHour(const string g[]);
This constructor initializes the Rush Hour puzzle using the array parameter g, which contains
contents for row 1 to row 6 of the grid. (That is, g[0] is used to initialize grid[1]; g[1] is used to
initialize grid[2]; …; g[5] is used to initialize grid[6].) Note that row 0 and row 7 are not
needed in the parameter because the two rows always contain only the ‘#’ symbol. You just have to
initialize grid[0] and grid[7] as “########”. E.g., suppose g is {"#11...2#", "#3..4.2#",
"#3004.2.", "#3..4..#", "#5...66#", "#5.777.#"}. Then grid shall be initialized such
that grid[0]…grid[7] become “########”, “#11...2#”, “#3..4.2#”, “#3004.2.”,
“#3..4..#”, “#5...66#”, “#5.777.#”, and “########” respectively (that is, the configuration in
Figure 1(a)).
You can assume that:
➢ Array parameter g is always of size 6;
➢ Each string g[0], …, g[5] is always of length 8, and always contains eight symbols of either ‘#’
(border), ‘.’ (empty), or digits ‘0’–‘9’ (cars);
➢ The strings g[0], …, g[5] always start and end with the border ‘#’. An exception is on g[2] (for
grid[3]), where its last character is always the exit hole (‘.’).
➢ The cars always occupy either two or three tiles, and are always properly aligned vertically or
horizontally.
CSCI1540 Fundamental Computing Using C++, Fall 2023/24
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Copyright © 2023 CSE, CUHK Page 3 of 7
You do not have to handle situations where the parameter g does not conform to these assumptions.
Remember to also initialize the data member totalSteps as 0.
bool locateCar(int car, int &row, int &col);
Finds the position of the parameter car in the puzzle. The position of a vertical car is its topmost tile.
The position of a horizontal car is its leftmost tile. The row and column indices of the found position
are assigned to the reference parameters row and col respectively, and the member function shall
return true. E.g., locating Car 2 in Figure 1(a) shall write 1 to row and 6 to col and return true,
because Car 2 appears at row 1, column 6. In case car cannot be located in the grid (e.g., there is no
Car 8 in Figure 1(a)), the member function shall not update row and col and return false.
int moveCar(int car, int step);
Performs the action of moving the parameter car by step tiles. A positive value for step means
moving down (for vertical car) or right (for horizontal car); a negative value means moving up (for
vertical car) or left (for horizontal car). E.g., in Figure 1(a), moving Car 6 left by three tiles has a step
of -3. A move is valid only if all the followings are satisfied:
➢ The parameter car exists in the grid.
➢ The parameter step is non-zero. (Moving a car by 0 tile is meaningless.)
➢ There is enough space to allow the car to move by step tiles, without hitting other cars or the
border, or going beyond the exit hole. (E.g., in Figure 1(a), Car 6 cannot move left by four tiles (-4
steps), as it would hit Car 5.)
If the move is valid, then data members grid and totalSteps shall be updated accordingly.
Otherwise, no updates to grid and totalSteps are needed. This member function shall return
either 0, 1, or 2, according to the following conditions:
Condition Return value
Move is valid 0
car does not exist in the grid or step is zero 1
Hit other cars or border or go beyond the exit hole 2
Implementation hint: First, find the position of car (with the help of locateCar()). Then
determine which one of the four cases the prospective move is: move left/right/up/down. Implement
the four cases one by one. For each case, check whether the move is valid or not. If valid, update the
car to the new position (by updating the grid contents).
bool isSolved();
Returns true if Car 0 touches the exit hole; returns false otherwise.
int getTotalSteps();
Returns the total number of steps that a player has moved the cars. That is, the value of the data
member totalSteps.
void print();
Prints out the Rush Hour puzzle and the number of steps that the player has used. The following is
an example output of print().
CSCI1540 Fundamental Computing Using C++, Fall 2023/24
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Copyright © 2023 CSE, CUHK Page 4 of 7
########
#311..2#
#3....2#
#300..2.
#5..4..#
#5664..#
#7774..#
########
Steps: 10
Client Program (playgame.cpp)
Your main program is a client of the RushHour class. You create a RushHour object here and call its
member functions to implement the following program flow.
1. The program starts with prompting the user to enter six strings (separated by spaces), which are
the initial grid contents for row 1 to row 6 of the puzzle. Then create a RushHour object using
the user input. You can assume that the six strings follow the same assumptions stated in the
constructor above).
2. Prompt the user to move a car. You can assume that the user always enters two integers,
denoting the car and the steps of the prospective move respectively. (Positive step means
moving down/right; negative step means moving up/left.)
3. In case the input is not a valid move (see definition in the moveCar() member function above),
the program prints a warning message and goes back to Step 2. Otherwise, move the car
accordingly.
Note: there are two kinds of warning messages. When the car does not exist or the step is zero,
the message “Invalid car or step! Try again.” shall be printed. When the move would hit other
cars or border or go beyond the exit hole, the message “Hit! Try again.” shall be printed.
4. If the puzzle is not yet solved after the move and the total number of steps is smaller than 100,
go back to Step 2.
5. Finally, print the puzzle and either the winning message “Congrats! You finished in 𝑋 steps.”
(where 𝑋 is the number of steps used) or the losing message “Oops! You could not solve in 100
steps.”
Some Points to Note
➢ You cannot declare any global variables in all your source files (except const ones).
➢ Remember to #include "RushHour.h" in both RushHour.cpp and playgame.cpp.
➢ You can write extra functions in any source files if necessary. However, extra member functions
(instance methods), no matter private or public, are not allowed.
➢ Your RushHour class shall not contain any cin statements. All user inputs shall be done in the
client program (playgame.cpp) only.
➢ The RushHour class shall not contain any cout statements except in the print() member
function for printing the puzzle.
CSCI1540 Fundamental Computing Using C++, Fall 2023/24
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Copyright © 2023 CSE, CUHK Page 5 of 7
Sample Run
In the following sample run, the blue text is user input and the other text is the program output. You
can try the provided sample program for other input. Your program output should be exactly the
same as the sample program (same text, symbols, letter case, spacings, etc.). Note that there is a
space after the ‘:’ in the program printout. More sample runs and initial grids are available in
Blackboard.
Enter initial grid: #11...2# #3..4.2# #3004.2. #3..4..# #5...66# #5.777.#
########
#11...2#
#3..4.2#
#3004.2.
#3..4..#
#5...66#
#5.777.#
########
Steps: 0
Move a car: 1 4
Hit! Try again.
Move a car: 1 1
########
#.11..2#
#3..4.2#
#3004.2.
#3..4..#
#5...66#
#5.777.#
########
Steps: 1
Move a car: 3 0
Invalid car or step! Try again.
Move a car: 3 -2
Hit! Try again.
Move a car: 8 1
Invalid car or step! Try again.
Move a car: 3 -1
########
#311..2#
#3..4.2#
#3004.2.
#...4..#
#5...66#
#5.777.#
########
Steps: 2
Move a car: 5 -1
CSCI1540 Fundamental Computing Using C++, Fall 2023/24
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Copyright © 2023 CSE, CUHK Page 6 of 7
########
#311..2#
#3..4.2#
#3004.2.
#5..4..#
#5...66#
#..777.#
########
Steps: 3
Move a car: 7 -2
########
#311..2#
#3..4.2#
#3004.2.
#5..4..#
#5...66#
#777...#
########
Steps: 5
Move a car: 6 -3
########
#311..2#
#3..4.2#
#3004.2.
#5..4..#
#566...#
#777...#
########
Steps: 8
Move a car: 4 2
########
#311..2#
#3....2#
#300..2.
#5..4..#
#5664..#
#7774..#
########
Steps: 10
Move a car: 2 3
########
#311...#
#3.....#
#300....
#5..4.2#
#5664.2#
#7774.2#
########
Steps: 13
Move a car: 0 5
Hit! Try again.
Move a car: 0 4
CSCI1540 Fundamental Computing Using C++, Fall 2023/24
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Copyright © 2023 CSE, CUHK Page 7 of 7
########
#311...#
#3.....#
#3....00
#5..4.2#
#5664.2#
#7774.2#
########
Steps: 17
Congrats! You finished in 17 steps.
Submission and Marking
➢ Your program file names should be RushHour.cpp and playgame.cpp. Submit the two files in
Blackboard (https://blackboard.cuhk.edu.hk/). You do not have to submit RushHour.h.
➢ Insert your name, student ID, and e-mail as comments at the beginning of all your files.
➢ Besides the above information, your program should include suitable comments as
documentation in all your files.
➢ You can submit your assignment multiple times. Only the latest submission counts.
➢ Your program should be free of compilation errors and warnings.
➢ Do NOT share your work to others and do NOT plagiarize. Those who shared their work and/or
plagiarized others work shall be penalized.
請加QQ:99515681 或郵箱:99515681@qq.com   WX:codehelp

掃一掃在手機打開當前頁
  • 上一篇:代寫CS 8編程、代做Python語言程序
  • 下一篇:COMP2396代做、代寫Tic-Tac-Toe Game設計編程
  • 無相關信息
    合肥生活資訊

    合肥圖文信息
    2025年10月份更新拼多多改銷助手小象助手多多出評軟件
    2025年10月份更新拼多多改銷助手小象助手多
    有限元分析 CAE仿真分析服務-企業/產品研發/客戶要求/設計優化
    有限元分析 CAE仿真分析服務-企業/產品研發
    急尋熱仿真分析?代做熱仿真服務+熱設計優化
    急尋熱仿真分析?代做熱仿真服務+熱設計優化
    出評 開團工具
    出評 開團工具
    挖掘機濾芯提升發動機性能
    挖掘機濾芯提升發動機性能
    海信羅馬假日洗衣機亮相AWE  復古美學與現代科技完美結合
    海信羅馬假日洗衣機亮相AWE 復古美學與現代
    合肥機場巴士4號線
    合肥機場巴士4號線
    合肥機場巴士3號線
    合肥機場巴士3號線
  • 短信驗證碼 目錄網 排行網

    關于我們 | 打賞支持 | 廣告服務 | 聯系我們 | 網站地圖 | 免責聲明 | 幫助中心 | 友情鏈接 |

    Copyright © 2025 hfw.cc Inc. All Rights Reserved. 合肥網 版權所有
    ICP備06013414號-3 公安備 42010502001045

    91精品国产91久久久久久_国产精品二区一区二区aⅴ污介绍_一本久久a久久精品vr综合_亚洲视频一区二区三区
    国产成人在线视频网站| 久久av免费一区| 中文字幕色av一区二区三区| 久久久久国产精品午夜一区| 菠萝蜜视频在线观看一区| 亚洲综合视频在线观看| 日韩欧美一二三四区| 亚洲另类视频| 国产成人精品亚洲日本在线桃色| 亚洲欧洲日产国码二区| 欧美日韩精品一区二区| 国产字幕视频一区二区| 日韩一区精品字幕| 精品国产乱码久久| 久久亚洲高清| 欧美福利在线| 日韩国产成人精品| 国产日韩欧美亚洲| 欧美乱妇一区二区三区不卡视频 | 粉嫩aⅴ一区二区三区四区五区| 亚洲免费观看高清完整版在线| 欧美肥妇free| 亚洲欧美日韩综合国产aⅴ| 不卡一区在线观看| 天天影视网天天综合色在线播放| 国产视频一区二区三区在线观看| 在线观看国产精品网站| 精品不卡视频| 成人小视频在线观看| 日本人妖一区二区| 国产精品福利电影一区二区三区四区| 欧美在线三级电影| 一区二区91| 97久久精品人人做人人爽| 激情综合色播激情啊| 亚洲国产一区二区视频| 国产精品久久久久久福利一牛影视| 91精品国产综合久久福利| 久久免费国产| 国产日韩欧美综合精品| 精品电影一区| 91一区二区在线| 国产成人午夜高潮毛片| 喷水一区二区三区| 亚洲chinese男男1069| 久久免费看少妇高潮| 欧美男人的天堂一二区| 色婷婷亚洲综合| 国产视频亚洲| 亚洲第一伊人| 欧美日韩日本国产亚洲在线| 不卡一区二区在线| 国产不卡视频在线播放| 精品一区中文字幕| 婷婷久久综合九色国产成人| 一级特黄大欧美久久久| 亚洲欧美怡红院| 国产精品福利一区| 国产精品美女www爽爽爽| 欧美激情一区二区三区蜜桃视频| 久久影音资源网| 久久先锋影音av鲁色资源网| 日韩欧美激情在线| 日韩午夜精品电影| 精品久久久久久久久久久久包黑料 | 久久久亚洲综合| 久久久亚洲综合| 国产亚洲精品aa午夜观看| 久久亚洲精华国产精华液 | 国产调教视频一区| 国产日产欧美一区| 国产精品素人一区二区| 国产精品久久久久久福利一牛影视 | 亚洲电影一区二区| 丝袜诱惑亚洲看片| 欧美aaaaaa午夜精品| 青草国产精品久久久久久| 免费成人在线观看| 美女视频网站久久| 狠狠色2019综合网| 粉嫩一区二区三区性色av| 成人一区二区三区视频在线观看| 丁香一区二区三区| 91在线视频播放| 欧美婷婷久久| 亚洲国产激情| 亚洲影音一区| 在线看不卡av| 在线成人av网站| 亚洲精品一线二线三线无人区| 日韩女优av电影在线观看| 久久久美女艺术照精彩视频福利播放 | 久久精品一区二区三区不卡| 中文字幕乱码日本亚洲一区二区| 成人欧美一区二区三区在线播放| 亚洲精品自拍动漫在线| 同产精品九九九| 国产乱人伦偷精品视频免下载| 成人激情黄色小说| 欧美日韩一区自拍| 亚洲一区二区网站| 欧美三级三级三级| 2020国产成人综合网| 国产精品免费人成网站| 亚洲一区二三区| 国产原创一区二区| 91视视频在线直接观看在线看网页在线看| 午夜精品久久99蜜桃的功能介绍| 亚洲片区在线| 欧美日韩免费观看一区二区三区| 日韩片之四级片| **性色生活片久久毛片| 日韩精品国产欧美| 懂色av噜噜一区二区三区av| 欧美视频观看一区| 91精品福利在线| 2欧美一区二区三区在线观看视频| 国产精品久久久久一区二区三区共 | 成人免费观看视频| 夜夜爽99久久国产综合精品女不卡| 在线观看av不卡| 国产午夜精品久久| 日韩精品国产精品| 91视频免费播放| 久久综合伊人| 久久亚洲免费视频| 天堂va蜜桃一区二区三区漫画版| 成人深夜福利app| 国产精品久久国产三级国电话系列| 欧美日韩亚洲另类| 国产精品乱人伦中文| 久久精品国产久精国产爱| 91看片淫黄大片一级在线观看| 香蕉久久夜色精品国产| 精品少妇一区二区三区在线视频| 亚洲九九爱视频| 成人免费视频国产在线观看| 国产精品久久久一区二区三区| 制服丝袜中文字幕一区| 亚洲精品中文字幕在线观看| 国产盗摄一区二区三区| 国产农村妇女精品一二区| 欧美xxx久久| 日产国产欧美视频一区精品| 欧美日韩喷水| 欧美一区二区在线播放| 一区二区三区丝袜| 91丨porny丨首页| 精品视频123区在线观看| 日韩一区欧美一区| 成人h动漫精品一区二区| 日本韩国欧美一区二区三区| 欧美激情在线观看视频免费| 国内精品伊人久久久久av一坑 | 国产精品免费看片| 国产成人精品在线看| 性久久久久久| 国产精品国产三级国产普通话99| 国产精品一色哟哟哟| 色综合久久久久久久久久久| 一区二区中文字幕在线| 丁香啪啪综合成人亚洲小说| 久久久久在线| 亚洲婷婷综合久久一本伊一区| 成人妖精视频yjsp地址| 欧洲亚洲国产日韩| 亚洲精品国产高清久久伦理二区| av午夜一区麻豆| 欧美精品三级日韩久久| 天堂蜜桃91精品| 一级成人国产| 国产精品日日摸夜夜摸av| 波多野结衣精品在线| 欧美丰满美乳xxx高潮www| 石原莉奈在线亚洲二区| 中国成人亚色综合网站| 国产精品区一区二区三| va亚洲va日韩不卡在线观看| 欧美另类高清zo欧美| 日韩不卡一区二区三区| 99精品视频免费观看视频| 欧美激情在线看| av不卡免费电影| 欧美va天堂va视频va在线| 久久99精品久久久久久久久久久久 | 蜜臀av性久久久久蜜臀aⅴ| 亚洲欧美日韩国产一区二区| 亚洲精品中文在线影院| 国产自产精品| 国产精品拍天天在线| 欧美a级在线| 欧美精品一区二区三区一线天视频| 国产在线一区观看| 欧美日韩精品一区二区三区蜜桃| 日韩福利视频网| 色婷婷综合久久| 午夜国产不卡在线观看视频| 美脚丝袜一区二区三区在线观看 | gogo大胆日本视频一区| 精品伦理精品一区|