Formated all files
This commit is contained in:
@ -8,7 +8,8 @@
|
||||
|
||||
/**
|
||||
* @brief The implementation of function Execute
|
||||
* @details Use it only when trying advanced task. Do NOT modify it before discussing with TA.
|
||||
* @details Use it only when trying advanced task. Do NOT modify it before
|
||||
* discussing with TA.
|
||||
*/
|
||||
void Execute(int row, int column) {
|
||||
std::string str;
|
||||
@ -21,11 +22,13 @@ void Execute(int row, int column) {
|
||||
std::cout.rdbuf(oss.rdbuf());
|
||||
// Here, we redirect the output stream to the string stream.
|
||||
// By this way the output of PrintMap() would be stored in the string.
|
||||
// If you do not understand, you can try to compare it with freopen, which redirect the output stream to a file.
|
||||
// If you do not understand, you can try to compare it with freopen, which
|
||||
// redirect the output stream to a file.
|
||||
PrintMap();
|
||||
std::cout.rdbuf(old_output_buffer); // Restore the output buffer
|
||||
str = oss.str(); // Read the output
|
||||
std::istringstream iss(str); // Redirect the input to the string, which stores the output recently
|
||||
std::istringstream iss(str); // Redirect the input to the string, which
|
||||
// stores the output recently
|
||||
std::streambuf *old_input_buffer = std::cin.rdbuf();
|
||||
ReadMap();
|
||||
std::cin.rdbuf(old_input_buffer);
|
||||
@ -36,6 +39,6 @@ int main() {
|
||||
std::cout << rows << " " << columns << std::endl;
|
||||
InitGame();
|
||||
while (true) {
|
||||
Decide(); // Exit() will be called in this function
|
||||
Decide(); // Exit() will be called in this function
|
||||
}
|
||||
}
|
@ -12,9 +12,10 @@ extern int columns; // The count of columns of the game map
|
||||
/**
|
||||
* @brief The definition of function Execute(int, int)
|
||||
*
|
||||
* @details This function is designed to take a step when player the client's (or player's) role, and the implementation
|
||||
* of it has been finished by TA. (I hope my comments in code would be easy to understand T_T) If you do not understand
|
||||
* the contents, please ask TA for help immediately!!!
|
||||
* @details This function is designed to take a step when player the client's
|
||||
* (or player's) role, and the implementation of it has been finished by TA. (I
|
||||
* hope my comments in code would be easy to understand T_T) If you do not
|
||||
* understand the contents, please ask TA for help immediately!!!
|
||||
*
|
||||
* @param row The row coordinate (0-based) of the block to be visited.
|
||||
* @param column The column coordinate (0-based) of the block to be visited.
|
||||
@ -24,8 +25,9 @@ void Execute(int row, int column);
|
||||
/**
|
||||
* @brief The definition of function InitGame()
|
||||
*
|
||||
* @details This function is designed to initialize the game. It should be called at the beginning of the game, which
|
||||
* will read the scale of the game map and the first step taken by the server (see README).
|
||||
* @details This function is designed to initialize the game. It should be
|
||||
* called at the beginning of the game, which will read the scale of the game
|
||||
* map and the first step taken by the server (see README).
|
||||
*/
|
||||
void InitGame() {
|
||||
int first_row, first_column;
|
||||
@ -36,9 +38,10 @@ void InitGame() {
|
||||
/**
|
||||
* @brief The definition of function ReadMap()
|
||||
*
|
||||
* @details This function is designed to read the game map from stdin when playing the client's (or player's) role.
|
||||
* Since the client (or player) can only get the limited information of the game map, so if there is a 3 * 3 map as
|
||||
* above and only the block (2, 0) has been visited, the stdin would be
|
||||
* @details This function is designed to read the game map from stdin when
|
||||
* playing the client's (or player's) role. Since the client (or player) can
|
||||
* only get the limited information of the game map, so if there is a 3 * 3 map
|
||||
* as above and only the block (2, 0) has been visited, the stdin would be
|
||||
* ???
|
||||
* 12?
|
||||
* 01?
|
||||
@ -50,8 +53,8 @@ void ReadMap() {
|
||||
/**
|
||||
* @brief The definition of function Decide()
|
||||
*
|
||||
* @details This function is designed to decide the next step when playing the client's (or player's) role. Open up your
|
||||
* mind and make your decision here!
|
||||
* @details This function is designed to decide the next step when playing the
|
||||
* client's (or player's) role. Open up your mind and make your decision here!
|
||||
*/
|
||||
void Decide() {
|
||||
// TODO (student): Implement me!
|
||||
|
@ -5,26 +5,27 @@
|
||||
#include <iostream>
|
||||
|
||||
/*
|
||||
* You may need to define some global variables for the information of the game map here.
|
||||
* Although we don't encourage to uss global variables in real cpp projects, you may have to use them because the use of
|
||||
* class is not taught yet. However, if you are member of A-class or have learnt the use of cpp class, member functions,
|
||||
* etc., you're free to modify this structure.
|
||||
* You may need to define some global variables for the information of the game
|
||||
* map here. Although we don't encourage to uss global variables in real cpp
|
||||
* projects, you may have to use them because the use of class is not taught
|
||||
* yet. However, if you are member of A-class or have learnt the use of cpp
|
||||
* class, member functions, etc., you're free to modify this structure.
|
||||
*/
|
||||
int rows; // The count of rows of the game map
|
||||
int columns; // The count of columns of the game map
|
||||
int game_state; // The state of the game, 0 for continuing, 1 for winning, -1 for losing
|
||||
|
||||
int rows; // The count of rows of the game map
|
||||
int columns; // The count of columns of the game map
|
||||
int game_state; // The state of the game, 0 for continuing, 1 for winning, -1
|
||||
// for losing
|
||||
/**
|
||||
* @brief The definition of function InitMap()
|
||||
*
|
||||
* @details This function is designed to read the initial map from stdin. For example, if there is a 3 * 3 map in which
|
||||
* mines are located at (0, 1) and (1, 2) (0-based), the stdin would be
|
||||
* 3 3
|
||||
* .X.
|
||||
* @details This function is designed to read the initial map from stdin. For
|
||||
* example, if there is a 3 * 3 map in which mines are located at (0, 1) and (1,
|
||||
* 2) (0-based), the stdin would be 3 3 .X.
|
||||
* ...
|
||||
* ..X
|
||||
* where X stands for a mine block and . stands for a normal block. After executing this function, your game map would
|
||||
* be initialized, with all the blocks unvisited.
|
||||
* where X stands for a mine block and . stands for a normal block. After
|
||||
* executing this function, your game map would be initialized, with all the
|
||||
* blocks unvisited.
|
||||
*/
|
||||
void InitMap() {
|
||||
std::cin >> rows >> columns;
|
||||
@ -34,40 +35,38 @@ void InitMap() {
|
||||
/**
|
||||
* @brief The definition of function VisitBlock(int, int)
|
||||
*
|
||||
* @details This function is designed to visit a block in the game map. We take the 3 * 3 game map above as an example.
|
||||
* At the beginning, if you call VisitBlock(0, 0), the return value would be 0 (game continues), and the game map would
|
||||
* be
|
||||
* 1??
|
||||
* @details This function is designed to visit a block in the game map. We take
|
||||
* the 3 * 3 game map above as an example. At the beginning, if you call
|
||||
* VisitBlock(0, 0), the return value would be 0 (game continues), and the game
|
||||
* map would be 1??
|
||||
* ???
|
||||
* ???
|
||||
* If you call VisitBlock(0, 1) after that, the return value would be -1 (game ends and the players loses) , and the
|
||||
* game map would be
|
||||
* 1X?
|
||||
* If you call VisitBlock(0, 1) after that, the return value would be -1 (game
|
||||
* ends and the players loses) , and the game map would be 1X?
|
||||
* ???
|
||||
* ???
|
||||
* If you call VisitBlock(0, 2), VisitBlock(2, 0), VisitBlock(1, 2) instead, the return value of the last operation
|
||||
* would be 1 (game ends and the player wins), and the game map would be
|
||||
* 1@1
|
||||
* 122
|
||||
* 01@
|
||||
* If you call VisitBlock(0, 2), VisitBlock(2, 0), VisitBlock(1, 2) instead, the
|
||||
* return value of the last operation would be 1 (game ends and the player
|
||||
* wins), and the game map would be 1@1 122 01@
|
||||
*
|
||||
* @param row The row coordinate (0-based) of the block to be visited.
|
||||
* @param column The column coordinate (0-based) of the block to be visited.
|
||||
*
|
||||
* @note You should edit the value of game_state in this function. Precisely, edit it to
|
||||
* 0 if the game continues after visit that block, or that block has already been visited before.
|
||||
* 1 if the game ends and the player wins.
|
||||
* -1 if the game ends and the player loses.
|
||||
* @note You should edit the value of game_state in this function. Precisely,
|
||||
* edit it to 0 if the game continues after visit that block, or that block has
|
||||
* already been visited before. 1 if the game ends and the player wins. -1 if
|
||||
* the game ends and the player loses.
|
||||
*/
|
||||
void VisitBlock(int row, int column) {
|
||||
void VisitBlock(int row, int column) {
|
||||
// TODO (student): Implement me!
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The definition of function PrintMap()
|
||||
*
|
||||
* @details This function is designed to print the game map to stdout. We take the 3 * 3 game map above as an example.
|
||||
* At the beginning, if you call PrintMap(), the stdout would be
|
||||
* @details This function is designed to print the game map to stdout. We take
|
||||
* the 3 * 3 game map above as an example. At the beginning, if you call
|
||||
* PrintMap(), the stdout would be
|
||||
* ???
|
||||
* ???
|
||||
* ???
|
||||
@ -79,13 +78,12 @@ void VisitBlock(int row, int column) {
|
||||
* ?X?
|
||||
* 12?
|
||||
* 01?
|
||||
* If the player visits all blocks without mine and call PrintMap() after that, the stdout would be
|
||||
* 1@1
|
||||
* 122
|
||||
* 01@
|
||||
* (You may find the global variable game_state useful when implementing this function.)
|
||||
* If the player visits all blocks without mine and call PrintMap() after that,
|
||||
* the stdout would be 1@1 122 01@ (You may find the global variable game_state
|
||||
* useful when implementing this function.)
|
||||
*
|
||||
* @note Use std::cout to print the game map, especially when you want to try the advanced task!!!
|
||||
* @note Use std::cout to print the game map, especially when you want to try
|
||||
* the advanced task!!!
|
||||
*/
|
||||
void PrintMap() {
|
||||
// TODO (student): Implement me!
|
||||
@ -94,13 +92,14 @@ void PrintMap() {
|
||||
/**
|
||||
* @brief The definition of function ExitGame()
|
||||
*
|
||||
* @details This function is designed to exit the game.
|
||||
* It outputs a line according to the result, and a line of two integers, visit_count and step_count,
|
||||
* representing the number of blocks visited and the number of steps taken respectively.
|
||||
* @details This function is designed to exit the game.
|
||||
* It outputs a line according to the result, and a line of two integers,
|
||||
* visit_count and step_count, representing the number of blocks visited and the
|
||||
* number of steps taken respectively.
|
||||
*/
|
||||
void ExitGame() {
|
||||
// TODO (student): Implement me!
|
||||
exit(0); // Exit the game immediately
|
||||
exit(0); // Exit the game immediately
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user