|
10鱼币
本帖最后由 戴宇轩 于 2015-8-2 20:44 编辑
第一段: - import random as r
- def move(step=r.randint(1,2)):
- power=100
- x = r.randint(0, 10)
- y = r.randint(0, 10)
- direction=r.randint(0,1)
- if direction==1:
- x+=step
- y+=step
- else:
- x-=step
- y-=step
- power-=1
- if 0<=x<=10 and 0<=y<=10:
- return (power,(x,y))
- else:
- return move(step=r.randint(1,2))
复制代码
第二段:- import random as r
- def move():
- power = 100
- x = r.randint(0, 10)
- y = r.randint(0, 10)
- new_x = x + r.choice([1, 2, -1, -2])
- new_y = y + r.choice([1, 2, -1, -2])
- if new_x <0:
- x = 0 - (new_x - 0)
- elif new_x > 10:
- x = 10 - (new_x - 10)
- else:
- x = new_x
- if new_y <0:
- y = 0 - (new_y - 0)
- elif new_y > 10:
- y = 10 - (new_y - 10)
- else:
- y = new_y
- power -= 1
- return (power,(x, y))
复制代码 |
最佳答案
查看完整内容
一样吧,你试试结果,写几个极值,test一下就完了
|