体验了一小把自制战略的乐趣,这一关比较开放;比起前面大多数关卡系统已经给出程序框架,本关完全自己编程制定策略。
简单来说,自己控制英雄在一场团战中胜利。敌方总兵力大于己方兵力,所以要有策略来打败敌人。
我的策略也很简单。首先走到地方的弓箭手的位置,弓箭手攻击力高,防御低,在自动对战中是主要的攻击兵种。打死了弓箭手就可以大幅减少敌方的攻击。所以我用了判断语句: if enemy.type == "archer":,来判断是否攻击。消灭敌方所有弓箭手之后,就是要保证自己英雄存活。我就使用了另一个判断语句:if hero.health > 100:,让英雄的血量小于100时他可以逃走。
代码如下:
# You'll need good strategy to win this one!
# Your clone will have the same equipment you have!
# But, they're not very skilled at using special powers.
hero.moveXY(83, 86)
while hero.pos.y > 45:
enemy = hero.findNearestEnemy()
if enemy.type == "archer":
hero.attack(enemy)
else:
hero.moveXY(hero.pos.x, hero.pos.y - 5)
while True:
if hero.health > 100:
hero.attack(hero.findNearestEnemy())
else:
hero.moveXY(49, 74)