【发布时间】:2020-02-13 18:46:52
【问题描述】:
我是 bscs 的学生,正在学习“人工智能”。
这是一个简单的反射代理程序,它在“Python”上工作,但我也在 p5.js (JavaScript) 上尝试过同样的事情来制作 UI。
但是我得到了这个错误,谁能告诉我为什么 this.currentRoom 没有得到 this.room1??
I'm adding error screenshot over here
或者您可以直接复制它并在在线编辑器上了解实际发生的情况。
对不起,如果我问得不好,实际上这是我第一次在 stackoverflow 上提问。
function setup(){
createCanvas(600,400);
vc = new VAgent();
twoRooms = new VEnvironment(vc);
twoRooms.executeStep(6);
}
function draw(){
background(0);
}
class Room{
constructor(location,status){
this.location=location;
this.status=status;
}
getAll(){
console.log(this.location);
console.log(this.status);
}
}
class VEnvironment{
contructor(agent){
this.agent=agent;
this.room1=new Room('a','Dirty');
this.room2=new Room('b','Dirty');
this.currentRoom=this.room1;
this.actionStatus='';
this.step=0;
}
executeStep(n){
for(var i=0;i<n;i++){
this.displayPerception();
this.agent.sense(this);
var res = this.agent.action();
if(res=='clean'){
this.currentRoom.status=='clean'
}else if(res=='Right'){
this.currentRoom=this.room2;
}else{
this.currentRoom=this.room1;
}
this.displayAction();
this.step++;
}
}
displayPerception(){
console.log('Agent is Present At Room '+this.currentRoom.location+' And The Status For Room Is '+this.currentRoom.status);
}
displayAction(){
console.log('Agent took at'+this.step+' And Action was ... '+this.currentRoom+'...');
}
}
class VAgent{
constructor(){
}
sense(currentEnv){
this.en=currentEnv;
}
action(){
if(this.en.currentRoom.status=='dirty'){
return 'Clean'
}else if(this.en.currentRoom.location=='a'){
return 'Left'
}else{
return 'Right'
}
}
}
【问题讨论】:
标签: javascript artificial-intelligence undefined p5.js agent