真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java迷宮并求解代碼 java 走迷宮

求用java語言尋找走出迷宮路線的算法

首先給定一個(gè)初始坐標(biāo),然后構(gòu)建一個(gè)容器保存坐標(biāo)值,之后進(jìn)行迭代,橫坐標(biāo)+1,或者縱坐標(biāo)+1,這個(gè)順尋自己定義(四個(gè)方向),經(jīng)過的“路徑”保存在那個(gè)容器中,如果遇到死角,以此往回迭代,在容器中將遇到死角的那個(gè)坐標(biāo)刪除。最后找到自己定義的那個(gè)迷宮出口坐標(biāo)。

創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括平昌網(wǎng)站建設(shè)、平昌網(wǎng)站制作、平昌網(wǎng)頁制作以及平昌網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,平昌網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到平昌省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

關(guān)于Java走迷宮的問題。我已經(jīng)有相關(guān)代碼了,但是我看不懂。麻煩高手幫忙注釋一下,然后再修改點(diǎn)兒。

package 走迷宮;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.ArrayList;

import java.util.LinkedList;

import java.util.List;

import java.util.TimerTask;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

// 迷宮

public class Maze extends JFrame implements ActionListener {

private JPanel panel;

private JPanel northPanel;

private JPanel centerPanel;

private MazeGrid grid[][];

private JButton restart;

private JButton dostart;

private int rows;// rows 和cols目前暫定只能是奇數(shù)

private int cols;

private ListString willVisit;

private ListString visited;

private LinkedListString comed;

private long startTime;

private long endTime;

public Maze() {

rows = 25;

cols = 25;

willVisit = new ArrayListString();

visited = new ArrayListString();

comed = new LinkedListString();

init();

this.setTitle("回溯法--走迷宮");

this.add(panel);

this.pack();

this.setVisible(true);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void init() {

panel = new JPanel();

northPanel = new JPanel();

centerPanel = new JPanel();

panel.setLayout(new BorderLayout());

restart = new JButton("重新生成迷宮");

dostart = new JButton("開始走迷宮");

grid = new MazeGrid[rows][cols];

centerPanel.setLayout(new GridLayout(rows, cols, 1, 1));

centerPanel.setBackground(new Color(0, 0, 0));

northPanel.add(restart);

northPanel.add(dostart);

dostart.addActionListener(this);

restart.addActionListener(this);

for (int i = 0; i grid.length; i++)

for (int j = 0; j grid[i].length; j++) {

if (j % 2 == 0 i % 2 == 0)

grid[i][j] = new MazeGrid(true, 20, 20);

else

grid[i][j] = new MazeGrid(false, 20, 20);

}

grid[0][0].setVisited(true);

grid[0][0].setPersonCome(true);

grid[0][0].setStart(true);

visited.add("0#0");

grid[rows - 1][cols - 1].setEnd(true);

grid = createMap(grid, 0, 0);

for (int i = 0; i grid.length; i++)

for (int j = 0; j grid[i].length; j++) {

grid[i][j].repaint();

centerPanel.add(grid[i][j]);

}

panel.add(northPanel, BorderLayout.NORTH);

panel.add(centerPanel, BorderLayout.CENTER);

}

/**

* 生成迷宮

*

* @param mazeGrid

* @param x

* @param y

* @return

*/

public MazeGrid[][] createMap(MazeGrid mazeGrid[][], int x, int y) {

int visitX = 0;

int visitY = 0;

if (x - 2 = 0) {

if (!mazeGrid[x - 2][y].isVisited()) {

willVisit.add((x - 2) + "#" + y);

}

}

if (x + 2 cols) {

if (!mazeGrid[x + 2][y].isVisited()) {

willVisit.add((x + 2) + "#" + y);

}

}

if (y - 2 = 0) {

if (!mazeGrid[x][y - 2].isVisited()) {

willVisit.add(x + "#" + (y - 2));

}

}

if (y + 2 rows) {

if (!mazeGrid[x][y + 2].isVisited()) {

willVisit.add(x + "#" + (y + 2));

}

}

if (!willVisit.isEmpty()) {

int visit = (int) (Math.random() * willVisit.size());

String id = willVisit.get(visit);

visitX = Integer.parseInt(id.split("#")[0]);

visitY = Integer.parseInt(id.split("#")[1]);

mazeGrid[(visitX + x) / 2][(visitY + y) / 2].setMark(true);

mazeGrid[visitX][visitY].setVisited(true);

if (!visited.contains(id)) {// 將這個(gè)點(diǎn)加到已訪問中去

visited.add(id);

}

willVisit.clear();

createMap(mazeGrid, visitX, visitY);

} else {

if (!visited.isEmpty()) {

String id = visited.remove(visited.size() - 1);// 取出最后一個(gè)元素

visitX = Integer.parseInt(id.split("#")[0]);

visitY = Integer.parseInt(id.split("#")[1]);

mazeGrid[visitX][visitY].setVisited(true);

createMap(mazeGrid, visitX, visitY);

}

}

return mazeGrid;

}

/**

* 走迷宮

*

* @param mazeGrid

* @param x

* @param y

*/

public String goMaze(MazeGrid mazeGrid[][], int x, int y) {

int comeX = 0;

int comeY = 0;

// left

if (x - 1 = 0) {

if (mazeGrid[x - 1][y].isMark()) {

if (!comed.contains((x - 1) + "#" + y))

willVisit.add((x - 1) + "#" + y);

}

}

// right

if (x + 1 cols) {

if (mazeGrid[x + 1][y].isMark()) {

if (!comed.contains((x + 1) + "#" + y))

willVisit.add((x + 1) + "#" + y);

}

}

// up

if (y - 1 = 0) {

if (mazeGrid[x][y - 1].isMark()) {

if (!comed.contains(x + "#" + (y - 1)))

willVisit.add(x + "#" + (y - 1));

}

}

// down

if (y + 1 rows) {

if (mazeGrid[x][y + 1].isMark()) {

if (!comed.contains(x + "#" + (y + 1)))

willVisit.add(x + "#" + (y + 1));

}

}

if (!willVisit.isEmpty()) {

int visit = (int) (Math.random() * willVisit.size());

String id = willVisit.get(visit);

comeX = Integer.parseInt(id.split("#")[0]);

comeY = Integer.parseInt(id.split("#")[1]);

mazeGrid[x][y].setPersonCome(false);

mazeGrid[comeX][comeY].setPersonCome(true);

mazeGrid[x][y].repaint();

mazeGrid[comeX][comeY].repaint();

willVisit.clear();

comed.add(x + "#" + y);

} else {

if (!comed.isEmpty()) {

String id = comed.removeLast();

comeX = Integer.parseInt(id.split("#")[0]);

comeY = Integer.parseInt(id.split("#")[1]);

mazeGrid[x][y].setPersonCome(false);

mazeGrid[comeX][comeY].setPersonCome(true);

mazeGrid[x][y].repaint();

mazeGrid[comeX][comeY].repaint();

comed.addFirst(x + "#" + y);

}

}

return comeX + "#" + comeY;

}

int comeX = 0;

int comeY = 0;

public void actionPerformed(ActionEvent e) {

if (e.getActionCommand().equals("重新生成迷宮")) {

refreshMap(grid);

} else if (e.getActionCommand().equals("開始走迷宮")) {

startTime = System.currentTimeMillis();

dostart.setVisible(false);

restart.setText("禁止刷新");

int delay = 1000;

int period = 500;// 循環(huán)間隔

java.util.Timer timer = new java.util.Timer();

timer.scheduleAtFixedRate(new TimerTask() {

public void run() {

if (grid[rows - 1][cols - 1].isPersonCome()) {

endTime = System.currentTimeMillis();

JOptionPane.showMessageDialog(null, "已經(jīng)走出迷宮,耗時(shí)"

+ (endTime - startTime) / 1000 + "秒", "消息提示",

JOptionPane.ERROR_MESSAGE);

this.cancel();

restart.setText("重新生成迷宮");

} else {

String id = goMaze(grid, comeX, comeY);

comeX = Integer.parseInt(id.split("#")[0]);

comeY = Integer.parseInt(id.split("#")[1]);

}

}

}, delay, period);

}

}

/**

* 刷新地圖

*/

public void refreshMap(MazeGrid mazeGrid[][]) {

comeX = 0;

comeY = 0;

willVisit.clear();

visited.clear();

comed.clear();

this.remove(panel);

init();

this.add(panel);

this.pack();

this.setVisible(true);

}

public static void main(String args[]) {

long start = System.currentTimeMillis();

new Maze();

long end = System.currentTimeMillis();

System.out.println("使用ArrayList生成迷宮耗時(shí):" + (end - start) + "毫秒");

}

}

JAVA走迷宮小游戲

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import javax.swing.event.*;

class JPanelEa1 extends JFrame implements MenuListener,ActionListener

{

JPanel mainp,p1,p2,p3,p4;

JTextField jt1;

JMenuItem mnuCopy;

JMenuItem mnuPaste;

JButton bM;

boolean isDouble = false;// 是否為實(shí)數(shù)

int opFlag = -1;

static double t1 = 0, t2 = 0, t3 = 0, result = 0;

static int opflag1 = -1, opflag2 = -1, flag = 0, resflag = 1;

int preOp, currentOp = 0;// 標(biāo)準(zhǔn)位

double op1 = 0, op2 = 0;// 操作數(shù)

double n3;

StringBuffer buf = new StringBuffer(20);

StringBuffer copyBoard = new StringBuffer(20);// 剪貼板

StringBuffer memory = new StringBuffer(20);// M系列

StringBuffer str = new StringBuffer();

public JPanelEa1()

{

p1=new JPanel();

p1.setLayout(new GridLayout(2,1,10,10));

JMenuBar mnuNotepad=new JMenuBar();

JMenu mnuEdit=new JMenu("編輯(E)");

mnuEdit.setMnemonic(KeyEvent.VK_E);

JMenu mnuCheck=new JMenu("查看(V)");

mnuCheck.setMnemonic(KeyEvent.VK_V);

JMenu mnuHelp=new JMenu("幫助(H)");

mnuCopy=new JMenuItem("復(fù)制(C)");

mnuPaste=new JMenuItem("粘貼(P)");

JMenuItem mnuVisit=new JMenuItem("查看幫助(V)");

JMenuItem mnuAbout=new JMenuItem("關(guān)于計(jì)算器(A)");

JSeparator sep=new JSeparator();

jt1=new JTextField("0.");

jt1.setEnabled(false);

jt1.setHorizontalAlignment(JTextField.RIGHT);

mnuEdit.addMenuListener(this);

mnuCheck.addMenuListener(this);

mnuHelp.addMenuListener(this);

mnuCopy.addActionListener(this);

mnuPaste.addActionListener(this);

mnuVisit.addActionListener(this);

mnuAbout.addActionListener(this);

mnuNotepad.add(mnuEdit);

mnuNotepad.add(mnuCheck);

mnuNotepad.add(mnuHelp);

mnuEdit.add(mnuCopy);

mnuEdit.add(mnuPaste);

mnuEdit.add(sep);

mnuHelp.add(mnuVisit);

mnuHelp.add(sep);

mnuHelp.add(mnuAbout);

p1.add(mnuNotepad);

p1.add(jt1);

p2=new JPanel();

p2.setLayout(new FlowLayout(FlowLayout.CENTER));

bM = new JButton(" ");

bM.setEnabled(false);

p2.add(bM);

Button b25=new Button("Backspace");

b25.addActionListener(this);

Button b26=new Button("CE");

b26.addActionListener(this);

Button b27=new Button("C");

b27.addActionListener(this);

p2.add(b25);

p2.add(b26);

p2.add(b27);

p3=new JPanel();

p3.setLayout(new GridLayout(4,6));

Button button1=new Button("MC");

button1.addActionListener(this);

Button button2=new Button("7");

button2.addActionListener(this);

Button button3=new Button("8");

button3.addActionListener(this);

Button button4=new Button("9");

button4.addActionListener(this);

Button button5=new Button("/");

button5.addActionListener(this);

Button button6=new Button("sqrt");

button6.addActionListener(this);

Button button7=new Button("MR");

button7.addActionListener(this);

Button button8=new Button("4");

button8.addActionListener(this);

Button button9=new Button("5");

button9.addActionListener(this);

Button button10=new Button("6");

button10.addActionListener(this);

Button button11=new Button("*");

button11.addActionListener(this);

Button button12=new Button("%");

button12.addActionListener(this);

Button button13=new Button("MS");

button13.addActionListener(this);

Button button14=new Button("1");

button14.addActionListener(this);

Button button15=new Button("2");

button15.addActionListener(this);

Button button16=new Button("3");

button16.addActionListener(this);

Button button17=new Button("-");

button17.addActionListener(this);

Button button18=new Button("1/x");

button18.addActionListener(this);

Button button19=new Button("M+");

button19.addActionListener(this);

Button button20=new Button("0");

button20.addActionListener(this);

Button button21=new Button("+/-");

button21.addActionListener(this);

Button button22=new Button(".");

button22.addActionListener(this);

Button button23=new Button("+");

button23.addActionListener(this);

Button button24=new Button("=");

button24.addActionListener(this);

p3.add(button1);p3.add(button2);

p3.add(button3);p3.add(button4);

p3.add(button5);p3.add(button6);

p3.add(button7);p3.add(button8);

p3.add(button9);p3.add(button10);

p3.add(button11);p3.add(button12);

p3.add(button13);p3.add(button14);

p3.add(button15);p3.add(button16);

p3.add(button17);p3.add(button18);

p3.add(button19);p3.add(button20);

p3.add(button21);p3.add(button22);

p3.add(button23);p3.add(button24);

setSize(250,150);

mainp=new JPanel();

mainp.setLayout(new GridLayout(3,1));

mainp.add(p1);

mainp.add(p2);

mainp.add(p3);

setContentPane(mainp);

setTitle("計(jì)算器");

setSize(300,300);

setVisible(true);

setDefaultCloseOperation(EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent e)

{

String s= e.getActionCommand();

if (s.equals("復(fù)制(C)")) {

String temp = jt1.getText().trim();

copyBoard.replace(0, copyBoard.length(), temp);

mnuPaste.setEnabled(true);

} else if (s.equals("粘貼(p)")) {

jt1.setText(copyBoard.toString());

} else if (s.equals("CE")) {

// 如果是CE則清除文本框

jt1.setText("0.");

} else if (s.equals("Backspace")) {

if (!jt1.getText().trim().equals("0.")) {

// 如果文本框中有內(nèi)容

if (str.length() != 1 str.length() != 0) {

jt1.setText(str.delete(str.length() - 1, str.length())

.toString());

} else {

jt1.setText("0.");

str.setLength(0);

}

}

op2 = Double.parseDouble(jt1.getText().trim());

} else if (s.equals("C")) {

// 如果是C刪除當(dāng)前計(jì)算

jt1.setText("0.");

op1 = op2 = 0;

str.replace(0, str.length(), " ");

preOp = currentOp = 0;

} else if (s.equals("MC")) {

// 如果是MC則清除緩沖區(qū)

String temp = "";

memory.replace(0, memory.length(), temp);

bM.setText(" ");

} else if (s.equals("MR")) {

// 如果按鍵為MR則恢復(fù)緩沖區(qū)的數(shù)到文本框

jt1.setText(memory.toString());

} else if (s.equals("MS")) {

// 如果按鍵為MS則將文本框的數(shù)存入緩沖區(qū)

String s1 = jt1.getText().trim();

memory.replace(0, memory.length(), s1);

bM.setText("M");

} else if (s.equals("M+")) {

// 如果按鍵為MS則將文本框值與緩沖區(qū)的數(shù)相加但不顯示結(jié)果

String temp1 = jt1.getText().trim();

double dtemp = Double.parseDouble(temp1);

String temp2 = memory.toString();

dtemp += Double.parseDouble(temp2);

temp1 = String.valueOf(dtemp);

memory.replace(0, memory.length(), temp1);

} else if (s.equals("1/x")) {

// 如果按鍵為1/x則將文本框中的數(shù)據(jù)為它的倒數(shù)

String temp = jt1.getText().trim();

double dtemp = Double.parseDouble(temp);

jt1.setText("" + 1 / dtemp);

} else if (s.equals("sqrt")) {

// 如果按鍵為sqrt則將文本框中的內(nèi)容求平方根

String temp = jt1.getText().trim();

double dtemp = Double.parseDouble(temp);

jt1.setText("" + Math.sqrt(dtemp));

} else if (s.equals("+")) {

str.setLength(0);

if (currentOp == 0) {

preOp = currentOp = 1;

op2 = 0;

jt1.setText("" + op1);

} else {

currentOp = preOp;

preOp = 1;

switch (currentOp) {

case 1:

op1 += op2;

jt1.setText("" + op1);

break;

case 2:

op1 -= op2;

jt1.setText("" + op1);

break;

case 3:

op1 *= op2;

jt1.setText("" + op1);

break;

case 4:

op1 /= op2;

jt1.setText("" + op1);

break;

}

}

} else if (s.equals("-")) {

str.setLength(0);

if (currentOp == 0) {

preOp = currentOp = 2;// op1=op2;op2=0;

jt1.setText("" + op1);

} else {

currentOp = preOp;

preOp = 2;

switch (currentOp) {

case 1:

op1 = op1 + op2;

jt1.setText("" + op1);

break;

case 2:

op1 = op1 - op2;

jt1.setText("" + op1);

break;

case 3:

op1 = op1 * op2;

jt1.setText("" + op1);

break;

case 4:

op1 = op1 / op2;

jt1.setText("" + op1);

break;

}

}

} else if (s.equals("*"))// *

{

str.setLength(0);

if (currentOp == 0) {

preOp = currentOp = 3;// op1=op2;op2=1;

jt1.setText("" + op1);// op1=op2;

} else {

currentOp = preOp;

preOp = 3;

switch (currentOp) {

case 1:

op1 = op1 + op2;

jt1.setText("" + op1);

break;

case 2:

op1 = op1 - op2;

jt1.setText("" + op1);

break;

case 3:

op1 = op1 * op2;

jt1.setText("" + op1);

break;

case 4:

op1 = op1 / op2;

jt1.setText("" + op1);

break;

}

}

} else if (s.equals("/"))// /

{

str.setLength(0);

if (currentOp == 0) {

preOp = currentOp = 4;// op2=1;

jt1.setText("" + op1);// op1=op2;

} else {

currentOp = preOp;

preOp = 4;

switch (currentOp) {

case 1:

op1 = op1 + op2;

jt1.setText("" + op1);

break;

case 2:

op1 = op1 - op2;

jt1.setText("" + op1);

break;

case 3:

op1 = op1 * op2;

jt1.setText("" + op1);

break;

case 4:

op1 = op1 / op2;

jt1.setText("" + op1);

break;

}

}

} else if (s.equals("="))// =

{

if (currentOp == 0) {

str.setLength(0);

jt1.setText("" + op2);

} else {

str.setLength(0);

currentOp = preOp;

switch (currentOp) {

case 1:

op1 = op1 + op2;

jt1.setText("" + op1);

break;

case 2:

op1 = op1 - op2;

jt1.setText("" + op1);

break;

case 3:

op1 = op1 * op2;

jt1.setText("" + op1);

break;

case 4:

op1 = op1 / op2;

jt1.setText("" + op1);

break;

}

currentOp = 0;

op2 = 0;

}

} else if (s.equals(".")) {

isDouble = true;

if (jt1.getText().trim().indexOf('.') != -1)

;

else {

if (jt1.getText().trim().equals("0")) {

str.setLength(0);

jt1.setText((str.append("0" + s)).toString());

}

// else

// if(jt1.getText().trim().equals("")){}//如果初時(shí)顯示為空則不做任何操作

else {

jt1.setText((str.append(s)).toString());

}

}

} else if (s.equals("0"))// 如果選擇的是"0"這個(gè)數(shù)字鍵

{

if (jt1.getText().trim().equals("0.")) {

} else {

jt1.setText(str.append(s).toString());

op2 = Double.parseDouble(jt1.getText().trim());

}

} else {

jt1.setText(str.append(s).toString());

op2 = Double.parseDouble(jt1.getText().trim());

if (currentOp == 0)

op1 = op2;

}

}

public static void main(String args[])

{

JPanelEa1 g=new JPanelEa1();

}

@Override

public void menuSelected(MenuEvent e) {

// TODO Auto-generated method stub

}

@Override

public void menuDeselected(MenuEvent e) {

// TODO Auto-generated method stub

}

@Override

public void menuCanceled(MenuEvent e) {

// TODO Auto-generated method stub

}

}

請(qǐng)幫忙用數(shù)據(jù)結(jié)構(gòu)(java版)的知識(shí)解決這道迷宮問題的程序代碼。

我這是用c寫的。你可以看看,希望能幫助到你。

#include"stdlib.h"

#include"stdio.h"

#define N 50

#define M 50

int X;

int maze[N+2][M+2];

struct point{

int row,col,predecessor;

}queue[512];

int head=0,tail=0;

void shoudong_maze(int m,int n){

int i,j;

printf("\n\n");

printf("請(qǐng)按行輸入迷宮,0表示通路,1表示障礙:\n\n");

for(i=0;im;i++)

for(j=0;jn;j++)

scanf("%d",maze[i][j]);

}

void zidong_maze(int m,int n){

int i,j;

printf("\n迷宮生成中……\n\n");

system("pause");

for(i=0;im;i++)

for(j=0;jn;j++)

maze[i][j]=rand()%2;

//由于rand()產(chǎn)生的隨機(jī)數(shù)是從0到RAND_MAX

//RAND_MAX是定義在stdlib.h中的,其值至少為32767)

//要產(chǎn)生從X到Y(jié)的數(shù),只需要這樣寫:k=rand()%(Y-X+1)+X;

}

void print_maze(int m,int n){

int i,j;

printf("\n迷宮生成結(jié)果如下:\n\n");

printf("迷宮入口\n");

printf("↓");

for(i=0;im;i++)

{printf("\n");

for(j=0;jn;j++)

{if(maze[i][j]==0) printf("□");

if(maze[i][j]==1) printf("■");}

}

printf("→迷宮出口\n");

}

void result_maze(int m,int n)

{ int i,j;

printf("迷宮通路(用☆表示)如下所示:\n\t");

for(i=0;im;i++)

{ printf("\n");

for(j=0;jn;j++)

{if(maze[i][j]==0||maze[i][j]==2) printf("□");

if(maze[i][j]==1) printf("■");

if(maze[i][j]==3) printf("☆");

}

}

}

void enqueue(struct point p)

{ queue[tail]=p;

tail++;

}

struct point dequeue()

{ head++;

return queue[head-1];

}

int is_empty()

{ return head==tail;

}

void visit(int row,int col,int maze[52][52])

{ struct point visit_point={row,col,head-1};

maze[row][col]=2;

enqueue(visit_point);

}

int mgpath(int maze[52][52],int m,int n)

{ X=1;

struct point p={0,0,-1};

if(maze[p.row][p.col]==1)

{ printf("\n===============================================\n");

printf("此迷宮無解\n\n");X=0;return 0;}

maze[p.row][p.col]=2;

enqueue(p);

while(!is_empty())

{p=dequeue();

if((p.row==m-1)(p.col==n-1)) break;

if((p.col+1n)(maze[p.row][p.col+1]==0)) visit(p.row,p.col+1,maze);

if((p.row+1m)(maze[p.row+1][p.col]==0)) visit(p.row+1,p.col,maze);

if((p.col-1=0)(maze[p.row][p.col-1]==0)) visit(p.row,p.col-1,maze);

if((p.row-1=0)(maze[p.row-1][p.col]==0)) visit(p.row-1,p.col,maze);

}

if(p.row==m-1p.col==n-1)

{printf("\n==================================================================\n");

printf("迷宮路徑為:\n");

printf("(%d,%d)\n",p.row,p.col);

maze[p.row][p.col]=3;

while(p.predecessor!=-1)

{p=queue[p.predecessor];

printf("(%d,%d)\n",p.row,p.col);

maze[p.row][p.col]=3;

}

}

else {printf("\n=============================================================\n");

printf("此迷宮無解!\n\n");X=0;}

return 0;

}

int main()

{int i,m,n,cycle=0;

while(cycle!=(-1))

{

printf("********************************************************************************\n");

printf(" ☆歡迎進(jìn)入迷宮求解系統(tǒng)☆\n");

printf(" 設(shè)計(jì)者:尹旭 林靜波(信息2班)\n");

printf("********************************************************************************\n");

printf(" 手動(dòng)生成迷宮 請(qǐng)按:1\n");

printf(" 自動(dòng)生成迷宮 請(qǐng)按:2\n");

printf(" 退出 請(qǐng)按:3\n\n");

printf("********************************************************************************\n");

printf("\n");

printf("請(qǐng)選擇你的操作:\n");

scanf("%d",i);

switch(i)

{case 1:printf("\n請(qǐng)輸入行數(shù):");

scanf("%d",m);

printf("\n");

printf("請(qǐng)輸入列數(shù):");

scanf("%d",n);

while((m=0||m50)||(n=0||n50))

{ printf("\n抱歉,你輸入的行列數(shù)超出預(yù)設(shè)范圍(0-50,0-50),請(qǐng)重新輸入:\n\n");

printf("請(qǐng)輸入行數(shù):");

scanf("%d",m);

printf("\n");

printf("請(qǐng)輸入列數(shù):");

scanf("%d",n);

}

shoudong_maze(m,n);

print_maze(m,n);

mgpath(maze,m,n);

if(X!=0)

result_maze(m,n);

printf("\n\nPress Enter Contiue!\n");

getchar();

while(getchar()!='\n');

break;

case 2:printf("\n請(qǐng)輸入行數(shù):");

scanf("%d",m);

printf("\n");

printf("請(qǐng)輸入列數(shù):");

scanf("%d",n);

while((m=0||m50)||(n=0||n50))

{printf("\n抱歉,你輸入的行列數(shù)超出預(yù)設(shè)范圍(0-50,0-50),請(qǐng)重新輸入:\n\n");

printf("請(qǐng)輸入行數(shù):");

scanf("%d",m);

printf("\n");

printf("請(qǐng)輸入列數(shù):");

scanf("%d",n);

}

zidong_maze(m,n);

print_maze(m,n);

mgpath(maze,m,n);

if(X!=0)

result_maze(m,n);

printf("\n\nPress Enter Contiue!\n");getchar();while(getchar()!='\n');break;

case 3:cycle=(-1);

break;

default:printf("\n");

printf("你的輸入有誤!\n");

printf("\nPress Enter Contiue!\n");

getchar();

while(getchar()!='\n');break;

}

}

}


分享標(biāo)題:java迷宮并求解代碼 java 走迷宮
網(wǎng)站路徑:http://weahome.cn/article/ddcshhi.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部