设为首页 加入收藏

TOP

营救公主(Java实现A*算法解决迷宫问题) (七)
2014-11-24 11:07:16 】 浏览:375
Tags:营救 公主 Java 实现 算法 解决 迷宫 问题
w][column]);
}
}

edgePosition = new Position(mazeMap.length, mazeMap[0].length);
}

public Position getPrincePosition()
{
return princePosition;
}

public Position getPrincessPosition()
{
return princessPosition;
}

/**
* 解析迷宫的位置信息
*/
private void parseMazePosition(Position currentPosition, char thing)
{
switch (thing)
{
case '.':
getAllReachablePositions().add(currentPosition);
break;
case '*':
break;
case 'S':
setPrincePosition(currentPosition);
break;
case 'P':
setPrincessPosition(currentPosition);
break;
default:
throw new UnknownElementException(null, thing);
}
}

private Position getOriginPosition()
{
return originPosition;
}

private Position getEdgePosition()
{
return edgePosition;
}

private void setPrincePosition(Position princePosition)
{
this.princePosition = princePosition;
}

private void setPrincessPosition(Position princessPosition)
{
this.princessPosition = princessPosition;
}

private List getAllReachablePositions()
{
return allReachablePositions;
}
}
[java]
import javax.lang.model.element.UnknownElementException;

/**
* 迷宫类:包含王子和迷宫地图两个对象
*
*/
public class Maze
{
/**
* 王子
*/
private Prince prince;

/**
* 迷宫地图
*/
private MazeMap map;

private boolean isInitOK = true;

public Maze(int time, char[][] map)
{
this.map = new MazeMap();
prince = new Prince(time);

initMap(map);
}

public void initMap(char[][] map)
{
try
{
getMap().initMazeMap(map);
getPrince().setMap(getMap());
}
catch (UnknownElementException e)
{
// TODO log
isInitOK = false;
}
}

/**
* 游戏开始:返回结果:-1表示营救失败;0表示营救成功
*
*/
public int start()
{
if (!isInitOK)
{
return -1;
}
return getPrince().startToSearch();
}

private MazeMap getMap()
{
return map;
}

private Prince getPrince()
{
return prince;
}
}

import javax.lang.model.element.UnknownElementException;

/**
* 迷宫类:包含王子和迷宫地图两个对象
*
*/
public class Maze
{
/**
* 王子
*/
private Prince prince;

/**
* 迷宫地图
*/
private MazeMap map;

private boolean isInitOK = true;

public Maze(int time, char[][] map)
{
this.map = new MazeMap();
prince = new Prince(time);

initMap(map);
}

public void initMap(char[][] map)
{
try
{
getMap().initMazeMap(map);
getPrince().setMap(getMap());
}
catch (UnknownElementException e)
{
// TODO log
isInitOK = false;
}
}

/**
* 游戏开始:返回结果:-1表示营救失败;0表示营救成功
*
*/
public int start()
{
if (!isInitOK)
{
return -1;
}
return getPrince().startToSearch();
}

private MazeMap getMap()
{
return map;
}

private Prince getPrince()
{
return prince;
}
}
[java]
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* 王子
*
* 类名称:Prince 类描述: 创建人:dobuy
*
*/
public class Prince
{
/**
* 营救公主失败
*/
private final static int FAIL = -1;

/**
* 营救公主成功
*/
private final static int SUCCESS = 0;

/**
* 剩余的时间
*/
private int time;

/**
* 迷宫地图
*/
private MazeMap map;

/**
* 正待尝试的位置集合(开启列表)
*/
private List attemptPositions;

首页 上一页 4 5 6 7 8 9 10 下一页 尾页 7/11/11
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇[小代码]如何捕获应用程序日志。 下一篇Java - 通过IP地址获取用户所在地

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目