第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

沒下源碼,自己琢磨出來了,有百度左右手算法,算法這東西真難XD...

#include <iostream>

#include <Windows.h>

#include <string>

#include <process.h>

#include <Windows.h>


using namespace std;


/* https://zhidao.baidu.com/question/1755742141667975828.html?

設(shè)定初始面向 East ( 如果是右手抹墻則是 West)


1如果當(dāng)前格為第一排,則說明當(dāng)前格為終點,結(jié)束。

2根據(jù)當(dāng)前格的數(shù)據(jù),找到下一步需要面向的方向, 方法是,如果當(dāng)前方向上有墻,則順時針(右手抹墻則逆時針)轉(zhuǎn)身,重復(fù)這一步驟直到面向的方向上可以行走

3沿當(dāng)前方向走一步

4逆時針(右手抹墻則順時針)轉(zhuǎn)身一次,使當(dāng)前面對方向為第3步之后的左手(或右手)方向, 然后回到步驟1

*/


//墻體和路常量

#define WOLD ?"■"

#define ROLD ?" ?"


//迷宮大小常量

const int X = 8;

const int Y = 8;


//計步器

int count = 0;


//方向枚舉

enum direction{

N = 0,

S = 1,

W = 2,

E = 3

};


//地圖類

class MazeMap {

public:

MazeMap() {}

void coutMap(string map[X][Y]) { //構(gòu)造地圖

for (int i = 0; i < X; i++) {

for (int j = 0; j < Y; j++) {

cout << map[i][j] ;

}

cout << endl;

}

}

};


//人類類

class Human {

public:

Human() :x(6), y(6), man("☆"), direction(W){} //默認(rèn)人初始化為第一個位置

Human(string _man) :x(6), y(6), man(_man), direction(W){} //可以設(shè)置人的標(biāo)識符

//橫縱坐標(biāo)

int x;

int y;

//人物標(biāo)識

string man;

//方向

int direction;

// 移動方法

void humanMove(string map[X][Y], Human *man) {

MazeMap *mazeMap = new MazeMap;

map[man->x][man->y] = man->man;

mazeMap->coutMap(map);

cout << "READY?(Q:y/n)" << endl;

char flag = 'n';

cin >> flag;

//單向?qū)ぢ吩瓌t ?右手抹墻,初始朝向為W

if (flag == 'y') {

do

{

turnBack(map, man);

move(map, man);

Sleep(1000);

system("cls");

mazeMap->coutMap(map);

} while (finsh(man));

cout << "YOU WIN!!!" << endl;

}

else {

cout << "YOU ARE A LOSE!!!" << endl;

}


delete mazeMap;

mazeMap = NULL;

}


//確定方向 如果方向上有墻就逆時針轉(zhuǎn)一下

void turnBack(string map[X][Y],Human *man) {

static int cache = 0;

if (man->direction == N) {

if (map[man->x - 1][man->y] == WOLD) {

man->direction = W;

cache++;

turnBack(map, man);

}

cache = 0;

return;

}

if (man->direction == S) {

if (map[man->x+1][man->y] == WOLD) {

man->direction = E;

cache++;

turnBack(map, man);

}

cache = 0;

return;

}

if (man->direction == W) {

if (map[man->x][man->y-1] == WOLD) {

man->direction = S;

cache++;

turnBack(map, man);

}

cache = 0;

return;

}

if (man->direction == E) {

if (map[man->x][man->y+1] == WOLD) {

man->direction = N;

cache++;

turnBack(map, man);

}

cache = 0;

return;

}

if (cache == 4) {

cache = 0;

return;

}

}

//移動一格 ?后順時針調(diào)轉(zhuǎn)方向

void move(string map[X][Y], Human *man) {

if (man->direction == N) {

man->direction = E;

map[man->x - 1][man->y] = man->man;

map[man->x][man->y] = ROLD;

man->x -= 1;

}else if (man->direction == S) {

man->direction = W;

map[man->x + 1][man->y] = man->man;

map[man->x][man->y] = ROLD;

man->x += 1;

}else if (man->direction == W) {

man->direction = N;

map[man->x][man->y - 1] = man->man;

map[man->x][man->y] = ROLD;

man->y -= 1;

}else if(man->direction == E) {

man->direction = S;

map[man->x][man->y + 1] = man->man;

map[man->x][man->y] = ROLD;

man->y += 1;

}

return;

}

//判斷是否完成

bool finsh(Human *man) {

if (man->x == 0)

return false;

return true;

}


};



int main(void) {

string map[X][Y] = { {WOLD,ROLD,WOLD,WOLD,WOLD,WOLD,WOLD,WOLD},

{WOLD,ROLD,ROLD,ROLD,ROLD,ROLD,WOLD,WOLD},

{WOLD,WOLD,WOLD,WOLD,WOLD,ROLD,ROLD,WOLD},

{WOLD,ROLD,ROLD,ROLD,ROLD,ROLD,WOLD,WOLD},

{WOLD,WOLD,ROLD,WOLD,ROLD,ROLD,WOLD,WOLD},

{WOLD,WOLD,ROLD,ROLD,ROLD,WOLD,WOLD,WOLD},

{WOLD,WOLD,WOLD,WOLD,ROLD,ROLD,ROLD,WOLD},

{WOLD,WOLD,WOLD,WOLD,WOLD,WOLD,WOLD,WOLD} };

Human *man = new Human("⊙");

man->humanMove(map,man);


delete man;

man = NULL;

return 0;

}



正在回答

4 回答

//確定方向 如果方向上有墻就逆時針轉(zhuǎn)一下

void turnBack(string map[X][Y], Human *man) {

static int cache = 0;

if (man->direction == N) {

if (map[man->x - 1][man->y] == WALL) {

man->direction = W;

cache++;

turnBack(map, man);

}

cache = 0;

return;

}

if (man->direction == S) {

if (map[man->x + 1][man->y] == WALL) {

man->direction = E;

cache++;

turnBack(map, man);

}

cache = 0;

return;

}

if (man->direction == W) {

if (map[man->x][man->y - 1] == WALL) {

man->direction = S;

cache++;

turnBack(map, man);

}

cache = 0;

return;

}

if (man->direction == E) {

if (map[man->x][man->y + 1] == WALL) {

man->direction = N;

cache++;

turnBack(map, man);

}

cache = 0;

return;

}

if (cache == 4) {

cache = 0;

return;

}

}

可以問一下,這個cache的作用是什么嗎?沒看懂???

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

puikiri 提問者

man轉(zhuǎn)向后的當(dāng)前方向, //方向枚舉 enum direction{ N = 0, S = 1, W = 2, E = 3 };
2019-02-18 回復(fù) 有任何疑惑可以回復(fù)我~
#2

puikiri 提問者

覺得不對勁,回頭看了下好像沒什么用 - - ,我去掉了運行也沒錯 - -
2019-02-18 回復(fù) 有任何疑惑可以回復(fù)我~
#3

puikiri 提問者

想起來了,這是判斷,如果出生點四處都是墻則強制返回的 = =
2019-02-18 回復(fù) 有任何疑惑可以回復(fù)我~
#4

puikiri 提問者

應(yīng)該把 if (cache == 4) { cache = 0; return; } 放在這句static int cache = 0;后面 = =,吐血,我的源碼改了上傳的沒改- -,難怪看半天總覺得不對- -
2019-02-18 回復(fù) 有任何疑惑可以回復(fù)我~
#5

puikiri 提問者 回復(fù) puikiri 提問者

感謝提出寶貴意見,之前沒注意到,出生點四處是墻應(yīng)該強制退出 = = ,
2019-02-18 回復(fù) 有任何疑惑可以回復(fù)我~
查看2條回復(fù)

process.h這個頭文件是干嘛的呀大佬?

0 回復(fù) 有任何疑惑可以回復(fù)我~

感謝大佬

0 回復(fù) 有任何疑惑可以回復(fù)我~

聽說算法和數(shù)據(jù)結(jié)構(gòu)是很重要的XD...,歡迎大家指出不足XD...

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

qq_阿斯蒂芬_0

你這個代碼 給新手看最好 void humanMove(string map[X][Y], Human *man) *man改為 *pMan 還有 turnBake(map, pMan); turnBake 改為 turnLeft
2019-01-04 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
C++遠(yuǎn)征之封裝篇(下)
  • 參與學(xué)習(xí)       70903    人
  • 解答問題       534    個

封裝--面向?qū)ο笕筇卣髦?,通過案例讓C++所學(xué)知識融會貫通

進入課程

沒下源碼,自己琢磨出來了,有百度左右手算法,算法這東西真難XD...

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號