Exercism.org-Java-Annalyn's Infiltration

https://exercism.org/tracks/java/exercises/annalyns-infiltration

Instructions

In this exercise, you’ll be implementing the quest logic for a new RPG game a friend is developing. The game’s main character is Annalyn, a brave girl with a fierce and loyal pet dog. Unfortunately, disaster strikes, as her best friend was kidnapped while searching for berries in the forest. Annalyn will try to find and free her best friend, optionally taking her dog with her on this quest.

After some time spent following her best friend’s trail, she finds the camp in which her best friend is imprisoned. It turns out there are two kidnappers: a mighty knight and a cunning archer.

Having found the kidnappers, Annalyn considers which of the following actions she can engage in:

  • Fast attack: a fast attack can be made if the knight is sleeping, as it takes time for him to get his armor on, so he will be vulnerable.
  • Spy: the group can be spied upon if at least one of them is awake. Otherwise, spying is a waste of time.
  • Signal prisoner: the prisoner can be signalled using bird sounds if the prisoner is awake and the archer is sleeping, as archers are trained in bird signaling, so they could intercept the message.
  • Free prisoner: Annalyn can try sneaking into the camp to free the prisoner. This is a risky thing to do and can only succeed in one of two ways:
    • If Annalyn has her pet dog with her she can rescue the prisoner if the archer is asleep. The knight is scared of the dog and the archer will not have time to get ready before Annalyn and the prisoner can escape.
    • If Annalyn does not have her dog then she and the prisoner must be very sneaky! Annalyn can free the prisoner if the prisoner is awake and the knight and archer are both sleeping, but if the prisoner is sleeping they can’t be rescued: the prisoner would be startled by Annalyn’s sudden appearance and wake up the knight and archer.

You have four tasks: to implement the logic for determining if the above actions are available based on the state of the three characters found in the forest and whether Annalyn’s pet dog is present or not.

1. Check if a fast attack can be made

Implement the (staticAnnalynsInfiltration.canFastAttack() method that takes a boolean value that indicates if the knight is awake. This method returns true if a fast attack can be made based on the state of the knight. Otherwise, returns false:

1
2
3
boolean knightIsAwake = true;
AnnalynsInfiltration.canFastAttack(knightIsAwake);
// => false

2. Check if the group can be spied upon

Implement the (staticAnnalynsInfiltration.canSpy() method that takes three boolean values, indicating if the knight, archer and the prisoner, respectively, are awake. The method returns true if the group can be spied upon, based on the state of the three characters. Otherwise, returns false:

1
2
3
4
5
boolean knightIsAwake = false;
boolean archerIsAwake = true;
boolean prisonerIsAwake = false;
AnnalynsInfiltration.canSpy(knightIsAwake, archerIsAwake, prisonerIsAwake);
// => true

3. Check if the prisoner can be signalled

Implement the (staticAnnalynsInfiltration.canSignalPrisoner() method that takes two boolean values, indicating if the archer and the prisoner, respectively, are awake. The method returns true if the prisoner can be signalled, based on the state of the two characters. Otherwise, returns false:

1
2
3
4
boolean archerIsAwake = false;
boolean prisonerIsAwake = true;
AnnalynsInfiltration.canSignalPrisoner(archerIsAwake, prisonerIsAwake);
// => true

4. Check if the prisoner can be freed

Implement the (staticAnnalynsInfiltration.canFreePrisoner() method that takes four boolean values. The first three parameters indicate if the knight, archer and the prisoner, respectively, are awake. The last parameter indicates if Annalyn’s pet dog is present. The method returns true if the prisoner can be freed based on the state of the three characters and Annalyn’s pet dog presence. Otherwise, it returns false:

1
2
3
4
5
6
boolean knightIsAwake = false;
boolean archerIsAwake = true;
boolean prisonerIsAwake = false;
boolean petDogIsPresent = false;
AnnalynsInfiltration.canFreePrisoner(knightIsAwake, archerIsAwake, prisonerIsAwake, petDogIsPresent);
// => false

Question Answers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class AnnalynsInfiltration {
public static boolean canFastAttack(boolean knightIsAwake) {
return !knightIsAwake;
}

public static boolean canSpy(boolean knightIsAwake, boolean archerIsAwake, boolean prisonerIsAwake) {
return knightIsAwake || archerIsAwake || prisonerIsAwake;
}

public static boolean canSignalPrisoner(boolean archerIsAwake, boolean prisonerIsAwake) {
return prisonerIsAwake && !archerIsAwake;
}

public static boolean canFreePrisoner(boolean knightIsAwake, boolean archerIsAwake, boolean prisonerIsAwake, boolean petDogIsPresent) {
return (prisonerIsAwake && !archerIsAwake && !knightIsAwake) || (!archerIsAwake && petDogIsPresent);
}
}

Word

represented
v.
代表,表示;(在竞赛或体育赛事中)代表(国家或地区);(标志或符号)意味着,代表着,标志着;描绘,(形象地)表现,描写;代理(个人或团体);代表(个人或团体)出席;使有代表性,使有代表作;使呈现;陈述,诉说;象征;展示;相当于,相等于;作为……的代表(代言人);表述;想象,设想;演出,扮演;提出异议,提出抗议;维护……的利益;回想;再提出;作为……的象征;典型地反映;成为……实例,成为典型;再呈现;抗议说;再递交;再上演,再演出;集中地体现;再赠送

implement
vt.
实施;执行;贯彻;使生效
n.
工具;器具;(常指)简单的户外用具

implementing
v.
实施;执行;贯彻;使生效
implement的现在分词

quest
n.
追求(幸福等);探索;寻找
vi.
探索;探求

logic
n.
逻辑;逻辑学;(做某事的)道理,合乎情理的原因;逻辑系统;思维方式;解释方法

develop
v.
发展;发展,变化;开发;加强;研制;出现(问题);使(胶卷)显影;(使)成长;壮大; 患(病);修建;详尽阐述;(问题)开始影响;(疾病)开始侵袭

developing
adj.
发展中的
v.
(使)成长,发展,壮大;开发;研制;出现(问题); 患(病);(问题)开始影响;(疾病)开始侵袭
develop的现在分词

Unfortunately
adv.
不幸地;遗憾地;可惜地;可悲地

disaster
n.
灾害;灾难;灾祸;不幸;祸患;彻底失败的人(或事)

strike
n.
罢工;(有损声誉的)不利因素,打击;袭击;(尤指)空袭;打;击;罢课;踢;罢市;全中;军事进攻;(珍贵东西的)意外发现;击球未中
v.
罢工;撞击;打;击打,踢(球等);击;碰撞;撞;敲;给(某人以…)印象;突击;擦,划(火柴);行进;侵袭;碰;弹奏;突然想到;照在…上;开采出;顿时使处于某状态

kidnap
vt.
绑架;劫持;诱拐(小孩等),拐骗
n.
诱拐;绑架罪

kidnappers
n.
绑架者;绑匪;拐骗犯
kidnapper的复数

berry
n.
浆果;莓

free
adj.
自由的;免费的;空闲的;(货物等) 免税的;自然的, 不拘束的;自愿的, 主动的;未固定的,松开的;不受阻碍的;丰盛的;直爽的, 坦率的;受准许的, 可允许的;(用钱) 大手大脚的
adv.
自由地;免费地;帆脚索被松开地
v.
释放;使免于;使可用于;使解脱出来;使能腾出时间

optionally
adv.
可选地;随意地

trail
v.
跟踪;(在比赛或其他竞赛中)落后,失利,失败;追踪;(被)拖,拉;蔓生;(尤指跟在他人后面)疲惫地走,没精打采地慢走,磨蹭
n.
(乡间的)小路,小径;(特定)路线,路径;(尤指打猎时跟踪的)踪迹,臭迹;(长串的)痕迹,踪迹,足迹

camp
n.
营地;阵营;(尤指政府让人长时间住宿的)营房,营帐;兵营;度假营
vi.
露营;(尤指在假日)野营;宿营;暂住;借住;借宿
adj.
夸张的,滑稽可笑的(尤指故意逗笑);做作的;故意带女子气的,女性化的(被某些人认为是典型同性恋的特征)

imprison
vt.
监禁;关押

mighty
adj.
强大的;巨大的;非凡的;强而有力的
adv.
非常;极其;很

cunning
adj.
狡猾的;巧妙的;奸诈的;诡诈的;灵巧的;精巧的
n.
狡猾;狡黠;诡诈

archer
n.
弓箭手;射箭运动员

consider
v.
考虑;认为;觉得;顾及;(尤指为作出决定而)仔细考虑;以为;细想;体谅;端详

action
n.
行动;(身体部位的)动作,功能;作用;行为;诉讼;起诉;战斗;情节;机械装置,活动部件;所做之事;激动人心的事
vt.
务必做,确保处理(某事)

engage
v.
从事;(使)衔接,啮合;聘用;雇用;与(某人)交战;吸引住(注意力、兴趣);与…建立密切关系;尽力理解

vulnerable
adj.
脆弱的;(身体上或感情上)易受…伤害的

attack
n.
攻击;袭击;(在战争中使用武器的)进攻;(队员等的)进攻;发作,侵袭;(病、虫等的)损害,伤害;(口头和书面的)抨击,非难;抑制;进攻队员;(情感的)一阵突发
v.
攻击;袭击;(在战争等中使用武器)进攻;抨击;侵袭;非难;奋力处理

armor
n.
装甲;盔甲
v.
为…装甲

spy
n.
间谍;密探;暗中监视
v.
当间谍;发现,注意到;察看,探查;突然看见,突然发现;仔细观察
adj.
间谍的,间谍活动的

upon
prep.
在……上;在上面;刚一……就;即将发生;用在一些动词后,与on 同义;(用于两个相同的名词之间,强调数量之多)(一个)接(一个),……又……
adv.
在上面,在物体上;从此,因此

signal
n.
信号;(尤指铁路和公路上的)指示灯,信号灯,红绿灯;标志;预示;暗号
v.
显示;表示;表明;标志;表达;发信号;示意;预示;发暗号
adj.
重大的;显要的

prisoner
n.
囚犯;犯人;战俘;俘虏;被(敌人等)关起来的人;羁押候审者

intercept
vt.
拦截;截住;拦阻
n.
拦截;(数学)截距;截击;截听;拦截者

train
n.
列车;火车;行列;队列;拖裾,裙裾;一系列相关的事情(或行动);列队行进的人(或动物)
v.
培训;训练(人或动物);教育;进行…训练;接受训练;培养…的能力(或素质);(尤指)进行体育锻炼;使(植物)朝某方向生长

trained
v.
培训;训练(人或动物);教育;进行…训练;接受训练;培养…的能力(或素质);(尤指)进行体育锻炼
adj.
培训;训练过的,受过培训的
train的过去分词和过去式

signaling
n.
打信号,发信号

sneak
v.
溜;偷走(不重要的或小的东西);偷拿;偷偷地走;偷带;(儿童向成人)打小报告,告状;偷偷地做
n.
打小报告的人,告状者(尤指儿童)
adj.
突然的;出其不意的

risky
adj.
有风险的;有危险(或风险)的

rescue
vt.
抢救;营救;援救
n.
救援;抢救;营救;获救;营救行动

escape
v.
逃脱,幸免于难;(从不愉快或危险处境中)逃脱;逃避;逃跑;摆脱;(从监禁或管制中)逃走;逃出;避免(不愉快或危险的事物);漏出;被忘掉;(不自觉地)由…发出
n.
逃脱;逃避;漏出;逃避现实;解脱;Esc键;消遣;渗出(量)

sneaky
adj.
偷偷摸摸的;鬼鬼祟祟的;悄悄的

rescued
v.
抢救;营救;援救
rescue的过去分词和过去式

sudden
adj.
突然的,忽然的;意外的,突然发生的;迅速的,快的;<古>未经事先考虑的,鲁莽的,急速作成的,草率从事的
adv.
<口>突然地,出乎意料地
n.
突然发生的事(或情况)

appearance
n.
出现;外观;外表;外貌;出版;公开露面;(尤指突然的)抵达,到来;起源;首次使用

implement
vt.
实施;执行;贯彻;使生效
n.
工具;器具;(常指)简单的户外用具

determining
v.
确定;测定;决定;影响;形成;安排;裁决;查明;支配;准确算出
adj.
决定性的
determine的现在分词

determine
v.
确定;测定;决定;决定,决心(做某事);影响;形成;安排;裁决;查明;支配;准确算出

available
adj.
可获得的;有空的;可购得的;可找到的

present
n.
目前;现在;礼物;礼品
adj.
存在;当前的;出现;出席;在场;现存的
vt.
提出;(以某种方式)展现,显示,表现;表达,表示;提交;使发生;颁发;交付;授予;把…交给;上演;正式介绍;突然出现;主持播放;正式出席

  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!

请我喝杯咖啡吧~

支付宝
微信