《课程格子》的一个笔试题目
2012-11-16 19:39
267 查看
题目如下,感觉很适合喜欢琢磨的程序员,也是考验你编码风格的时候。
Let's make a tower defense game(塔防游戏):
1. You have 1 tower, with H health and D dps(damage per second).
2. There are n attackers, each with h_i health and d_i dps.
3. The attackers are represented by an array [h_0, d_0, h_1, d_1, ...]
4. The tower deals damage to attackers in order, starting with i = 0
5. When the health of an attacker reaches 0, they die and cease to deal further damage
6. If the tower's health reaches 0, you lose
Please write a function to report the result of the battle:
If your tower dies and you lose, return 0
If your tower survives the attack, please return the amount of health left on the tower
Example function:
boolean tower_defense(int H, int D, int[] attackers);
Bonus Question:
If you do not have to deal damage to attackers in order, and can instead pick your targets, how would you improve the "AI" of your tower?
Example function:
boolean smart_tower_defense(int H, int D, int[] attackers);
Please submit sample code in a language of your choice ALONG WITH UNIT TESTS to demonstration 3-4 interesting cases. Bonus points for the following set of languages(Ruby, Objective-C, Java, Javascript)
FAQ:
If the tower and the last enemy dies at the same time, still return 0
The tower is not able to split its attack(each second, it deals exactly D damage to a single attacker)
//翻译如下.........................................................
让我们来制作一个塔防游戏:
(1)仅有一个塔,有H生命值和D攻击值;
(2)有n个进攻者,每个有h_i生命值和d_i攻击值;
(3)进攻者用数组[h_0,d_0,h_1,d-1...]表示;
(4)塔对进攻者的伤害是有序的,由i=0开始;
(5)当进攻者的生命值为0时,将会死亡并停止造成进一步的伤害;
(6)如果塔的生命值为0,游戏失败。
请书写一个函数来报告战斗的结果:
如果塔死掉和失败,返回0;
如果塔在攻击中存活,返回塔的生命值。
样例函数:
boolean tower_defense(int H, int D, int[] attackers);
奖励问题:
如果塔不是对进攻者采用顺序攻击,而是挑选目标,你如何改进塔的AI?
样例函数:
boolean smart_tower_defense(int H, int D, int[] attackers);
请提交代码和测试用例来说明3-4个有趣的例子。
FAQ:如果塔和最后一名进攻者在同时死掉,仍返回0。
塔不能分裂攻击(每次,它仅仅对一个进攻者造成D伤害)
Let's make a tower defense game(塔防游戏):
1. You have 1 tower, with H health and D dps(damage per second).
2. There are n attackers, each with h_i health and d_i dps.
3. The attackers are represented by an array [h_0, d_0, h_1, d_1, ...]
4. The tower deals damage to attackers in order, starting with i = 0
5. When the health of an attacker reaches 0, they die and cease to deal further damage
6. If the tower's health reaches 0, you lose
Please write a function to report the result of the battle:
If your tower dies and you lose, return 0
If your tower survives the attack, please return the amount of health left on the tower
Example function:
boolean tower_defense(int H, int D, int[] attackers);
Bonus Question:
If you do not have to deal damage to attackers in order, and can instead pick your targets, how would you improve the "AI" of your tower?
Example function:
boolean smart_tower_defense(int H, int D, int[] attackers);
Please submit sample code in a language of your choice ALONG WITH UNIT TESTS to demonstration 3-4 interesting cases. Bonus points for the following set of languages(Ruby, Objective-C, Java, Javascript)
FAQ:
If the tower and the last enemy dies at the same time, still return 0
The tower is not able to split its attack(each second, it deals exactly D damage to a single attacker)
//翻译如下.........................................................
让我们来制作一个塔防游戏:
(1)仅有一个塔,有H生命值和D攻击值;
(2)有n个进攻者,每个有h_i生命值和d_i攻击值;
(3)进攻者用数组[h_0,d_0,h_1,d-1...]表示;
(4)塔对进攻者的伤害是有序的,由i=0开始;
(5)当进攻者的生命值为0时,将会死亡并停止造成进一步的伤害;
(6)如果塔的生命值为0,游戏失败。
请书写一个函数来报告战斗的结果:
如果塔死掉和失败,返回0;
如果塔在攻击中存活,返回塔的生命值。
样例函数:
boolean tower_defense(int H, int D, int[] attackers);
奖励问题:
如果塔不是对进攻者采用顺序攻击,而是挑选目标,你如何改进塔的AI?
样例函数:
boolean smart_tower_defense(int H, int D, int[] attackers);
请提交代码和测试用例来说明3-4个有趣的例子。
FAQ:如果塔和最后一名进攻者在同时死掉,仍返回0。
塔不能分裂攻击(每次,它仅仅对一个进攻者造成D伤害)
相关文章推荐
- cookie和session的区别(搜狐笔试考到的一个题目)
- 一个公司的笔试题目
- [笔试题目]使用Stringbuffer无 参的构造函数创建 一个对象时,默认的初始容量是多少? 如果长度不够使用了,自动增长多少倍?
- EMC的一个笔试题目
- EMC的一个笔试题目
- 阿里巴巴校招2017前端笔试题目 -- 原生js/html5 实现一个路由
- 一个关于SQL的笔试题目及解答
- 阿里的一个笔试题目,求积水体积。
- 一道笔试题 题目是这样的:判断一个小于1000的正整数是否为素数。
- 据说是一个著名公司的笔试题目
- 一个JavaScript笔试题目
- 关于360笔试题的一个题目的以下代码执行后输出结果为()思考
- 百度前端笔试题目--css 实现一个带尖角的正方形
- (笔试中的题目)一个已经排序好的数组找到两个数字相加等于一个给定的数
- 一个笔试题目
- 咪咕笔试题目:统计键盘写入一个字符串的按键点击次数
- 一个关于的指针的经典笔试题目,加上自己的一点体会
- 明源笔试题目--将一个正整数分解质因数
- 问对于一个给定的n,怎样才能用最少的步骤将它变到1。--淘宝笔试题目
- 看了SAP的笔试题目,顺手写一个单件模式