实训总结

实训任务

  1. 阶段 1 了解GridWorld以及接触入门学习ant,junit,sonar等
  2. 阶段 2 对GridWorld进行扩展
  3. 阶段3 图像处理,学习一些算法比如Astar算法

实训内容及总结

阶段一 学习ant,junit,sonar,vim以及运行gridworld

vim

vim是很基础的linux编辑器,之前课程中经常使用,所以这次学习基本上就是复习,不过我更喜欢用gedit,还有eclipse,所以实际上这次实训期间使用后者比较多,因为eclipse会有语法提示等等,eclipse对于java 的学习帮助很大

ant

ant是一个构建工具,和之前学习的makefile,cmake作用类似,尤其对于大型项目而言,使用这些构建工具无疑是省力很多

sonar

一开始我是在自己的笔记本上配置环境去安装sonar的,安装成功后使用时却总有一些问题,所以第二周在实验室里使用了ta配置好的sonar环境,进去SONAR_HOME,命令行输入./sonar.sh start,然后就可以回到项目下进行sonar分析了,一开始不明白sonar分析有什么意义,只是按照任务去分析了,最后在localhost:9000查看到自己的代码要么是命名不规范要么是注释格式什么的有问题,ta也和我仔细讲了,才意识到自己之前从没注意过这些规范小细节,但是无疑根据sonar分析后的数据修改源码,源码美观了很多,而且也帮助我加强了写注释的意识

junit

junit作为测试单元也非常好用,之前学习c,c++什么的时候,每次测试都是自己手动输入测试,简直要烦死了,有了这个以后测试会省力很多

计算器

计算器的设计这次要求的功能比较少,只要求加减乘除和GUI的使用,但是在TA检查后才去注意到一些逻辑上的错误问题——除数为0时无反应,这里我应该加上报错或者输出提示infinity

运行gridworld
云平台中已经预装好Java (openJDK) 环境,在终端中输入以下命令可以看到java的版本信息。
java -version
云平台中已经预装好了apache ant 环境,在 shell命令行敲入以下命令:
ant
如果显示以下信息,则表明已安装 ant。

Buildfile: build.xml does not exist!
Build failed
在 shell 命令行中编译以及执行 BugRunner 的方法

路径中有空格的可使用’‘包含路径。

## 编译
javac -classpath .:gridworld.jar 所要编译的 java 文件所在目录路径/BugRunner.java
## 执行
java -classpath .:gridworld.jar:所要执行的 class 文件所在的目录路径  BugRunner
如果将gridworld.jar文件包含到JAVA的安装目录中,并在CLASSPATH中引用gridworld.jar包,则可以这样执行

## 编译:
javac 要编译的java文件所在的目录路径/BugRunner.java
## 执行:
java 所要执行的 class 文件所在的目录路径  BugRunner
推荐一个java教程:http://www.cnblogs.com/vamei/archive/2013/03/31/2991531.html

然后ant的直接build+run闪退的看这里:http://hellokenlee.blog.163.com/blog/static/213933032201462282950245/

first project运行: 命令行进入到 $Gridworld_Project/GridWorldCode/projects/firstProject
## 编译:
javac -classpath .:./../../gridworld.jar BugRunner.java
## 执行:
java  -classpath .:./../../gridworld.jar BugRunner
gridworld.jar是预先打包构建好的,为本次实训提供教学框架的代码包(jar),在各个阶段开发中,需要将其引入到我们的编译之中。

在实际运行时,一开始由于粗心没注意到javac java 命令后面的“:”的区别,没有编译成功,仔细检查之后很成功的运行了

总结

阶段一的时候身体不太舒服,没有及时进入状态,还好阶段一的任务并不是很重,所以最后并没有耽误很多,同时在这里学习了几个工具的使用,收获很大,同时熟悉了Java,从Helloworld开始到计算器,难度不大,但是比较考验细节。

阶段二 完成对gridworld的part2-5 扩展

CircleBug SpiralBug ZBug DancingBug

这里继承了bug,然后对他们的act进行修改补充等可以重新定义他们的行动方式,比如ZBug,要求是运行完一个Z就停止,那么整个过程就是运动三条线,所以可以设置一个变量所以状态指示器,状态1,3都是向右走,类似这样定义不同的行动

Jumper

这里要考虑如下一些问题:

Inception: clarify the details of the problem:

a. What will a jumper do if the location in front of it is empty, but the location two cells in front contains a flower or a rock?

b. What will a jumper do if the location two cells in front of the jumper is out of the grid?

c. What will a jumper do if it is facing an edge of the grid?

d. What will a jumper do if another actor (not a flower or a rock) is in the cell that is two cells in front of the jumper?

e. What will a jumper do if it encounters another jumper in its path?

f. Are there any other tests the jumper needs to make?

* You should answer the above questions simply in your design report.

Elaboration: solve the following problems:

a. Which class should Jumper extend?

b. Is there an existing class that is similar to the Jumper class?

c. Should there be a constructor? If yes, what parameters should be specified for the constructor?

d. Which methods should be overridden?

e. What methods, if any, should be added?

f. What is the plan for testing the class?

* You don’t need to write down your answers to this group of questions, just think about them and go to the construction part.

Construction: Implement the Jumper and JumperRunner classes.

Test: Carry out the test plan with junit to verify that the Jumper class meets the specification.
ChameleonKid RockHound BlusterCritter QuickCrab KingCrab

这里需要这两个类ChameleonCritter CrabCritter,根据要求:

Create a class called ChameleonKid that extends ChameleonCritter as modified in exercise 1. A ChameleonKid changes its color to the color of one of the actors immediately in front or behind. If there is no actor in either of these locations, then the ChameleonKid darkens like the modified ChameleonCritter.
Create a class called RockHound that extends Critter. A RockHound gets the actors to be processed in the same way as a Critter. It removes any rocks in that list from the grid. A RockHound moves like a Critter.
Create a class BlusterCritter that extends Critter. A BlusterCritter looks at all of the neighbors within two steps of its current location. (For a BlusterCritter not near an edge, this includes 24 locations). It counts the number of critters in those locations. If there are fewer than c critters, the BlusterCritter’s color gets brighter (color values increase). If there are c or more critters, the BlusterCritter’s color darkens (color values decrease). Here, c is a value that indicates the courage of the critter. It should be set in the constructor.
Create a class QuickCrab that extends CrabCritter. A QuickCrab processes actors the same way a CrabCritter does. A QuickCrab moves to one of the two locations, randomly selected, that are two spaces to its right or left, if that location and the intervening location are both empty. Otherwise, a QuickCrab moves like a CrabCritter.
Create a class KingCrab that extends CrabCritter. A KingCrab gets the actors to be processed in the same way a CrabCritter does. A KingCrab causes each actor that it processes to move one location further away from the KingCrab. If the actor cannot move away, the KingCrab removes it from the grid. When the KingCrab has completed processing the actors, it moves like a CrabCritter.

这里也要注意细节,一开始我没注意到一些细节导致出错了

bounded unbounded map

这里是对地图做一些扩充

阶段三

image reader

这里是读入图像进行处理,读入就是简单的文件读写操作,然后提取rgb三个通道的方法也很简单,比如红色只提取第一个——(R, 0,0),类似如此,灰色的话就稍微复杂点需要一个函数来处理

mazeBug

这里用到了深度优先搜索,概率,回溯等方法——一开始随机走,然后如果向着某个方向走的次数越多代表这个方向概率越大,下次随机走的时候更有可能向着这个方向探索,如果到了死路就回退重新探索

Npuzzle

这里学习了广搜和A*算法(启发式搜索)
广搜和深搜经常会遇到一个问题——跑不出来,因为要遍历所有的情况,这里不知道其他同学的广搜有没有成功,这里我一直没跑出来,算法思想呢,就和深搜差不多了
我们开始先把所有节点标记为未访问,然后访问一个标记一个直到所有可能的情况都遍历了

A*算法在人工智能课程里已经学习过了,计算的关键是下面这个等式:
F = G + H
这里,G = 从起点 A 移动到指定方格的移动代价,沿着到达该方格而生成的路径。
H = 从指定的方格移动到终点 B 的估算成本。这里我用的估算方法是距离函数——根号下(x平方+y平方)
我们的路径是这么产生的:反复遍历 open list ,选择 F 值最小的方格。为了继续搜索,我们从 open list 中选择 F 值最小的 ( 方格 ) 节点,然后对所选择的方格作如下操作:把它从 open list 里取出,放到 close list 中。检查所有与它相邻的方格,忽略其中在 close list 中或是不可走 (unwalkable) 的方格 ( 比如石头) ,如果方格不在open lsit 中,则把它们加入到 open list 中。把我们选定的方格设置为这些新加入的方格的父亲。如果某个相邻的方格已经在 open list 中,则检查这条路径是否更优,也就是说经由当前方格 ( 我们选中的方格 ) 到达那个方格是否具有更小的 G 值。如果没有,不做任何操作。相反,如果 G 值更小,则把那个方格的父亲设为当前方格 ( 我们选中的方格 ) ,然后重新计算那个方格的 F 值和 G 值。

总结

这里实训只有四周时间,双休日都可以实验,学习了不少工具还有一些算法,收获很大

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值