Established the main structure

This commit is contained in:
2023-09-26 10:39:11 +08:00
parent 9c33209313
commit 2f668d681d
2 changed files with 39 additions and 5 deletions

View File

@ -1,6 +1,7 @@
#ifndef CLIENT_H #ifndef CLIENT_H
#define CLIENT_H #define CLIENT_H
#include <cassert>
#include <iostream> #include <iostream>
#include <utility> #include <utility>
@ -46,8 +47,34 @@ void InitGame() {
* 12? * 12?
* 01? * 01?
*/ */
namespace Client {
const int max_size = 35;
char game_map[max_size][max_size];
/**
* @brief The definition of function PreProcessData()
*
* @details This function is designed to preprocess the data of the game map immedietly after reading it.
*/
void PreProcessData() {
using namespace Client;
}
/**
* @brief The definition of function GenerateNextStep()
*
* @details This function is designed to generate the next step when playing the client's (or player's) role.
*/
std::pair<int, int> GenerateNextStep() {
using namespace Client;
return std::make_pair(0, 0);
}
} // namespace Client
void ReadMap() { void ReadMap() {
// TODO (student): Implement me! using namespace Client;
for (int i = 0; i < rows; i++) {
std::cin >> game_map[i];
assert(strlen(game_map[i]) == columns);
}
PreProcessData();
} }
/** /**
@ -57,10 +84,11 @@ void ReadMap() {
* client's (or player's) role. Open up your mind and make your decision here! * client's (or player's) role. Open up your mind and make your decision here!
*/ */
void Decide() { void Decide() {
// TODO (student): Implement me! using namespace Client;
// while (true) { while (true) {
// Execute(0, 0); std::pair<int, int> next_step = GenerateNextStep();
// } Execute(next_step.first, next_step.second);
}
} }
#endif #endif

View File

@ -18,12 +18,14 @@ int rows; // The count of rows of the game map
int columns; // The count of columns 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 int game_state; // The state of the game, 0 for continuing, 1 for winning, -1
// for losing // for losing
namespace Server {
int visit_count, step_count; int visit_count, step_count;
const int max_size = 35; const int max_size = 35;
char origin_map[max_size][max_size]; // The original map char origin_map[max_size][max_size]; // The original map
char visible_map[max_size][max_size]; // The map that the player can see char visible_map[max_size][max_size]; // The map that the player can see
int number_of_nearby_mines[max_size][max_size]; // The number of nearby mines int number_of_nearby_mines[max_size][max_size]; // The number of nearby mines
int number_of_all_mines; // The number of all mines int number_of_all_mines; // The number of all mines
} // namespace Server
/** /**
* @brief The definition of function InitMap() * @brief The definition of function InitMap()
* *
@ -38,6 +40,7 @@ int number_of_all_mines; // The number of all mines
*/ */
void InitMap() { void InitMap() {
using namespace std; using namespace std;
using namespace Server;
std::cin >> rows >> columns; std::cin >> rows >> columns;
assert(2 <= rows && rows <= 30 && 2 <= columns && columns <= 30); assert(2 <= rows && rows <= 30 && 2 <= columns && columns <= 30);
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
@ -94,6 +97,7 @@ void InitMap() {
* the game ends and the player loses. * the game ends and the player loses.
*/ */
void VisitBlock(int row, int column) { void VisitBlock(int row, int column) {
using namespace Server;
step_count++; step_count++;
using namespace std; using namespace std;
assert(0 <= row && row < rows && 0 <= column && column < columns); assert(0 <= row && row < rows && 0 <= column && column < columns);
@ -156,6 +160,7 @@ void VisitBlock(int row, int column) {
* the advanced task!!! * the advanced task!!!
*/ */
void PrintMap() { void PrintMap() {
using namespace Server;
if (game_state != 1) { if (game_state != 1) {
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
std::cout << visible_map[i] << std::endl; std::cout << visible_map[i] << std::endl;
@ -183,6 +188,7 @@ void PrintMap() {
* number of steps taken respectively. * number of steps taken respectively.
*/ */
void ExitGame() { void ExitGame() {
using namespace Server;
assert(game_state != 0); assert(game_state != 0);
if (game_state == 1) { if (game_state == 1) {
std::cout << "YOU WIN!" << std::endl; std::cout << "YOU WIN!" << std::endl;