mirror of
https://gitee.com/dromara/easyAi.git
synced 2024-12-02 03:38:08 +08:00
更改测试案例
This commit is contained in:
parent
922e6e9288
commit
3f56751906
@ -12,15 +12,16 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class GameRobotTest {
|
||||
private static DynamicProgramming dynamicProgramming = new DynamicProgramming();
|
||||
private static DynamicProgramming dynamicProgramming = new DynamicProgramming();//智能机器人
|
||||
|
||||
//游戏机器人测试
|
||||
//这是一个寻找宝藏的游戏,地图是一个6*6大小的格子地图,游戏里有1个宝藏,三个炸弹,每次宝藏和炸弹刷新的位置随机。
|
||||
//一个小人从地图的随机一个位置出发,共走六步,如果能拿到四个宝藏中的指定宝藏就成功。
|
||||
// 如果五步没有拿到宝藏就失败,或者五步之内撞到地图边缘同样也是失败,如果碰到炸弹同样失败。
|
||||
//一个小人从地图的随机一个位置出发,共走六步,如果能拿到指定宝藏就成功。
|
||||
// 如果六步没有拿到宝藏就失败,或者六步之内撞到地图边缘同样也是失败,如果碰到炸弹同样失败。
|
||||
public static void main(String[] args) throws Exception {
|
||||
dynamicProgramming.setGaMa(0.9);//取值范围(0-1),值越低越注重短期收益,值越高越注重长期收益
|
||||
dynamicProgramming.setMaxTimes(500);//取值范围(正整数),值越低速度越快精度越低,值越大速度越慢,精度越高
|
||||
dynamicProgramming.setValueTh(0.0001);//取值范围(很小的正数),值越低精度越大速度越慢,值越大精度越小速度越快
|
||||
//dynamicProgramming.setGaMa(0.9);//取值范围(0-1),值越低越注重短期收益,值越高越注重长期收益
|
||||
//dynamicProgramming.setMaxTimes(500);//取值范围(正整数),值越低速度越快精度越低,值越大速度越慢,精度越高
|
||||
//dynamicProgramming.setValueTh(0.0001);//取值范围(很小的正数),值越低精度越大速度越慢,值越大精度越小速度越快
|
||||
GameConfig gameConfig = new GameConfig();
|
||||
init(gameConfig);
|
||||
List<int[]> prizeList = gameConfig.getPrizeList();//生成随机四个奖品坐标
|
||||
@ -28,9 +29,12 @@ public class GameRobotTest {
|
||||
for (int i = 0; i < size; i++) {
|
||||
System.out.println("i==" + i + ",cood==" + Arrays.toString(prizeList.get(i)));
|
||||
}
|
||||
dynamicProgramming.gameStart();//先跑数据
|
||||
dynamicProgramming.gameStart();//探索
|
||||
dynamicProgramming.strategyStudy();//研究策略
|
||||
Matrix matrix = dynamicProgramming.getValueMatrix();
|
||||
//List<ValueFunction> valueFunctions = dynamicProgramming.getValueFunction();//返回一个多维的获取价值函数
|
||||
//List<Integer> actionList = dynamicProgramming.getBestAction(new int[]{1, 2});//获取下一步行动
|
||||
//返回一个动作id集合
|
||||
Matrix matrix = dynamicProgramming.getValueMatrix();//返回一个二维状态主键可打印的价值函数
|
||||
System.out.println(matrix.getString());
|
||||
}
|
||||
|
||||
@ -38,6 +42,7 @@ public class GameRobotTest {
|
||||
Random random = new Random();
|
||||
//初始化随机奖品位置
|
||||
List<int[]> prizeList = gameConfig.getPrizeList();//生成随机四个奖品坐标
|
||||
int[] cup = new int[]{random.nextInt(3) + 3, random.nextInt(3) + 3};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
@ -47,20 +52,20 @@ public class GameRobotTest {
|
||||
prizeList.add(new int[]{random.nextInt(3) + 3, random.nextInt(3)});
|
||||
break;
|
||||
case 2:
|
||||
prizeList.add(new int[]{random.nextInt(3) + 3, random.nextInt(3) + 3});
|
||||
prizeList.add(cup);
|
||||
break;
|
||||
case 3:
|
||||
prizeList.add(new int[]{random.nextInt(3), random.nextInt(3) + 3});
|
||||
break;
|
||||
}
|
||||
}
|
||||
//加载状态
|
||||
//加载状态 生成地图
|
||||
List<DynamicState> dynamicStateList = dynamicProgramming.getDynamicStateList();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
for (int j = 0; j < 6; j++) {
|
||||
int[] stateId = new int[]{i, j};
|
||||
DynamicState dynamicState = new DynamicState(stateId);
|
||||
//dynamicState.setFinish(isFinish(gameConfig, stateId));//设置终结态
|
||||
dynamicState.setFinish(isFinish(gameConfig, stateId));//设置终结态
|
||||
dynamicStateList.add(dynamicState);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class Left extends Action {//向左移动
|
||||
super.setActionId(actionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override//动作 参数是 执行该动作的状态
|
||||
protected int[] action(int[] stateId) {//左移动作
|
||||
int x = stateId[0];//横坐标
|
||||
int y = stateId[1];//纵坐标
|
||||
@ -36,7 +36,7 @@ public class Left extends Action {//向左移动
|
||||
return new int[]{x, y};
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override//该动作带来的收益
|
||||
protected int getProfit(int[] stateId) {//左移后的惩罚或者奖励值设置
|
||||
int profit = 0;
|
||||
if (stateId[0] == 0) {//如果左移会撞墙,给惩罚-10
|
||||
|
Loading…
Reference in New Issue
Block a user