日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

JACK——PaintRobot Exercise9

發(fā)布時(shí)間:2025/4/5 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JACK——PaintRobot Exercise9 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

來(lái)源:http://aosgrp.com/

?

Exercise 9

Modify the behaviour of the robot agent so that painting takes a specific period of time to complete.

?

Introduction

In the previous exercise, parts were painted the requested colours. However, painting only took the amount of time required to print out a statement indicating that the robot was painting the part a particular colour. We will discover some interesting effects if we allow the plans involved to 'sleep' for a short time while the robot paints the part. To achieve this, we use the reasoning method statement @sleep.

The @sleep statement takes the following form:

@sleep(double timeout);

timeout represents the period of time that the agent must wait before continuing with the plan. The time-out period is specified in 'ticks' on the agent's clock. The actual time depends on the Timer that the agent is using. If the timer is the real-time clock (the default), then it represents a sleep period in seconds.


Note: @sleep only causes the current task to sleep. Any other tasks that the agent is currently executing proceed as normal.


?

Instructions

1. Modify the 'painting' plans so that they contain an @sleep(5) statement to sleep for 5 seconds after they print the message to indicate that they are painting a part.

If editing the files as JACK files, save and close them before continuing.

2. Save the project.

3. Compile and run the program with the interaction diagram.

?

示例程序

?

運(yùn)行結(jié)果:

(1) test with red

(2) test with no specified colour

(3) Painting part the requested colour (1st coat) red

(4) Painting part the requested colour (2nd coat) red

(5) test with green

(6) No specified colour. Painting the part red

(7) test with green again

(8) Painting part the requested colour (1st coat) green

(9) Painting part the requested colour (2nd coat) green

(10) painting the part the current colour: green

(11) part1@%portal has been painted green

(12) part2@%portal has been painted green

(13) part3@%portal has been painted green

(14) part4@%portal has been painted green

?

運(yùn)行結(jié)果分析:

運(yùn)行結(jié)果與例8大致相同,不同之處在于最后4條(11)、(12)、(13)、(14),這是語(yǔ)句@sleep(5) 產(chǎn)生的效果,即在規(guī)劃完成后阻塞5秒,由于sleep語(yǔ)句只阻塞當(dāng)前的任務(wù),所以其他任務(wù)照常執(zhí)行,5秒鐘足夠讓其他任務(wù)執(zhí)行完成。

?

Questions

1. How do you explain the output?

2. How can you ensure that the robot does not begin a new task to start painting another part while it is still 'busy'?

?

Answers

1. 分析結(jié)果參考上述運(yùn)行結(jié)果分析

2.? (1)在Robot Agent中添加boolean類型的busy字段,用來(lái)標(biāo)識(shí)Robot Agent是否處于忙的狀態(tài),初始值設(shè)為false,即空閑狀態(tài)。

(2)在body()的推理方法中增加while語(yǔ)句,不斷輪詢判斷當(dāng)前Robot Agent的狀態(tài),如果為忙的狀態(tài),則阻塞1秒,形式如下:

while(self.busy)

{

System.out.println("wait for a moment");

@sleep(1);

}

修改原來(lái)的sleep時(shí)間為2秒,這樣結(jié)果出來(lái)更快一些(也可不修改)

?

順序執(zhí)行示例程序?

?

運(yùn)行結(jié)果:

test with red

test with no specified colour

Painting part the requested colour (1st coat) red

Painting part the requested colour (2nd coat) red

test with green

part1@%portal has been painted red

wait for a moment

test with green again

wait for a moment

wait for a moment

wait for a moment

wait for a moment

wait for a moment

No specified colour. Painting the part red

wait for a moment

wait for a moment

part2@%portal has been painted red

wait for a moment

wait for a moment

Painting part the requested colour (1st coat) green

Painting part the requested colour (2nd coat) green

wait for a moment

part3@%portal has been painted green

wait for a moment

Painting part the requested colour (1st coat) green

Painting part the requested colour (2nd coat) green

part4@%portal has been painted green

由上可見(jiàn),交給Robot Agent的任務(wù)是串行執(zhí)行。

轉(zhuǎn)載于:https://www.cnblogs.com/6DAN_HUST/archive/2011/06/13/2079725.html

總結(jié)

以上是生活随笔為你收集整理的JACK——PaintRobot Exercise9的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。