Code Combat -- Clash of Clones by shenchensucc

View this thread on steempeak.com
· @shenchensucc ·
$5.71
Code Combat -- Clash of Clones
体验了一小把自制战略的乐趣,这一关比较开放;比起前面大多数关卡系统已经给出程序框架,本关完全自己编程制定策略。

简单来说,自己控制英雄在一场团战中胜利。敌方总兵力大于己方兵力,所以要有策略来打败敌人。

我的策略也很简单。首先走到地方的弓箭手的位置,弓箭手攻击力高,防御低,在自动对战中是主要的攻击兵种。打死了弓箭手就可以大幅减少敌方的攻击。所以我用了判断语句:    if enemy.type == "archer":,来判断是否攻击。消灭敌方所有弓箭手之后,就是要保证自己英雄存活。我就使用了另一个判断语句:if hero.health > 100:,让英雄的血量小于100时他可以逃走。


![image.png](https://cdn.steemitimages.com/DQmQNd7zLXK81oxRSF6DwxwTPbZSUWX6Ztc2qTbsE99i3Tb/image.png)


![image.png](https://cdn.steemitimages.com/DQmdRuagcBtCeruAxz2MebUktW5PYR6cQvYddyECCorzpRm/image.png)

代码如下:

~~~
# 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)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 119 others
properties (23)
post_id86,531,575
authorshenchensucc
permlinkcode-combat-clash-of-clones
categoryhive-180932
json_metadata{"tags":["cn","cn-programming","jjm","whalepower","zzan","dblog","diamondtoken","marlians","upfundme","actnearn"],"image":["https:\/\/cdn.steemitimages.com\/DQmQNd7zLXK81oxRSF6DwxwTPbZSUWX6Ztc2qTbsE99i3Tb\/image.png","https:\/\/cdn.steemitimages.com\/DQmdRuagcBtCeruAxz2MebUktW5PYR6cQvYddyECCorzpRm\/image.png"],"app":"steemcn\/0.1","format":"markdown"}
created2020-07-01 02:34:30
last_update2020-07-01 02:34:30
depth0
children2
net_rshares9,461,571,691,348
last_payout2020-07-08 02:34:30
cashout_time1969-12-31 23:59:59
total_payout_value2.916 SBD
curator_payout_value2.793 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length989
author_reputation308,239,923,974,515
root_title"Code Combat -- Clash of Clones"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (183)
@sunai ·
啪啪啪
properties (22)
post_id86,538,067
authorsunai
permlinkqcsofe
categoryhive-180932
json_metadata{"app":"steemcn\/0.1"}
created2020-07-01 14:33:18
last_update2020-07-01 14:33:18
depth1
children0
net_rshares0
last_payout2020-07-08 14:33:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length3
author_reputation82,329,514,724,848
root_title"Code Combat -- Clash of Clones"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@wilhb81 ·
有时间,我也要去学习制作游戏代码,拍拍~
properties (22)
post_id86,544,429
authorwilhb81
permlinkqctpxq
categoryhive-180932
json_metadata{"app":"steemcn\/0.1"}
created2020-07-02 04:03:27
last_update2020-07-02 04:03:27
depth1
children0
net_rshares0
last_payout2020-07-09 04:03:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length20
author_reputation451,278,293,500,053
root_title"Code Combat -- Clash of Clones"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000