拼图小游戏
结对队友:031802620 刘京一
她的博客链接:031802620
Github链接:031802623 031802620
具体分工:
| 031802623 | AI | |
|---|---|---|
| 031802620 | 原型设计实践 | 原型设计 |
2.1 原型设计
2.2 AI与原型设计实现
2.2.1 代码实现思路:
1>网络接口的使用:
python获取接口数据的方式如下:
import request as rq
import json
url = "http://47.102.118.1:8089/api/challenge/start/392eaf5a-f533-4411-a712-344b59a37f0c"
data={'teamid':43,'token':'db89ae69-2536-4f96-91b0-d1c998a7850b'}
data = json.dumps(data)
# 有的时候data需要时json类型的
headers = {'content-type': "application/json"}
req = rq.post(url=url,data=data,headers=headers)
a=json.loads(req.text)
b=a.get("data")
print("第几步进行强制转换: ", b.get("step"))
print("调换的图片编号: ", b.get("swap"))
print("题目标识: ", a.get("uuid"))
print("是否成功:",a.get("success"))
2>代码组织与内部实现设计(类图):

3>算法关键流程图:

4>关键代码:
def init(self, start, pos, target):
IDAstar.start = start
IDAstar.pos = pos
IDAstar.target = target
IDAstar.init = Board(start, pos)
IDAstar.maxdep = 0 # 搜索的最大深度
IDAstar.path = ""
def dfs(self, now, lastd):
#开始深度搜索
if now.cost > self.maxdep:
return False
if now.stat == self.target:
return True
pos = now.pos
step = now.step
for i in range(4):
# 方向不可走时
if self.d[pos][i] == -1:
continue
stat = copy.deepcopy(now.stat)
# 0, 1, 2, 3
# w, d, s, a
# 上一步为向左,此步则不能向右走老路,其他方向同理。
if (lastd == -1) or (lastd % 2) != (i % 2) or (lastd == i):
stat[pos], stat[self.d[pos][i]] = stat[self.d[pos][i]], stat[pos]
# 构造函数形式:
# Board(stat, pos, step=0, preboard=None, prepath=[])
temp = Board(stat, self.d[pos][i], step + 1, now, self.index_to_direct[i])
# 如果找到最短路径,递归地记录路径
if self.dfs(temp, i):
self.path += temp.prepath
return True
return False
def IDA(self):
self.maxdep = self.init.cost
while not self.dfs(self.init, -1):
self.maxdep += 1
self.path = self.path[::-1]
return self.path
5>性能分析:


6>部分测试结果:

2.2.2 GitHub签入记录:

2.2.3 遇到的代码模块异常或结对困难及解决方法:
1>问题: 如何判断该八数码是否有解?
2>判断是否有解的原理
2.2.4 评价队友:
1>值得学习的地方:
我的队友超强的,算法思路清晰明确,编码能力极佳,这些都是我所欠缺的。
2>需要改进的地方:
太懒了,每次都在deadline前一刻才出炉完整代码。
2.2.5 PSP表格:
| 第N周 | 新增代码 | 累计代码 | 本周学习耗时(小时) | 累计学习耗时(小时) | 重要成长 |
|---|---|---|---|---|---|
| 1 | 87 | 87 | 7 | 7 | 学习了如何使图像切片以及打乱 |
| 2 | 141 | 228 | 10 | 17 | 学习A*算法,深度搜索 |
| 3 | 228 | 456 | 20 | 37 | 了解有关判断八数码是否有解的原理 |
| 4 | 117 | 573 | 5 | 42 | 学习关于接口的使用 |
浙公网安备 33010602011771号